Skip to content

Commit

Permalink
Fix localicious
Browse files Browse the repository at this point in the history
  • Loading branch information
phavekes committed Jan 17, 2025
1 parent 32eed40 commit fd717a0
Show file tree
Hide file tree
Showing 5 changed files with 722 additions and 674 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/localicious.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ jobs:
- name: Create Localizable.strings files
run: |
cd ${{ github.workspace }}
yarn localicious render ./localizations.yaml ./account-gui/src/locale/ --languages en,nl --outputTypes js -c SHARED
localicious render ./localizations.yaml ./account-gui/src/locale/ --languages en,nl --outputTypes js -c SHARED
rm -fr ./account-gui/src/locale/js/Localizable.ts
yarn localicious render ./localizations.yaml ./myconext-gui/src/locale/ --languages en,nl --outputTypes js -c SHARED
localicious render ./localizations.yaml ./myconext-gui/src/locale/ --languages en,nl --outputTypes js -c SHARED
rm -fr ./myconext-gui/src/locale/js/Localizable.ts
- name: Commit updated files
uses: stefanzweifel/git-auto-commit-action@v4
Expand Down
45 changes: 45 additions & 0 deletions account-gui/src/locale/js/Localizable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// DO NOT EDIT. This file is auto-generated using Localicious (https://github.com/PicnicSupermarket/localicious).

import en from "./en/strings.json";
import nl from "./nl/strings.json";

type LanguageStrings = | typeof en | typeof nl;

type Language = | "en" | "nl";

type EnumDictionary<T extends string | symbol | number, U> = {
[K in T]: U;
};

export type TranslationKey = keyof LanguageStrings;

const strings: EnumDictionary<Language, LanguageStrings> = {
en: en,
nl: nl,
};

const format = (string: string, ...args: string[]) => {
let result = string;
for (let i = 0; i < args.length; i++) {
const pos = i + 1;
if (typeof args[i] === "string") {
result = result.replace("%" + pos + "$s", args[i]);
}
if (typeof args[i] === "number") {
result = result.replace("%" + pos + "$d", args[i]);
}
}
return result;
};

export const translation = (
language: Language,
key: TranslationKey,
...args: string[]
): string | undefined => {
// Check if translation exists.
if (!(language in strings) && !(key in strings[language])) {
return undefined;
}
return format(strings[language][key], ...args);
};
Loading

0 comments on commit fd717a0

Please sign in to comment.