-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
The code for setting `config["lang"]`, in `isso/app/config.js`, assumes that browsers will always provide a value for `navigator.language` and/or `navigator.userLanguage`. Per bug #521, this is not a safe assumption. While I was attempting to fix this, I noticed that regional variants of a language (`zh-TW`, `pt-BR`) were being handled in an ad-hoc, unreliable manner. I also noticed a new user-agent language property [`navigator.languages`][] which more closely matches the semantics of [`Accept-Language`][]—it would be good to support that. This patch addresses all the above problems, as follows: 1. Add a new configuration property `data-isso-default-lang` that specifies the language to use (instead of English) when the browser *doesn’t* have a preference. 2. Document that we expect the value of `data-isso-lang` and `data-isso-default-lang` to be a [BCP 47][] language tag, because this is what `navigator.language` etc contain. (The practical upshot is that tags like `zh-TW` are officially allowed now.) 3. In `config.js`, compile an array of candidate language tags, in descending order of preference, from all available sources: `data-isso-lang`, `navigator.languages`, `navigator.language`, `navigator.userLanguage`, `data-isso-default-lang`, and finally `"en"` as a backstop. Handle any or all of the above being null/undefined/empty. This array goes into `config["langs"]`. `config["lang"]` is removed. 4. In `i18n.js`, select the first entry in `config["langs"]` for which we have both pluralforms and a translation, and make that the value of `i18n.lang`. An English backstop is supplied here too for extra defensiveness. Also, if we don’t have a translation for say `zh-HK`, try `zh` before moving on to the next entry in the array. 5. New function `utils.normalize_bcp47` ensures that we process language tags, whereever they came from, case-insensitively and treating `_` as equivalent to `-`. 6. Move `utils.ago` to `i18n.ago` to avoid a circular dependency between utils and i18n. [`navigator.languages`]: https://developer.mozilla.org/en-US/docs/Web/API/NavigatorLanguage/languages [`Accept-Language`]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language [BCP 47]: https://tools.ietf.org/html/bcp47
- Loading branch information
Showing
6 changed files
with
176 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters