Skip to content

Commit

Permalink
⚡ improvement(index): make silentTranslationWarn work for dates and n…
Browse files Browse the repository at this point in the history
…umbers too (#481) by @Raiondesu

Currently, the `silentTranslationWarn` flag only disables warnings for regular translations, which, I think, is not what people would expect from this option. Even when `silentTranslationWarn` is enabled - warning for fallback translations for numbers and dates still occur, completely littering the console.

This fix makes all fallback warnings to vanish (including numbers and dates) upon setting the `silentTranslationWarn` flag, while leaving other (non-fallback) warnings intact.
  • Loading branch information
Raiondesu authored and kazupon committed Dec 15, 2018
1 parent b4a8c27 commit 402092b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ export default class VueI18n {

// fallback locale
if (isNull(formats) || isNull(formats[key])) {
if (process.env.NODE_ENV !== 'production') {
if (process.env.NODE_ENV !== 'production' && !this._silentTranslationWarn) {
warn(`Fall back to '${fallback}' datetime formats from '${locale} datetime formats.`)
}
_locale = fallback
Expand Down Expand Up @@ -533,7 +533,7 @@ export default class VueI18n {
const ret: ?DateTimeFormatResult =
this._localizeDateTime(value, locale, this.fallbackLocale, this._getDateTimeFormats(), key)
if (this._isFallbackRoot(ret)) {
if (process.env.NODE_ENV !== 'production') {
if (process.env.NODE_ENV !== 'production' && !this._silentTranslationWarn) {
warn(`Fall back to datetime localization of root: key '${key}' .`)
}
/* istanbul ignore if */
Expand Down Expand Up @@ -596,7 +596,7 @@ export default class VueI18n {

// fallback locale
if (isNull(formats) || isNull(formats[key])) {
if (process.env.NODE_ENV !== 'production') {
if (process.env.NODE_ENV !== 'production' && !this._silentTranslationWarn) {
warn(`Fall back to '${fallback}' number formats from '${locale} number formats.`)
}
_locale = fallback
Expand Down Expand Up @@ -640,7 +640,7 @@ export default class VueI18n {
const ret: ?NumberFormatResult =
this._localizeNumber(value, locale, this.fallbackLocale, this._getNumberFormats(), key, options)
if (this._isFallbackRoot(ret)) {
if (process.env.NODE_ENV !== 'production') {
if (process.env.NODE_ENV !== 'production' && !this._silentTranslationWarn) {
warn(`Fall back to number localization of root: key '${key}' .`)
}
/* istanbul ignore if */
Expand Down

0 comments on commit 402092b

Please sign in to comment.