@@ -156,20 +156,26 @@ export default class I18N extends AdminForthPlugin {
156156 } ) ;
157157 }
158158
159+ const compMeta = {
160+ brandSlug : adminforth . config . customization . brandNameSlug ,
161+ pluginInstanceId : this . pluginInstanceId ,
162+ supportedLanguages : this . options . supportedLanguages . map ( lang => (
163+ {
164+ code : lang ,
165+ // lang name on on language native name
166+ name : iso6391 . getNativeName ( lang ) ,
167+ }
168+ ) )
169+ } ;
159170 // add underLogin component
160- ( adminforth . config . customization . loginPageInjections . underInputs as AdminForthComponentDeclaration [ ] ) . push ( {
171+ ( adminforth . config . customization . loginPageInjections . underInputs ) . push ( {
161172 file : this . componentPath ( 'LanguageUnderLogin.vue' ) ,
162- meta : {
163- brandSlug : adminforth . config . customization . brandNameSlug ,
164- pluginInstanceId : this . pluginInstanceId ,
165- supportedLanguages : this . options . supportedLanguages . map ( lang => (
166- {
167- code : lang ,
168- // lang name on on language native name
169- name : iso6391 . getNativeName ( lang ) ,
170- }
171- ) )
172- }
173+ meta : compMeta
174+ } ) ;
175+
176+ ( adminforth . config . customization . globalInjections . userMenu ) . push ( {
177+ file : this . componentPath ( 'LanguageInUserMenu.vue' ) ,
178+ meta : compMeta
173179 } ) ;
174180
175181 // disable create allowedActions for translations
@@ -301,8 +307,6 @@ export default class I18N extends AdminForthPlugin {
301307
302308 const translations = await this . adminforth . resource ( this . resourceConfig . resourceId ) . list ( Filters . IN ( this . primaryKeyFieldName , selectedIds ) ) ;
303309
304- console . log ( '🪲translations' , translations ) ;
305-
306310 for ( const lang of this . options . supportedLanguages ) {
307311 if ( lang === 'en' ) {
308312 // all strings are in English, no need to translate
@@ -321,8 +325,6 @@ export default class I18N extends AdminForthPlugin {
321325 }
322326 }
323327
324- console . log ( '🪲needToTranslateByLang' , needToTranslateByLang ) ;
325-
326328 const maxKeysInOneReq = 10 ;
327329
328330 const updateStrings : Record < string , {
521523
522524 adminforth . tr = async ( msg : string , category : string , lang : string ) : Promise < string > => {
523525 console . log ( '🪲tr' , msg , category , lang ) ;
526+
527+ // if lang is not supported , throw
528+ if ( ! this . options . supportedLanguages . includes ( lang as LanguageCode ) ) {
529+ throw new Error ( `Language ${ lang } is not entered to be supported by requested by browser in request headers accept-language` ) ;
530+ }
531+
524532 // try to get translation from cache
525533 const cacheKey = `${ resourceConfig . resourceId } :${ category } :${ lang } :${ msg } ` ;
526534 const cached = await this . cache . get ( cacheKey ) ;
536544 } ) ;
537545 return msg ;
538546 }
547+
548+ // do this check here, to faster register missing translations
549+ // also not cache it - no sense to cache english strings
550+ if ( lang === 'en' ) {
551+ return msg ;
552+ }
553+
539554 const result = translation [ this . trFieldNames [ lang ] ] ;
555+ if ( ! result ) {
556+ // return english
557+ return msg ;
558+ }
540559 await this . cache . set ( cacheKey , result ) ;
541560 return result ;
542561 }
0 commit comments