Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List of available languages #193

Closed
cirience-zz opened this issue Jul 8, 2017 · 10 comments · May be fixed by tt9133github/snyktest#3 or ajesse11x/vuetify#5
Closed

List of available languages #193

cirience-zz opened this issue Jul 8, 2017 · 10 comments · May be fixed by tt9133github/snyktest#3 or ajesse11x/vuetify#5

Comments

@cirience-zz
Copy link

I'd like to have an feature which allows me to output all available languages with one method. That would allow to make a list of all available translations.

@kazupon
Copy link
Owner

kazupon commented Jul 8, 2017

Thank you for your feedback.

However, I could not understand the reason of your feedback.
Could you talk us more explanation please?

@thoean
Copy link

thoean commented Jul 12, 2017

I started using https://github.com/bdswiss/country-language, which has methods to retrieve ISO standard names for languages, as well as country specific mapping.

@cirience-zz
Copy link
Author

When I'm adding the 'messages' to your plugin, I'm creating different Objects like en, de, ja. I'd think it would be useful if there is an built-in function to get all 'Objects' which are basically languages-codes in my case.

@eagerestwolf
Copy link

In the meantime until this comes to fruition, I did find a stop gap:

computed: {
  languages() {
    return Object.keys(this.$i18n.messages);
  }
}

@rimiti
Copy link

rimiti commented Mar 6, 2019

@kazupon It could be nice to provide a getLocales() method which returns an array of the available locales: ['en', 'fr', 'pt'].

PS: With the same result of the @sethmurphy18 snippet.

@exoego
Copy link
Collaborator

exoego commented Mar 6, 2019

Could someone provide use-case for this feature?

I imagine this may be useful to create language selector UI which shows available languages based on messages objects.
But not sure.

@rimiti
Copy link

rimiti commented Mar 6, 2019

Example:
If you want to redirect a user to a path (with locale):

routes: [
    {
      path: '/', redirect: (to) => {
        const browserLocale = getBrowserLocale();
        if (Object.keys(VueI18n.messages).includes(browserLocale)) {
          return `/${browserLocale}`;
        }

        return `/${VueI18n.fallbackLocale}`;
      },
    },
]

@exoego
Copy link
Collaborator

exoego commented Mar 7, 2019

@rimiti
That use-case totally makes sense 👍

exoego pushed a commit to exoego/vue-i18n that referenced this issue Mar 7, 2019
exoego pushed a commit to exoego/vue-i18n that referenced this issue Mar 7, 2019
exoego pushed a commit to exoego/vue-i18n that referenced this issue Mar 7, 2019
@rimiti
Copy link

rimiti commented Mar 7, 2019

It's a good job @exoego, you rock 🚀

exoego pushed a commit to exoego/vue-i18n that referenced this issue Mar 8, 2019
exoego pushed a commit to exoego/vue-i18n that referenced this issue Mar 8, 2019
kazupon pushed a commit that referenced this issue Mar 8, 2019
…exoego

* feat(index): Fix #193 add availableLocales

* Update src/index.js

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

* feat(index): Fix #193 add type definition to availableLocales

* fix(index): add missing type definition to numberFormats

* fix(index): Fix #193 add docs to availableLocales

* Update vuepress/api/README.md

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

* fix(index): Fix #193 ensure order of locales
@haceneouserir
Copy link

You can do that by "availableLocales" option.
e.g: (i18n.availableLocales), will return an array that has a list of available locales.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants