Skip to content

Commit

Permalink
small tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Dougley committed Feb 18, 2022
1 parent 44219ba commit 0ff5822
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
dist/
src/languages/
4 changes: 4 additions & 0 deletions .github/workflows/crowdin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ jobs:
with:
upload_sources: false
download_translations: true
create_pull_request: false
push_translations: false
skip_untranslated_strings: true
skip_untranslated_files: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
Expand Down
5 changes: 4 additions & 1 deletion src/utils/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export function translate (key: string, args?: Record<string, any>, lang?: strin
}
try {
const msg = traverse(key, lang)
if (!(typeof msg === 'string')) error(`Translation key ${key} not found in cache!`, 'i18n')
if (!(typeof msg === 'string') && lang !== defaultLang) {
warn(`Translation key ${key} for language ${lang ?? defaultLang} not found in cache! Retrying for default language`, 'i18n')
return translate(key, args, defaultLang)
} else error(`Translation key ${key} for default language not found in cache!`, 'i18n')
return new IntlMessageFormat(typeof msg === 'string' ? msg : '[TRANSLATION FAILED]').format(args)
} catch (e) {
error(`Failed to translate ${key}`, 'i18n')
Expand Down

0 comments on commit 0ff5822

Please sign in to comment.