-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix standalone registeration #556
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Just one comment about the console warning
Registration of a translation bundle in standalone application didn't work without initializing global `_oc_l10n_registry_*` objects. Add global registry initialization in `register` function. Signed-off-by: Grigorii Shartsev <grigorii.shartsev@nextcloud.com>
Signed-off-by: Grigorii Shartsev <grigorii.shartsev@nextcloud.com>
4a49f1f
to
f801f7d
Compare
export function getAppTranslations(appId: string): AppTranslations { | ||
if ( | ||
typeof window._oc_l10n_registry_translations === 'undefined' | ||
|| typeof window._oc_l10n_registry_plural_functions === 'undefined' | ||
typeof window._oc_l10n_registry_translations?.[appId] === 'undefined' | ||
|| typeof window._oc_l10n_registry_plural_functions?.[appId] === 'undefined' | ||
) { | ||
console.warn('No OC L10N registry found') | ||
return { | ||
translations: {}, | ||
pluralFunction: (number: number) => number, | ||
} | ||
console.warn(`No translation for appId "${appId}" have been registered`) | ||
} | ||
|
||
return { | ||
translations: window._oc_l10n_registry_translations[appId] || {}, | ||
pluralFunction: window._oc_l10n_registry_plural_functions[appId], | ||
translations: window._oc_l10n_registry_translations?.[appId] ?? {}, | ||
pluralFunction: window._oc_l10n_registry_plural_functions?.[appId] ?? ((number: number) => number), | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update warns logic here.
Since it doesn't matter if "no app translation has been registered" or "only appId
hasn't been registered", check both situations with optional chaining.
Warn is always about concrete appId
, as there is no "general translation registration." It is always some app translation registration.
Also, return default stub for both translations
and pluralFunction
if there is no value.
In 2.0.0
@nextcluod/l10n
became independent from globalOC
for being standalone.That is great and really useful for me.
But a translation registration requires global
window._oc_l10n_registry_*
objects to exist. Otherwise, registration fails withCannot get property of undefined
._oc_l10n_registry_
objects existence and creating if they do not exist.