@@ -43,7 +43,9 @@ export interface AppTranslations {
4343 */
4444export function hasAppTranslations ( appId : string ) : boolean {
4545 return (
46- appId in globalThis . _oc_l10n_registry_translations
46+ globalThis . _oc_l10n_registry_translations !== undefined
47+ && globalThis . _oc_l10n_registry_plural_functions !== undefined
48+ && appId in globalThis . _oc_l10n_registry_translations
4749 && appId in globalThis . _oc_l10n_registry_plural_functions
4850 )
4951}
@@ -64,6 +66,9 @@ export function registerAppTranslations(
6466 throw new Error ( 'Invalid appId' )
6567 }
6668
69+ globalThis . _oc_l10n_registry_translations ??= { }
70+ globalThis . _oc_l10n_registry_plural_functions ??= { }
71+
6772 globalThis . _oc_l10n_registry_translations [ appId ] = {
6873 ...( globalThis . _oc_l10n_registry_translations [ appId ] || { } ) ,
6974 ...translations ,
@@ -78,8 +83,8 @@ export function registerAppTranslations(
7883 * @param appId - The app id
7984 */
8085export function unregisterAppTranslations ( appId : string ) : void {
81- delete globalThis . _oc_l10n_registry_translations [ appId ]
82- delete globalThis . _oc_l10n_registry_plural_functions [ appId ]
86+ delete globalThis . _oc_l10n_registry_translations ?. [ appId ]
87+ delete globalThis . _oc_l10n_registry_plural_functions ?. [ appId ]
8388}
8489
8590/**
@@ -89,11 +94,7 @@ export function unregisterAppTranslations(appId: string): void {
8994 */
9095export function getAppTranslations ( appId : string ) : AppTranslations {
9196 return {
92- translations : globalThis . _oc_l10n_registry_translations [ appId ] ?? { } ,
93- pluralFunction : globalThis . _oc_l10n_registry_plural_functions [ appId ] ?? ( ( number : number ) => number ) ,
97+ translations : globalThis . _oc_l10n_registry_translations ?. [ appId ] ?? { } ,
98+ pluralFunction : globalThis . _oc_l10n_registry_plural_functions ?. [ appId ] ?? ( ( number : number ) => number ) ,
9499 }
95100}
96-
97- // Initialize global state if needed
98- globalThis . _oc_l10n_registry_translations ??= { }
99- globalThis . _oc_l10n_registry_plural_functions ??= { }
0 commit comments