Skip to content
This repository has been archived by the owner on Mar 13, 2022. It is now read-only.

feat: i18n locale auto-detect (issue #153) #152

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

tomers
Copy link
Contributor

@tomers tomers commented May 12, 2021

This PR makes the app auto-detect browser locale and set it.

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

The local selection behavior would change. It will now select the locale from the browser, instead of from the hard-coded default.

@tomers tomers changed the title feat: i18n locale auto-detect feat: i18n locale auto-detect (issue #153) May 12, 2021
@IlCallo IlCallo changed the base branch from master to dev August 10, 2021 08:56
@IlCallo
Copy link
Member

IlCallo commented Aug 10, 2021

There are a couple of problems here:

  • navigator.userLanguage isn't standard and should be removed, since we don't support IE anymore
  • the PR should be rebased on latest changes for Qv2 (both on Quasar and vue-i18n side)
  • why is String(...) used? Doesn't navigator.language always return a string?
  • there's no default language in case the one from the browser isn't available into messages object. fallbackLocale option will help in those cases, but it will emit a lot of warnings

Can you address these problems?

@MatthewSH
Copy link

I just happened to notice this and figured I'd also respond.

To respond directly to you @IlCallo, yeah. It does return a DOMString/String. Not sure why we're creating a string again, maybe a precaution for that off chance you get a weird locale back that's not valid, but then it would use fallbackLocale in that case.

The code should probably be:

locale: navigator.language || 'en-us'

However, here's something else. If we wanted to support auto-detection of the locale through navigator, couldn't we opt for possibly something like this?

locale: navigator.languages[0] || navigator.language || 'en-us'

Languages will return an array of preferred languages if I can recall correctly and the navigator.language comes from that. I don't know, may not be worth the extra effort because, although it's widely supported in current browser versions, it [navigator.languages] may still be marked as experimental.

michaldolensky added a commit to michaldolensky/ecollector that referenced this pull request Aug 21, 2021
MatthewSH added a commit to MatthewSH/quasar-starter-kit that referenced this pull request Aug 23, 2021
Closes quasarframework#153. Original PR quasarframework#152 by tomers.
Co-authored-by: Tomer Shalev <tshalev@proofpoint.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants