Get current locale value (string or array?)
See original GitHub issue- [yes] I am on the latest ember-intl version
- [yes] I have searched the issues of this repo and believe that this is not a duplicate
Environment
- Ember Version: 3.5.0
- Ember CLI Version: 3.5.0
- Ember Intl Version: latest
- Browser(s): chromium v68
- Node Version: 8.11.3
I need the current locale at different instances in my application, to get the current locale I use:
this.get('intl').get('locale')
This always returns an array with a single string value, is there a way to just return te value instead of an array with a single element?
My value was set using
this.get('intl').setLocale('en')
How do I get a return of “en” instead of [“en”] ?
I was searching the docs when I noticed this:
Locale
Set/get the current locale for your application. The value can either be a String or an Array of Strings.
But couldn’t find more info about when which return is given.
Thanks in advance
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Get string from default locale using string in specific locale
The code below will retrieve localized string for polish language even if the default locale on the device is different:
Read more >Array.prototype.toLocaleString() - JavaScript - MDN Web Docs
The toLocaleString() method returns a string representing the elements of the array. The elements are converted to Strings using their ...
Read more >Locale (Java Platform SE 8 ) - Oracle Help Center
Returns a locale for the specified IETF BCP 47 language tag string. Returns an array of all installed locales.
Read more >Internationalization with Java Locale | Phrase
You can create a priority list using a set of language ranges. ... rangeString is a valid string with set of locales and...
Read more >Set locale information
If locale is NULL or the empty string "", the locale names will be set from the values of environment variables with the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@buschtoens With
primaryLocale
, do you mean the currently Active locale or the primary locale in the locales[].If it’s the current Active locale, that would be very helpful!
Because
setLocale
accepts an array of locales in order to support fallbacks. This is the reason, why there is no “one” locale. There is only a primary locale and a number of fallback locales.You could access
this.get('intl.locale.firstObject')
.We could also think about adding a
primaryLocale
to theintl
service for convenience.