How to obtain a registry of consulted keys #1646
-
So I have a very big legacy project where i18n was used for translation, but one of the languages was a little left behind. A while back we started refactoring, which led to changing many keys, and adding some others. The thing is that now, a new language wants to be added, and the one that was left behind needs to be updated. Therefore, I wanted to know if there is any plugin/setting/etc... that would allow me to log into a log file of some sort all keys that are consulted in runtime. I know that there's i18n-extract that does static file analysis, but that leaves out dynamically set values. I'm using VUE 2 / vue-i18n v8.x Thank you for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Ok so, after some code inspection, I realized that there's a I think it’s a cool feature, that I couldn't find anywhere in the documentation really, and could be nice to add it there! Dummy example of my setup that allows me to log every computed key: export default new VueI18n({
locale: process.env.VUE_APP_I18N_LOCALE || 'es',
fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'es',
messages: loadLocaleMessages(),
postTranslation: (translatedValue, key) => {
console.log(`i18n(${key}) => ${translatedValue}`);
return translatedValue;
},
});```
then i get something like
`> i18n(hello.world) => Hello, World!` |
Beta Was this translation helpful? Give feedback.
Ok so, after some code inspection, I realized that there's a
postTranslation
hook that can be used for this purpose. From the call of it, I figured that it's interface is that it receives two arguments: the translated value and the key used to fetch it, and needs to return the translation.I think it’s a cool feature, that I couldn't find anywhere in the documentation really, and could be nice to add it there!
Dummy example of my setup that allows me to log every computed key: