@@ -6,6 +6,7 @@ import { syncI18nextToCeleraModule } from "./integration.ts";
66import type { LocaleOptions } from "./types.ts" ;
77import { createBackend } from "./backend.ts" ;
88import Strings from "./strings.yaml" ;
9+ import { registerTranslationLoader } from "./loaders.ts" ;
910
1011export const CELERA_NAMESPACE = "celerans" ;
1112
@@ -15,6 +16,8 @@ export const CELERA_NAMESPACE = "celerans";
1516 * This function calls `initLocale` internally, so you don't need to do that yourself.
1617 */
1718export const initLocale = async < TLocale extends string > ( options : LocaleOptions < TLocale > ) => {
19+ registerTranslationLoader ( CELERA_NAMESPACE , loadCeleraTranslations ) ;
20+
1821 const defaultLocale = options . default ;
1922 let instance = i18next ;
2023 const syncMode = options . sync || "full" ;
@@ -43,31 +46,10 @@ export const initLocale = async <TLocale extends string>(options: LocaleOptions<
4346 instance = instance . use ( initReactI18next ) ;
4447
4548 const loader = options . loader ;
46- if ( typeof loader === "function" ) {
47- const backend = createBackend (
48- {
49- translation : loader ,
50- [ CELERA_NAMESPACE ] : loadCeleraTranslations ,
51- } ,
52- defaultLocale ,
53- ) ;
54- instance = instance . use ( backend ) ;
55- await instance . init ( ) ;
56- return ;
57- }
58-
59- const backend = createBackend (
60- {
61- ...loader ,
62- [ CELERA_NAMESPACE ] : loadCeleraTranslations ,
63- } ,
64- defaultLocale ,
65- ) ;
49+ const backend = createBackend ( loader , defaultLocale ) ;
6650 instance = instance . use ( backend ) ;
6751 await instance . init ( {
68- // make sure the namespaces are registered, so translations work
69- // in contexts without react-i18next
70- ns : Object . keys ( loader ) ,
52+ ns : [ CELERA_NAMESPACE ] ,
7153 } ) ;
7254} ;
7355
0 commit comments