diff options
| author | Shinigami <[email protected]> | 2023-03-29 10:22:57 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-03-29 08:22:57 +0000 |
| commit | f890d627164c5436e2b2a3ac05239a1a1634015e (patch) | |
| tree | 93d77a9f2c8dcf105b4e45e44ea9fb0c85b30a3d /scripts | |
| parent | de47aaa56892621a0088ac63386cfaf06c560f16 (diff) | |
| download | faker-f890d627164c5436e2b2a3ac05239a1a1634015e.tar.xz faker-f890d627164c5436e2b2a3ac05239a1a1634015e.zip | |
feat: add base locale (#1748)
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/generateLocales.ts | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/scripts/generateLocales.ts b/scripts/generateLocales.ts index d8fa1be1..7a8aa299 100644 --- a/scripts/generateLocales.ts +++ b/scripts/generateLocales.ts @@ -125,10 +125,15 @@ function generateLocaleFile(locale: string): void { } } - if (locales[locales.length - 1] !== 'en') { + // TODO christopher 2023-03-07: Remove 'en' fallback in a separate PR + if (locales[locales.length - 1] !== 'en' && locale !== 'base') { locales.push('en'); } + if (locales[locales.length - 1] !== 'base') { + locales.push('base'); + } + let content = ` ${autoGeneratedCommentHeader} @@ -148,8 +153,10 @@ function generateLocaleFile(locale: string): void { writeFileSync(resolve(pathLocale, `${locale}.ts`), content); } -function tryLoadLocalesMainIndexFile(pathModules: string): LocaleDefinition { - let localeDef: LocaleDefinition; +function tryLoadLocalesMainIndexFile( + pathModules: string +): LocaleDefinition | undefined { + let localeDef: LocaleDefinition | undefined; // This call might fail, if the module setup is broken. // Unfortunately, we try to fix it with this script // Thats why have a fallback logic here, we only need the title anyway @@ -165,9 +172,10 @@ function tryLoadLocalesMainIndexFile(pathModules: string): LocaleDefinition { resolve(pathModules, 'index.ts'), 'utf-8' ); - localeDef = { - title: localeIndex.match(/title: '(.*)',/)[1], - }; + const title = localeIndex.match(/title: '(.*)',/)?.[1]; + if (title) { + localeDef = { title }; + } } catch { console.error(`Failed to load ${pathModules} or manually parse it.`, e); } |
