Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(i18n): support translations for shelves titles and menu labels #612

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/common/src/utils/configSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const menuSchema: SchemaOf<Menu> = object().shape({
contentId: string().defined(),
filterTags: string().notRequired(),
type: mixed().oneOf(['playlist', 'content_list', 'media']).notRequired(),
custom: object().notRequired(),
});

const featuresSchema: SchemaOf<Features> = object({
Expand Down
3 changes: 2 additions & 1 deletion packages/common/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ export type Content = {
type: AppShelfType;
featured?: boolean;
backgroundColor?: string | null;
custom?: Record<string, unknown>;
custom?: Record<string, string>;
};

export type Menu = {
label: string;
contentId: string;
type?: AppMenuType;
filterTags?: string;
custom?: Record<string, string>;
};

export type Styling = {
Expand Down
8 changes: 6 additions & 2 deletions packages/ui-react/src/containers/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import styles from './Layout.module.scss';

const Layout = () => {
const { t } = useTranslation('common');
const { i18n } = useTranslation();

// Determine currently selected language
const language = i18n.language;

const { config } = useConfigStore(
({ config, accessModel, supportedLanguages }) => ({
Expand All @@ -48,8 +52,8 @@ const Layout = () => {

const navItems = [
{ label: t('home'), to: '/' },
...menu.map(({ label, contentId, type }) => ({
label,
...menu.map(({ label, contentId, type, custom }) => ({
label: custom?.[`label-${language}`] || label,
to: determinePath({ type, contentId, label }),
})),
];
Expand Down
11 changes: 9 additions & 2 deletions packages/ui-react/src/containers/ShelfList/ShelfList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ const ShelfList = ({ rows }: Props) => {
const { accessModel } = useConfigStore(({ accessModel }) => ({ accessModel }), shallow);
const [rowsToLoad, setRowsToLoad] = useState(INITIAL_ROWS_TO_LOAD);
const { t } = useTranslation('error');
const { i18n } = useTranslation();

// Determine currently selected language
const language = i18n.language;

const watchHistoryDictionary = useWatchHistoryStore((state) => state.getDictionaryWithSeries());

Expand Down Expand Up @@ -71,6 +75,9 @@ const ShelfList = ({ rows }: Props) => {
const posterAspect = parseAspectRatio(playlist.cardImageAspectRatio || playlist.shelfImageAspectRatio);
const visibleTilesDelta = parseTilesDelta(posterAspect);

const translatedKey = custom?.[`title-${language}`];
const translatedTitle = translatedKey || title || playlist?.title;

const isFeatured = isTruthyCustomParamValue(custom?.featured) || featured;

const ShelfComponent = isFeatured ? FeaturedShelf : Shelf;
Expand All @@ -79,7 +86,7 @@ const ShelfList = ({ rows }: Props) => {
<section
key={`${index}_${playlist.id}`}
className={classNames(styles.shelfContainer, { [styles.featured]: isFeatured })}
data-testid={testId(`shelf-${isFeatured ? 'featured' : type === 'playlist' ? slugify(title || playlist?.title) : type}`)}
data-testid={testId(`shelf-${isFeatured ? 'featured' : type === 'playlist' ? slugify(translatedTitle) : type}`)}
aria-label={title || playlist?.title}
>
<Fade duration={250} delay={index * 33} open>
Expand All @@ -89,7 +96,7 @@ const ShelfList = ({ rows }: Props) => {
type={type}
playlist={playlist}
watchHistory={type === PersonalShelf.ContinueWatching ? watchHistoryDictionary : undefined}
title={title || playlist?.title}
title={translatedTitle}
featured={isFeatured}
accessModel={accessModel}
isLoggedIn={!!user}
Expand Down
Loading