kazupon / vue-i18n

:globe_with_meridians: Internationalization plugin for Vue.js
https://kazupon.github.io/vue-i18n/
MIT License
7.27k stars 860 forks source link

`missing` option still generates warnings #1155

Open fabis94 opened 3 years ago

fabis94 commented 3 years ago

Module versions (please complete the following information):

To Reproduce Use missing Vuei18n contructor option to set a function that ignores all errors, something like this:

function missing() {
 return "whatever";
}

Then use one of the translation methods in a Vue template for a key that doesn't exist in any of the translation files:

<span>$t("This isn't defined in any translation file!")</span>

You'll still get the following warning in development mode:

Value of key 'This isn't defined in any translation file!' is not a string or function!

Expected behavior From the docs it looks like the above implementation of missing (https://kazupon.github.io/vue-i18n/api/#constructor-options) should suppress all warnings, but it doesn't.

Additional context From the source code of this package it looks like missing is only used for the first warning that appears - "Cannot translate the value of keypath X. Use the value of keypath as default." The other warning, however, uses no such check and thus the warning is emitted regardless.

Here you can see missing is used to skip the warning: image

Here, however, there is no check and warnings are shown always: image

I want to completely suppress all warnings for the default locale, because I'll use the key as the message and thus won't need to have any translation file for the default locale. In the case of the default locale $t('Some message') will just output Some message

I know that the API supports supressing all warnings or suppressing all warnings if the fallback locale actually has defined translations, but none of these options work for me because my default/fallback locale won't have any translations (the translation file will essentially just contain {}) and I still want warnings for when other locales have missing keys.

flavio-marchi commented 3 years ago

This is not a "Proposal" or an "Improvement". Its stated in the docs that the warnings will be prevented, but they don't.

missing Type: MissingHandler

Default: null

A handler for localization missing. The handler gets called with the localization target locale, localization path key, the Vue instance and values.

If missing handler is assigned, and occurred localization missing, it's not warned.

This is very confusing, please update the docs. And possibly fix the issue.