@@ -11,10 +11,7 @@ const appLang = getAppLang();
1111
1212const languages = await getListLanguages ( ) ;
1313
14- // programatically load all locales
15- for await ( const record of languages ) {
16- const language = record . path ;
17-
14+ const getLangTranslations = async ( language : string ) => {
1815 const activities = await import ( `@locales/${ language } /activities.json` ) . then (
1916 ( module ) => module . default
2017 ) ;
@@ -62,7 +59,7 @@ for await (const record of languages) {
6259 ( module ) => module . default
6360 ) ;
6461
65- resources [ record . locale ] = {
62+ return {
6663 ui : {
6764 ...activities ,
6865 ...congregation ,
@@ -79,6 +76,15 @@ for await (const record of languages) {
7976 songs,
8077 releases,
8178 } ;
79+ } ;
80+
81+ // programatically load all locales
82+ for ( const record of languages ) {
83+ const language = record . path ;
84+
85+ const resource = await getLangTranslations ( language ) ;
86+
87+ resources [ record . locale ] = resource ;
8288}
8389
8490const supportedLangs = languages . map ( ( l ) => l . locale ) ;
@@ -93,3 +99,21 @@ i18n.use(initReactI18next).init({
9399} ) ;
94100
95101export default i18n ;
102+
103+ export const refreshLocalesResources = async ( ) => {
104+ const supportedLangs = Object . keys ( i18n . options . resources ) ;
105+
106+ const languages = await getListLanguages ( ) ;
107+
108+ const newLanguages = languages . filter (
109+ ( record ) => ! supportedLangs . includes ( record . locale )
110+ ) ;
111+
112+ for ( const language of newLanguages ) {
113+ const resource = await getLangTranslations ( language . path ) ;
114+
115+ for ( const [ key , values ] of Object . entries ( resource ) ) {
116+ i18n . addResources ( language . locale , key , values ) ;
117+ }
118+ }
119+ } ;
0 commit comments