Skip to content
This repository has been archived by the owner on Dec 31, 2024. It is now read-only.

Disable warnings for fallback to root locale #139

Closed
SebastianS90 opened this issue Apr 7, 2017 · 15 comments
Closed

Disable warnings for fallback to root locale #139

SebastianS90 opened this issue Apr 7, 2017 · 15 comments
Labels
good first issue Good for newcomers

Comments

@SebastianS90
Copy link
Contributor

vue & vue-i18n version

2.2.6, 6.0.0

Steps to reproduce

Use the example for component locales

What is Expected?

No warning in developer console

What is actually happening?

[vue-i18n] Value of key 'message.greeting' is not a string!
[vue-i18n] Fall back to translate the keypath 'message.greeting' with root locale.

My use case for component locales is as follows:

  • Commonly used words are global locales (firstname, lastname, ...)
  • Each page in my SPA ships with its own component locales (benefits from code splitting: only load locales for the current page)
  • The page component uses both global and component locales

Right now I get warnings whenever I use a global locale. They go away when compiling for production, but it is still annoying as it interrupts the development process. Can you please provide a way to disable these warnings?

@victor-am
Copy link

victor-am commented Aug 23, 2017

Any thoughts on this @kazupon? 🤔

-- Edit

Hmmm, seems like the silentTranslationWarn option does the trick, are there any side effects?

@dnomak
Copy link

dnomak commented Nov 22, 2017

In case of someone need it

new VueI18n({
  locale,
  messages,
  silentTranslationWarn: true
})

@jsfeldman
Copy link

Based on the description of fallbackRoot it seems like setting fallbackRoot to true should stop this warning from logging as well, but I still get the message. It seems like silentTranslationWarn might stop you from seeing all warnings rather than just ones with valid fallbacks.

If there was a way to specify that the translation should come from the root, it might be a good way to confirm it's being done purposefully, but it might end up making things too verbose.

@alxmagro
Copy link

In my opinion, if fallbackRoot is false and value of key was not found, it's should warning, and is returned the key, as documented.

If fallbackRoot is true, the warning should only be triggered if the key value is not found, neither in the current locale, nor in root locale.

@SzNagyMisu
Copy link
Contributor

Considering what @jsfeldman suggests

specify that the translation should come from the root

a possibility could be to implement something like the "lazy" lookup of rails i18n, and decide that component based translations should always start with a . (v-t="'.path.to.localMessage'"). On the other hand it would surely break tons of existing code, and also it seems unnecessary, since the fallback system works great.

Personally, I'm on @AlexandreMagro 's opinion: there should be a way to configure vue-i18n so that one gets warning if and only if there is no translation available neither on component nor on root level.

@clementmas
Copy link

Hey @kazupon, would you consider re-opening this issue based on @AlexandreMagro 's suggestion?

I do want to be warned when a translation is missing but right now it's impossible to see it in the middle of all the "Fall back with root locale" warnings.

@FlorianWendelborn
Copy link

Any news or workarounds on this issue? It makes it pretty much insane to use this feature and the fix should probably be trivial to implement.

@SzNagyMisu
Copy link
Contributor

What about indtroducing another option, like silentFallbackWarn?

Then warnings like

[vue-i18n] Value of key 'path.to.translation' is not a string!
[vue-i18n] Fall back to translate the keypath 'path.to.translation' with 'en-US' locale.
// OR
[vue-i18n] Fall back to translate the keypath 'path.to.translation' with root locale.

would appear only if silentFallbackWarn is not set to true or (the first one) if we are on root level and still no translation is found.

It would help more than silencing all translation warnings since it shows if there is really no translation provided.

I think I could submit a PR.

@exoego
Copy link
Collaborator

exoego commented Jan 16, 2019

I think new option to suppress warning increase complexity.
Instead, I suggest make every warning is produced only while development mode (vue-i18n.js, not min.js).

@gmw-web
Copy link

gmw-web commented Jan 17, 2019

Instead, I suggest make every warning is produced only while development mode (vue-i18n.js, not min.js).

While developing, the output generated by this plugin is extensive and fills up the console. This makes developing harder as the output of other elements gets lost between all the warnings from vue-i18n.

I would only like to see the plugin warn me if no translation is found at all, but not for an intended fallback.

@SzNagyMisu
Copy link
Contributor

@exoego I cannot really imagine a situation when adding new logic to a code does not increase its complexity :-)

By the way, there is no warning in production, it is already part of the code, in src/index.js every call to warn is placed inside

if (process.env.NODE_ENV !== 'production'/* && ... */) {
  warn(/* ... */)
}

And in development there is a possibility to silent all translation warnings (silentTranslationWarn: true).

What would be more welcome, however, is the possibility to silent warnings for intentional fallback and keep them for when there is really no translation at all (typos, missing paths...)

If by 'increasing complexity' you mean that we should be able to handle this with the existing option silentTranslationWarn, I am in for it too. Then it could receive true or, say, 'all' to silent all translation warnings, and 'fallback' to warn where no translation is found at all.

What do you think about it?
@kazupon what is your opinion?

SzNagyMisu pushed a commit to SzNagyMisu/vue-i18n that referenced this issue Jan 18, 2019
* feature(option): add silentFallbackWarn to VueI18n constructor
  * silence fallback warnings
  * warn only if no translation is found at all
@kazupon
Copy link
Owner

kazupon commented Jan 19, 2019

@SzNagyMisu
I look your proposal is good.
You can contribute it.

when there is really no translation at all (typos, missing paths...)

I feel that improvement is necessary for that.
I got feedback from some users.

Maybe, I'll plan to provide VSCode extension, or API.
#508

@kazupon kazupon reopened this Jan 19, 2019
@kazupon
Copy link
Owner

kazupon commented Jan 19, 2019

@SzNagyMisu
However, the warning suppression options is increased complexity.
We should be used a suppress warning option with bit operation flags (e.g. flag1 & flag2 ).

kazupon pushed a commit that referenced this issue Jan 23, 2019
* ⚡ improvement(option): silentFallbackWarn (#139)

* feature(option): add silentFallbackWarn to VueI18n constructor
  * silence fallback warnings
  * warn only if no translation is found at all

* adding typescript property declaration

* 📝 docs(options): document silentFallbackWarn

* Update vuepress/api/README.md

Co-Authored-By: SzNagyMisu <[email protected]>

* ⚡ improvement(option): silentFallbackWarn

* include case when pathRet is not null, undefined, array, plain object or string
* provide test case
@scriptcoded
Copy link

For anyone wondering it might be worth mentioning that PR #510 adds a new option, silentFallbackWarn, which if set to true silences all fallback warnings.

new VueI18n({
  locale,
  messages,
  silentFallbackWarn: true
})

@WormGirl
Copy link

WormGirl commented Nov 20, 2019

In my opinion, if fallbackRoot is false and value of key was not found, it's should warning, and is returned the key, as documented.

If fallbackRoot is true, the warning should only be triggered if the key value is not found, neither in the current locale, nor in root locale.

Is there a plan to release a version?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests