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.

Fallback to langcode if locale unknown

See original GitHub issue

There are few situations, which covers following issue:

  • Numbro won’t try to match langcode in case full locale is unknown

    Let’s say we have locale es-ARG. Numbro doesn’t have such locale and thus will throw error about unknown locale, but it can at least try to match langcode (es). In some very rare scenarios it isn’t best approach, but it will work for most cases. It’s better then receive unformatted value.

  • Numbro will ignore locales, which consists only from langcode. For example, ru is same as ru-RU. Numbro won’t accept ru as locale name, despite it’s perfectly valid.

  • Sometimes we want to provide just langcode and let fortune decide for which exactly country formatting should be picked up — for most languages it’s ok

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
BenjaminVanRyseghemcommented, Oct 17, 2015

numbro.setLanguage seems exactly what we need. However, it’s marked as depreciated. Will it be incorporated somewhere?

We may keep it, it’s still under discussion 😄

How it works is:

  • numbro.setLocale(‘ru-BR’, ‘fr-FR’):
    • first try to match the exact code;
    • second try tom find a code matching ru-*
    • third, if a default is provided, falls back to it (french here)
    • otherwise falls back to en-US
  • numbro.setCulture(‘ru-BR’, ‘fr-FR’):
    • first try to match the exact code;
    • second try tom find a code matching *-BR
    • third, if a default is provided, falls back to it (french here)
    • otherwise falls back to en-US

Hope it helps

0reactions
gwynjuddcommented, Mar 30, 2017

@timmcintosh one way to hard code the behaviour we want is to make an alias like this:

var zhTW = numbro.cultureData('zh-TW');
numbro.culture('zh-Hant', zhTW);

I’m leaning towards us doing this kind of thing instead of spending too much effort changing the fallback code to make it more complex.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring MVC: Fallback for unknown language code in uri ...
My suggestion would be to subclass the SessionLocaleResolver and override the getLocale method: @SpringBootApplication public class ...
Read more >
Error if folder doesn't exist when using fallbackLng #1941
We should first check whether the folder exists before reading from it. If default locale is specified, and its folder doesn't exist, fallback...
Read more >
Locale | Android Developers
Returns the name of this locale's language, localized to locale . If the language name is unknown, the language code is returned.
Read more >
API - i18next documentation
An error can occur if for example there was a loading issue when using a backend plugin. i18next.init({. fallbackLng: 'en',. ns: ['file1', 'file2'],....
Read more >
locale.module - Backdrop CMS Documentation
Add language handling functionality and enables the translation of the user interface to languages other than English. When enabled, multiple languages can ...
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