Skip to content
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

Merged
merged 5 commits into from
Jan 23, 2019
Merged

Conversation

SzNagyMisu
Copy link
Contributor

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.

Szijjártó Nagy Misu added 2 commits January 18, 2019 08:35
* feature(option): add silentFallbackWarn to VueI18n constructor
  * silence fallback warnings
  * warn only if no translation is found at all
@codecov-io
Copy link

codecov-io commented Jan 21, 2019

Codecov Report

Merging #510 into dev will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/mixin.js 96.82% <100%> (+0.05%) ⬆️
src/index.js 99.65% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e879024...9a9da76. Read the comment docs.

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))) {
Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Owner

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 gets fallback as a param, but it always points to this.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.

Copy link
Owner

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.

image

However, t or $t is returned the value of TranslateResult

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.

Copy link
Owner

@kazupon kazupon left a 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))) {
Copy link
Owner

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 gets fallback as a param, but it always points to this.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))) {
Copy link
Owner

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.

image

However, t or $t is returned the value of TranslateResult

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.

vuepress/api/README.md Outdated Show resolved Hide resolved
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
Copy link
Contributor Author

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?

Copy link
Owner

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
Copy link
Owner

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!

@kazupon
Copy link
Owner

kazupon commented Jan 23, 2019

@SzNagyMisu Thanks!

@SzNagyMisu
Copy link
Contributor Author

Thanks for the opportunity!

@SzNagyMisu SzNagyMisu deleted the m_fallback_warning branch January 23, 2019 11:25
@meelie
Copy link

meelie commented Feb 7, 2019

Thank you so much for this feature <3 !

@jbnv
Copy link

jbnv commented Jan 30, 2020

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 $t('Some text here') without defining a translation. But that results in a lot of unneeded warning messages.

@SzNagyMisu
Copy link
Contributor Author

@jbnv
I would recommend considering the constructor option silentTranslationWarn or missing.
There might be other options better tailored to your need, so having a look at each constructor option might lead you to something I missed.

@jbnv
Copy link

jbnv commented Jan 31, 2020

That helps. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants