1- import { readFileSync } from 'fs' ;
2- import Nullstack from ' nullstack' ;
3- import YAML from ' yaml' ;
1+ import { existsSync , readFileSync } from "fs" ;
2+ import Nullstack from " nullstack" ;
3+ import YAML from " yaml" ;
44
55class Translatable extends Nullstack {
6-
76 static async geti18nByLocale ( { locale } ) {
8- const [ name ] = this . name . split ( '_' ) ;
9- const file = readFileSync ( `i18n/${ locale } /components/${ name } .yml` , 'utf-8' ) ;
10- return YAML . parse ( file ) ;
7+ const [ name ] = this . name . split ( "_" ) ;
8+ const translationPath = `i18n/${ locale } /components/${ name } .yml` ;
9+ if ( existsSync ( translationPath ) ) {
10+ const file = readFileSync ( translationPath , "utf-8" ) ;
11+ return YAML . parse ( file ) ;
12+ }
13+ return { } ;
1114 }
1215
1316 async initiate ( { page, locale } ) {
1417 this . locale = locale ;
1518 this . i18n = await this . geti18nByLocale ( { locale } ) ;
1619 if ( this . i18n . title ) {
1720 page . description = this . i18n . description ;
18- page . locale = locale || ' en-US' ;
21+ page . locale = locale || " en-US" ;
1922 }
2023 }
2124
@@ -30,7 +33,6 @@ class Translatable extends Nullstack {
3033 this . initiate ( ) ;
3134 }
3235 }
33-
3436}
3537
36- export default Translatable ;
38+ export default Translatable ;
0 commit comments