Skip to content

Commit

Permalink
fix: loader should return empty translations in development
Browse files Browse the repository at this point in the history
  • Loading branch information
tricoder42 committed Aug 9, 2018
1 parent 8f08942 commit 1b9c05a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 7 additions & 3 deletions packages/cli/src/api/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,17 @@ function processTokens(tokens, arg) {
)
}

export function createCompiledCatalog(locale: string, messages: CatalogType) {
export function createCompiledCatalog(
locale: string,
messages: CatalogType,
strict: boolean = false
) {
const [language] = locale.split(/[_-]/)
const pluralRules = plurals[language]

const compiledMessages = R.keys(messages).map(key => {
const translation = messages[key]
return t.objectProperty(t.stringLiteral(key), compile(translation || key))
const translation = messages[key] || (!strict ? key : "")
return t.objectProperty(t.stringLiteral(key), compile(translation))
})

const languageData = [
Expand Down
8 changes: 7 additions & 1 deletion packages/loader/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@ export default function(source) {
catalogs[locale]
)

return createCompiledCatalog(locale, messages)
// In production we don't want untranslated strings. It's better to use message
// keys as a last resort.
// In development, however, we want to catch missing strings with `missing` parameter
// of I18nProvider (React) or setupI18n (core) and therefore we need to get
// empty translations if missing.
const strict = process.env.NODE_ENV !== "production"
return createCompiledCatalog(locale, messages, strict)
}

0 comments on commit 1b9c05a

Please sign in to comment.