Comments (5)
Hi @Eiskis,
I understand your use case, but I am not sure if providing a message exists function is the best way to go about this. Especially edge cases with variable replacements and pluralization might be hard to get right as well.
Maybe another way to go about this would be to have the option to provide a default translation for a key (as second argument)
computed: {
pageTitle: function () {
var messageKey = 'pageTitles.' + this.$route.name;
return 'My App' + this.$t(key, '');
}
}
from vuex-i18n.
I added the function $i18n.keyExists to the plugin in version 1.3.7. Might come in handy for other use cases as well.
I will also think a little more about the option to provide a default translation key.
from vuex-i18n.
Thanks for the quick response and quick fix! I'll use keyExists
for now to get around this.
I like the default translation approach a lot actually, cuts down on the boilerplate and provides a good pattern to the user that can also be documented easily. Basically I don't think rendering keys makes sense in production very often (if ever?), but now they serve as default translations which the user has no control over. This would be really useful, other localisation solutions probably have something similar.
from vuex-i18n.
Our initial idea was, that the key itself would be the default translation. This way you would not have to think about keys for translations strings but just use the translation string directly.
However, this proved to be not working so well if using multiple locales and changing the translations later on. Therefore the default option would probably make more sense.
from vuex-i18n.
That's exactly my experience as well. Having douple-purpose keys like that is tricky because then those keys will be in constant flux and the default translations will have to be synced across all localisation files, and thus might be duplicated who knows how man times. It's better to separate those concerns.
from vuex-i18n.
Related Issues (20)
- Support for yarn HOT 1
- What is the current version? HOT 3
- The v1.10.7 introduced a couple of breaking changes: Comparison vs v1.10.5 HOT 5
- Not able to access i18 plugin from mutation in classic mode store in Nuxt application HOT 1
- Usage of special characters inside the translations ( ) HOT 2
- Testing the fallback language - Chai HOT 2
- Single File Component Children not updating HOT 3
- Hook custom logic for non existent keys in lang HOT 2
- nuxt example implementation HOT 2
- Improve typescript declarations HOT 3
- Improve plugin documentation
- Multiple modules HOT 2
- What about provide plugin for debugging content HOT 1
- Using square brackets in identifier does not work HOT 2
- Linked local messages HOT 1
- Set Fallback language File HOT 5
- How to translate a component attribute/property
- Unicode-Support?
- support change language key before render ?
- Option to suppress the `i18n: Not all placeholders found` console warnings HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vuex-i18n.