Coder Social home page Coder Social logo

Comments (5)

smhg avatar smhg commented on June 14, 2024

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.

kazkondo avatar kazkondo commented on June 14, 2024

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.

smhg avatar smhg commented on June 14, 2024

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.

kazkondo avatar kazkondo commented on June 14, 2024

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.

smhg avatar smhg commented on June 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.