Skip to content

Commit

Permalink
i18n: add translations and formatting to InlineList "more"
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinstadler committed Jan 20, 2025
1 parent 1184f75 commit 8463561
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/[locale]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export default function LocaleLayout(props: LocaleLayoutProps): ReactNode {
"AppHeader",
"BernhardCategories",
"Error",
"InlineList",
"InstantSearch",
"Languages",
"LanguagesPage",
Expand Down
8 changes: 7 additions & 1 deletion components/inline-list.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useTranslations } from "next-intl";
import type { ReactNode } from "react";

interface InlineListProps {
Expand All @@ -8,12 +9,17 @@ interface InlineListProps {

export function InlineList(props: InlineListProps): ReactNode {
const { children, limit, separator } = props;
const t = useTranslations("InlineList");

const andMore = limit && children.length > limit;
if (andMore) {
const overhead = 1 + children.length - limit;
// eslint-disable-next-line @typescript-eslint/no-floating-promises
children.splice(limit - 1, overhead, `+ ${overhead.toString()} more`);
children.splice(
limit - 1,
overhead,
<span className="text-nowrap">{t("and_x_more", { x: overhead })}</span>,
);
}

return (
Expand Down
3 changes: 3 additions & 0 deletions messages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
"lead-in": "",
"title": "Thomas Bernhard in Translation"
},
"InlineList": {
"and_x_more": "+ noch {x, number}"
},
"InstantSearch": {
"all": "alle",
"filter": "Suche",
Expand Down
3 changes: 3 additions & 0 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
"lead-in": "",
"title": "Thomas Bernhard in Translation"
},
"InlineList": {
"and_x_more": "+ {x, number} more"
},
"InstantSearch": {
"all": "all",
"filter": "search",
Expand Down

0 comments on commit 8463561

Please sign in to comment.