-
-
Notifications
You must be signed in to change notification settings - Fork 861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
silence fallback warnings #510
Conversation
* feature(option): add silentFallbackWarn to VueI18n constructor * silence fallback warnings * warn only if no translation is found at all
Codecov Report
@@ Coverage Diff @@
## dev #510 +/- ##
==========================================
+ Coverage 96.73% 96.75% +0.02%
==========================================
Files 9 9
Lines 674 679 +5
==========================================
+ Hits 652 657 +5
Misses 22 22
Continue to review full report at Codecov.
|
src/index.js
Outdated
@@ -230,7 +236,7 @@ export default class VueI18n { | |||
if (isPlainObject(message)) { | |||
ret = message[key] | |||
if (typeof ret !== 'string') { | |||
if (process.env.NODE_ENV !== 'production' && !this._silentTranslationWarn) { | |||
if (process.env.NODE_ENV !== 'production' && !this._silentTranslationWarn && !(this._silentFallbackWarn && (this._isFallbackRoot() || locale !== this.fallbackLocale))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kazupon is it ok to check locale !== this.fallbackLocale
? I got confused because _translate
gets fallback
as a param, but it always points to this.fallbackLocale
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we have a similar condition in line 246/252. I don't really understand the use case for that (boolean? number?) and I didn't find any tests, so I dared not touch to that. Should it contain the same logic? How do I test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it ok to check
locale !== this.fallbackLocale
?
Yes, that's right!
I got confused because
_translate
getsfallback
as a param, but it always points tothis.fallbackLocale
.
The current vue-i18n is very complexity due to none of your business. 😭 In next major version, I will to write with full-scratch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we have a similar condition in line 246/252.
Just as you said, these is similar condition.
In unit test coverage (the following is removed /* istanbul ignore else */
), the code of 246/249 is not passed in unit tests.
However, t
or $t
is returned the value of TranslateResult
Line 12 in e879024
type TranslateResult = string | LocaleMessages; |
If you want to add a test case, we will be very helpful if you do so.
Although it is a bad design as API 😂, We need to maintain backwards compatibility.
In next major version, I'll plan to change this specification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your PR!
I've reviewed your PR 👀
Please check it!
src/index.js
Outdated
@@ -230,7 +236,7 @@ export default class VueI18n { | |||
if (isPlainObject(message)) { | |||
ret = message[key] | |||
if (typeof ret !== 'string') { | |||
if (process.env.NODE_ENV !== 'production' && !this._silentTranslationWarn) { | |||
if (process.env.NODE_ENV !== 'production' && !this._silentTranslationWarn && !(this._silentFallbackWarn && (this._isFallbackRoot() || locale !== this.fallbackLocale))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it ok to check
locale !== this.fallbackLocale
?
Yes, that's right!
I got confused because
_translate
getsfallback
as a param, but it always points tothis.fallbackLocale
.
The current vue-i18n is very complexity due to none of your business. 😭 In next major version, I will to write with full-scratch.
src/index.js
Outdated
@@ -230,7 +236,7 @@ export default class VueI18n { | |||
if (isPlainObject(message)) { | |||
ret = message[key] | |||
if (typeof ret !== 'string') { | |||
if (process.env.NODE_ENV !== 'production' && !this._silentTranslationWarn) { | |||
if (process.env.NODE_ENV !== 'production' && !this._silentTranslationWarn && !(this._silentFallbackWarn && (this._isFallbackRoot() || locale !== this.fallbackLocale))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we have a similar condition in line 246/252.
Just as you said, these is similar condition.
In unit test coverage (the following is removed /* istanbul ignore else */
), the code of 246/249 is not passed in unit tests.
However, t
or $t
is returned the value of TranslateResult
Line 12 in e879024
type TranslateResult = string | LocaleMessages; |
If you want to add a test case, we will be very helpful if you do so.
Although it is a bad design as API 😂, We need to maintain backwards compatibility.
In next major version, I'll plan to change this specification.
Co-Authored-By: SzNagyMisu <szijjartonagy.misu@gmail.com>
* include case when pathRet is not null, undefined, array, plain object or string * provide test case
silentFallbackWarn: true, | ||
messages: { | ||
en: { winner: 'winner' }, | ||
hu: { winner: true } // translation value is boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kazupon is it the right use case? boolean
, number
etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it the right use case?
yes! that's correct!not a string
is warning!
silentFallbackWarn: true, | ||
messages: { | ||
en: { winner: 'winner' }, | ||
hu: { winner: true } // translation value is boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it the right use case?
yes! that's correct!not a string
is warning!
@SzNagyMisu Thanks! |
Thanks for the opportunity! |
Thank you so much for this feature <3 ! |
Question: How do we silence warning messages when there is no translation at all? I'm using Vue-I18n in an application framework where we probably will never actually need to translate to languages other than English, but Vue-I18n is very useful for loading configuration information. I'm finding that in a lot of cases it's less code to just write |
@jbnv |
That helps. Thanks. |
aims to fix #139
warnings should be silenced for fallback but not if there is no translation at all.
PR is incomplete as yet, but still have some questions.