File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
22 "name" : " @pistonite/celera" ,
3- "version" : " 0.3.0 " ,
3+ "version" : " 0.3.1 " ,
44 "type" : " module" ,
55 "private" : true ,
66 "description" : " In-house UI framework" ,
Original file line number Diff line number Diff line change @@ -7,16 +7,12 @@ import type { LocaleOptions } from "./types.ts";
77import { createBackend } from "./backend.ts" ;
88import Strings from "./strings.yaml" ;
99import { registerTranslationLoader } from "./loaders.ts" ;
10+ import { once } from "@pistonite/pure/sync" ;
1011
1112export const CELERA_NAMESPACE = "celerans" ;
1213
13- /**
14- * Initialize locale system in Pure and connect it with I18next
15- *
16- * This function calls `initLocale` internally, so you don't need to do that yourself.
17- */
18- export const initLocale = async < TLocale extends string > ( options : LocaleOptions < TLocale > ) => {
19- registerTranslationLoader ( CELERA_NAMESPACE , loadCeleraTranslations ) ;
14+ const initLocaleInternal = async < TLocale extends string > ( options : LocaleOptions < TLocale > ) => {
15+ await registerTranslationLoader ( CELERA_NAMESPACE , loadCeleraTranslations ) ;
2016
2117 const defaultLocale = options . default ;
2218 let instance = i18next ;
@@ -52,6 +48,11 @@ export const initLocale = async <TLocale extends string>(options: LocaleOptions<
5248 ns : [ CELERA_NAMESPACE ] ,
5349 } ) ;
5450} ;
51+ /**
52+ * Initialize locale system in Celera and connect it with I18next
53+ * @function
54+ */
55+ export const initLocale = once ( { fn : initLocaleInternal } ) ;
5556
5657const loadCeleraTranslations = async ( language : string ) : Promise < Record < string , string > > => {
5758 const SupportedLocales = [
Original file line number Diff line number Diff line change @@ -7,19 +7,21 @@ const namedspacedLoaders: Map<string, LoadLanguageFn> = new Map();
77const namespacedAwaiters : Map < string , ( ( loader : LoadLanguageFn ) => void ) [ ] > = new Map ( ) ;
88
99/** Register a translation loader for a namespace */
10- export const registerTranslationLoader = ( namespace : string , loader : LoadLanguageFn ) => {
10+ export const registerTranslationLoader = async (
11+ namespace : string ,
12+ loader : LoadLanguageFn ,
13+ ) : Promise < void > => {
1114 if ( namedspacedLoaders . has ( namespace ) ) {
1215 log . error ( `translation namespace '${ namespace } ' is already registered` ) ;
1316 return ;
1417 }
1518 namedspacedLoaders . set ( namespace , loader ) ;
1619 const awaiters = namespacedAwaiters . get ( namespace ) ;
17- if ( ! awaiters ) {
18- return ;
20+ if ( awaiters ) {
21+ namespacedAwaiters . delete ( namespace ) ;
22+ awaiters . forEach ( ( x ) => x ( loader ) ) ;
1923 }
20- namespacedAwaiters . delete ( namespace ) ;
21- awaiters . forEach ( ( x ) => x ( loader ) ) ;
22- void i18next . loadNamespaces ( namespace ) ;
24+ await i18next . loadNamespaces ( namespace ) ;
2325} ;
2426
2527export const getTranslationLoaderForNamespace = ( namespace : string ) : Promise < LoadLanguageFn > => {
You can’t perform that action at this time.
0 commit comments