Code Monkey home page Code Monkey logo

Comments (5)

tikiatua avatar tikiatua commented on May 25, 2024

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.

tikiatua avatar tikiatua commented on May 25, 2024

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.

jerryjappinen avatar jerryjappinen commented on May 25, 2024

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.

tikiatua avatar tikiatua commented on May 25, 2024

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.

jerryjappinen avatar jerryjappinen commented on May 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.