-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide
translate
and translatePlural
functions
* Provide both functions, code is mostly taken from server some minor cleanup * Added test cases * Added *not* exported `registry` module for loading translations (so this is not exposed to users) Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
- Loading branch information
Showing
5 changed files
with
175 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
declare var window: { | ||
_oc_l10n_registry_translations: Record<string, Record<string, string | undefined>> | ||
_oc_l10n_registry_plural_functions: Record<string, (number: number) => number> | ||
} | ||
|
||
interface AppTranslations { | ||
translations: Record<string, string | undefined>; | ||
pluralFunction: (number: number) => number; | ||
} | ||
|
||
/** | ||
* @param {string} appId the app id | ||
* @return {object} | ||
*/ | ||
export function getAppTranslations(appId: string): AppTranslations { | ||
if (typeof window._oc_l10n_registry_translations === 'undefined' || | ||
typeof window._oc_l10n_registry_plural_functions === 'undefined') { | ||
console.warn('No OC L10N registry found') | ||
return { | ||
translations: {}, | ||
pluralFunction: (number: number) => number | ||
} | ||
} | ||
|
||
return { | ||
translations: window._oc_l10n_registry_translations[appId] || {}, | ||
pluralFunction: window._oc_l10n_registry_plural_functions[appId], | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters