Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iso code for locales config not used #499

Closed
TimonPeng opened this issue Oct 21, 2019 · 12 comments
Closed

iso code for locales config not used #499

TimonPeng opened this issue Oct 21, 2019 · 12 comments

Comments

@TimonPeng
Copy link

TimonPeng commented Oct 21, 2019

https://github.com/nuxt-community/nuxt-i18n/blob/3a64fdad274571f160046f08f861aa7c3c4d7a15/src/helpers/utils.js#L15

This question is available on Nuxt community (#c330)
@ghost ghost closed this as completed Oct 21, 2019
@ghost ghost added the cmty:question label Oct 21, 2019
@ghost
Copy link

ghost commented Oct 21, 2019

This issue as been imported as question since it does not respect nuxt-i18n issue template. Only bug reports and feature requests stays open to reduce maintainers workload.
If your issue is not a question, please mention the repo admin or moderator to change its type and it will be re-opened automatically.
Your question is available at https://cmty.app/nuxt/nuxt-i18n/issues/c330.

@TimonPeng
Copy link
Author

#37 (comment)

@rchl
Copy link
Collaborator

rchl commented Oct 21, 2019

Code looks fine to me. Please provide reproducion on https://codesandbox.io because I don't understand what problem do you see here.

@TimonPeng
Copy link
Author

@rchl Review please. https://codesandbox.io/s/codesandbox-nuxt-rng17

When don't set a cookie, it always choose English not depending on the http header accept-language.

You can use the following command for environment replication.

curl 'https://rng17.sse.codesandbox.io/' -H 'accept-language: zh-CN,zh;q=0.9,ja;q=0.8' --compressed -L -v

You can see two 302 redirects happend.

  • The first time is depend on rootRedirect: "cn"
  • The second time is depend on detectBrowserLanguage? I think.

@rchl
Copy link
Collaborator

rchl commented Oct 22, 2019

In a locale defined this way:

      {
        name: "简体中文",
        code: "cn",
        iso: "zh-CN",
        file: "cn.js"
      }

The code property is used to match the browser language. In your case, it doesn't match because we match it against zh from the accept-language header, not cn. So I think the issue here is with configuration - you should change code property to zh. Same for rootRedirect.

@rchl
Copy link
Collaborator

rchl commented Oct 22, 2019

The iso code is only used for some SEO functionality, not for matching browser locale.

@TimonPeng
Copy link
Author

@rchl Ok, thank you.

Would you mind adding an alias configuration for router path or domain name?

Like apple.com:

For example:

{
  ...
  locales: [
    {
      code: 'ja',
      alias: 'jp',
      iso: 'ja-JP',
      file: 'ja-JP.js'
    },
    {
      code: 'zh-HK',
      alias: 'hk',
      iso: 'zh-HK',
      file: 'zh-HK.js'
    },
    {
      code: 'zh-TW',
      alias: 'tw',
      iso: 'zh-TW',
      file: 'zh-TW.js'
    },
  ],
  ...
}

@TimonPeng
Copy link
Author

alias is country code.

@TimonPeng
Copy link
Author

Like next-i18next's localeSubpaths.

https://github.com/isaachinman/next-i18next#5-locale-subpaths

@rchl
Copy link
Collaborator

rchl commented Oct 22, 2019

It probably makes sense to have something like that but would have to figure out how to best implement it.

Browser language detection needs to be considered also - currently it only looks at first two characters of accept-language token.

@progvb
Copy link

progvb commented Mar 3, 2020

I'm wondering what motivation was behind the decision to use only the first two characters?

rchl added a commit that referenced this issue Dec 3, 2020
Resolves #979
Resolves #499

Co-authored-by: Rafał Chłodnicki <rchl2k@gmail.com>
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants