@@ -19,6 +19,7 @@ export default class VueI18n {
1919 _missing : ?MissingHandler
2020 _exist : Function
2121 _watcher : any
22+ _silentTranslationWarn : boolean
2223
2324 constructor ( options : I18nOptions = { } ) {
2425 const locale : Locale = options . locale || 'en-US'
@@ -29,7 +30,12 @@ export default class VueI18n {
2930 this . _missing = options . missing || null
3031 this . _root = options . root || null
3132 this . _sync = options . sync === undefined ? true : ! ! options . sync
32- this . _fallbackRoot = options . fallbackRoot === undefined ? true : ! ! options . fallbackRoot
33+ this . _fallbackRoot = options . fallbackRoot === undefined
34+ ? true
35+ : ! ! options . fallbackRoot
36+ this . _silentTranslationWarn = options . silentTranslationWarn === undefined
37+ ? false
38+ : ! ! options . silentTranslationWarn
3339
3440 this . _exist = ( message : Object , key : Path ) : boolean => {
3541 if ( ! message || ! key ) { return false }
@@ -86,12 +92,15 @@ export default class VueI18n {
8692 get formatter ( ) : Formatter { return this . _formatter }
8793 set formatter ( formatter : Formatter ) : void { this . _formatter = formatter }
8894
95+ get silentTranslationWarn ( ) : boolean { return this . _silentTranslationWarn }
96+ set silentTranslationWarn ( silent : boolean ) : void { this . _silentTranslationWarn = silent }
97+
8998 _warnDefault ( locale : Locale , key : Path , result : ?any , vm : ?any ) : ?string {
9099 if ( ! isNull ( result ) ) { return result }
91100 if ( this . missing ) {
92101 this . missing . apply ( null , [ locale , key , vm ] )
93102 } else {
94- if ( process . env . NODE_ENV !== 'production' ) {
103+ if ( process . env . NODE_ENV !== 'production' && ! this . _silentTranslationWarn ) {
95104 warn (
96105 `Cannot translate the value of keypath '${ key } '. ` +
97106 'Use the value of keypath as default.'
@@ -116,7 +125,7 @@ export default class VueI18n {
116125 if ( isPlainObject ( message ) ) {
117126 ret = message [ key ]
118127 if ( typeof ret !== 'string' ) {
119- if ( process . env . NODE_ENV !== 'production' ) {
128+ if ( process . env . NODE_ENV !== 'production' && ! this . _silentTranslationWarn ) {
120129 warn ( `Value of key '${ key } ' is not a string!` )
121130 }
122131 return null
@@ -128,7 +137,7 @@ export default class VueI18n {
128137 if ( typeof pathRet === 'string' ) {
129138 ret = pathRet
130139 } else {
131- if ( process . env . NODE_ENV !== 'production' ) {
140+ if ( process . env . NODE_ENV !== 'production' && ! this . _silentTranslationWarn ) {
132141 warn ( `Value of key '${ key } ' is not a string!` )
133142 }
134143 return null
@@ -166,7 +175,7 @@ export default class VueI18n {
166175
167176 res = this . _interpolate ( messages [ fallback ] , key , args )
168177 if ( ! isNull ( res ) ) {
169- if ( process . env . NODE_ENV !== 'production' ) {
178+ if ( process . env . NODE_ENV !== 'production' && ! this . _silentTranslationWarn ) {
170179 warn ( `Fall back to translate the keypath '${ key } ' with '${ fallback } ' locale.` )
171180 }
172181 return res
@@ -183,7 +192,7 @@ export default class VueI18n {
183192
184193 const ret : any = this . _translate ( messages , locale , this . fallbackLocale , key , parsedArgs . params )
185194 if ( this . _isFallbackRoot ( ret ) ) {
186- if ( process . env . NODE_ENV !== 'production' ) {
195+ if ( process . env . NODE_ENV !== 'production' && ! this . _silentTranslationWarn ) {
187196 warn ( `Fall back to translate the keypath '${ key } ' with root locale.` )
188197 }
189198 if ( ! this . _root ) { throw Error ( 'unexpected error' ) }
0 commit comments