Comments (5)
Language-only locales are not supported (because they are often not useful). You need to provide a mapping of languages to full locales. E.g.:
{
map: {
ja: 'ja_JP'
}
}
Meaning: you need to tell the middleware what the defaults of your project are.
from express-locale.
But Google Chrome always return 'ja' in Japanese Environment, so your module always returns "en-US" as default. In Japan, There is no locale ( only Japan, mean ja-JP is the only language-locale ) so we often use only 'ja'. I think there is a language which has a related situation in the world. I understand what you mean, but that problem comes from historical things of browser and that always causes problem for us. At least you should implement the mapping in the module from the first ( not option ).
FYI
My Google Chrome laungage setting : Japanese, English(US), English
-> Accept-Language Header : ja,en-US;q=0.9,en;q=0.8
from express-locale.
I think there are some misconceptions in your view on this module (or locales in general).
This is not related to browsers.
Regions(/countries)/languages are not set in stone. They change.
That means some languages might only be related to one region now but not tomorrow.
There is no such thing as a fixed list of locales where there is only one region for one language forever.
The idea is that you provide what your project's defaults are. You know your project best.
It comes down to this in your example:
What happens when a new region is added where Japanese is spoken?
express_locale
shouldn't decide this for you.
from express-locale.
I understand what you meant to say. But if the module needs to determine the "locale" by Accept-"Language" header of web browser, the module should return most related "locale," isn't it? for example, en -> en-US ( of cause someone would say this should be en-GB!) , fr-> fr-FR, ja -> ja-JP. So I think that it would be better your module supports the default mapping list which can be replaced by users, or at least the module should not return "en-US" as default if there is no locale if that is your policy. I think that current spec causes just confusing for module users. Thanks.
from express-locale.
What is the "most related" region for en
? Or for fr
?
It depends on your project.
en_US
is only returned because you allow it to be returned. There is a property allowed
which should not contain en_US
in your case.
Based on the information you provided, your configuration should be something like:
{
priority: ['accept-language', 'map', 'default'],
map: {
ja: 'ja_JP'
},
default: 'ja_JP',
allowed: ['ja_JP']
}
But, I assume you support at least one additional locale? If not, you don't even need this module.
from express-locale.
Related Issues (16)
- Parse short codes HOT 2
- Add support for debug HOT 2
- Add option to limit accepted locales HOT 2
- Setting allowed breaks to undefined HOT 2
- add config sanity checks HOT 1
- Date.toLocaleString (native) - RangeError: Invalid language tag: en_US HOT 3
- Invalid locale hard coded 'en_UK'; HOT 1
- Unclear interaction between `map` and `allowed` HOT 3
- The map parameter shows no effect HOT 1
- Always defaults HOT 3
- figure out missing region information HOT 5
- 1.0.0 roadmap HOT 2
- Query lookup doesnโt appear to be bundled HOT 10
- allow for setting language not based on region HOT 3
- Error: Cannot find module 'babel-polyfill' HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from express-locale.