question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
driesdlcommented, Nov 22, 2018

@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!

1reaction
buschtoenscommented, Nov 20, 2018

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 the intl service for convenience.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found