Skip to content

Commit

Permalink
fix: locale not present in catalogs warn (#871)
Browse files Browse the repository at this point in the history
  • Loading branch information
tricoder42 authored Nov 17, 2020
2 parents aa62ad3 + a53e12f commit d0b3eb5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion packages/cli/src/api/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,21 @@ export class Catalog {
console.error(`Message with key ${key} is missing in locale ${locale}`)
}

const getTranslation = (locale) => catalogs[locale][key].translation
const getTranslation = (locale) => {
const configLocales = this.config.locales.join('", "')
if (catalogs[locale]) {
return catalogs[locale][key].translation
}

console.warn(`
Catalog "${locale}" isn't present in locales config parameter
Add "${locale}" to your lingui.config.js:
{
locales: ["${configLocales}", "${locale}"]
}
`)
return null
}

const getMultipleFallbacks = (locale) => {
const fL = fallbackLocales[locale]
Expand Down
2 changes: 1 addition & 1 deletion packages/conf/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ describe("@lingui/conf", function () {
),
})
expect(config.fallbackLocales).toEqual({
"en-US": "en",
"en-US": ["en"],
default: "en",
"es-MX": "es"
})
Expand Down
2 changes: 1 addition & 1 deletion packages/conf/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export function fallbackLanguageMigration(

config.locales.forEach((locale) => {
const fl = getCldrParentLocale(locale.toLowerCase())
if (fl) {
if (fl && !config.fallbackLocales[locale]) {
config.fallbackLocales = {
...config.fallbackLocales,
[locale]: fl
Expand Down

1 comment on commit d0b3eb5

@vercel
Copy link

@vercel vercel bot commented on d0b3eb5 Nov 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.