Skip to content

Commit

Permalink
Small tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpocock committed Aug 7, 2023
1 parent f7d9f60 commit 87f1e16
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/06-challenges/34-internationalization.solution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ type GetParamKeys<TTranslation extends string> = TTranslation extends ""
const translate = <
TTranslations extends Record<string, string>,
TKey extends keyof TTranslations,
TComputedArgs extends string[] = GetParamKeys<TTranslations[TKey]>,
TParamKeys extends string[] = GetParamKeys<TTranslations[TKey]>,
>(
translations: TTranslations,
key: TKey,
...args: TComputedArgs extends []
...args: TParamKeys extends []
? []
: [params: Record<TComputedArgs[number], string>]
: [params: Record<TParamKeys[number], string>]
) => {
const translation = translations[key];
const params: any = args[0] || {};
Expand All @@ -26,7 +26,7 @@ const translate = <
// TESTS

const translations = {
title: "Hello, {firstName} {surname}!",
title: "Hello, {name}!",
subtitle: "You have {count} unread messages.",
button: "Click me!",
} as const;
Expand All @@ -39,7 +39,7 @@ it("Should translate a translation without parameters", () => {

it("Should translate a translation WITH parameters", () => {
const subtitle = translate(translations, "subtitle", {
count: "2",
count: "123123",
});

expect(subtitle).toEqual("You have 2 unread messages.");
Expand Down

0 comments on commit 87f1e16

Please sign in to comment.