-
Notifications
You must be signed in to change notification settings - Fork 56
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
Proposal: i18n-system-languages #569
Open
carlosjeurissen
wants to merge
27
commits into
w3c:main
Choose a base branch
from
carlosjeurissen:getOSLanguage-proposal
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
d078e45
Add getOSLanguage proposal
carlosjeurissen 7ed4c53
Update proposals/i18n-getOSLanguage.md
carlosjeurissen 916f91d
Update proposals/i18n-getOSLanguage.md
carlosjeurissen 30fbed6
Update workaround description
carlosjeurissen 1339056
Add back Sponsoring Browser with TBD
carlosjeurissen b7781f4
Add Bugzilla bug to related issues
carlosjeurissen ae8e4e2
Add Author GitHub link
carlosjeurissen 0c352e8
Add bcp47 link
carlosjeurissen 15fde77
Rephrase objective
carlosjeurissen 1bf297c
Rename IETF tags to BCP47 language tags
carlosjeurissen b9ab150
Remove > from title
carlosjeurissen da34a81
Replace chromium source reference with a permalink
carlosjeurissen 6107700
Update proposals/i18n-getOSLanguage.md
carlosjeurissen 38e9f39
Update proposal to include both getPreferredSystemLanguages and getSy…
carlosjeurissen 4eb3df1
Rename proposal file to better reflect the proposal
carlosjeurissen 280efb5
Fix proposal title
carlosjeurissen 90dec9b
Update proposals/i18n-system-languages.md
carlosjeurissen 1d995e9
Update proposals/i18n-system-languages.md
carlosjeurissen 89f08b3
Clarify the type of list returned by getPreferredSystemLanguages
carlosjeurissen 76acf81
Rewrite sentences to use locale instead of language when it makes sense
carlosjeurissen 395c02e
Add purest form use-case
carlosjeurissen 07b64c9
Update proposals/i18n-system-languages.md
carlosjeurissen e8ae3a9
Clarify additional subtags on getSystemUILanguage
carlosjeurissen 7e3c88f
Update getSystemUILanguage to be async
carlosjeurissen 64b942d
Clarify getPreferredSystemLanguages callback parameter
carlosjeurissen 42f71ae
Clarify getPreferredSystemLanguages would not insert less specific lo…
carlosjeurissen 7ac0a42
Remove additional subtags note on getSystemUILanguage
carlosjeurissen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# Proposal: i18n.getPreferredSystemLanguages() and i18n.getSystemUILanguage() | ||
|
||
**Summary** | ||
|
||
Allows getting the language(s)/locale(s) of your operating system as a [BCP47 language tag](https://www.rfc-editor.org/bcp/bcp47.html) | ||
|
||
**Document Metadata** | ||
|
||
**Author:** [carlosjeurissen](https://github.com/carlosjeurissen) | ||
|
||
**Sponsoring Browser:** Safari | ||
|
||
**Created:** 2024-03-18 | ||
|
||
**Related Issues:** | ||
https://github.com/w3c/webextensions/issues/252 | ||
https://bugzilla.mozilla.org/show_bug.cgi?id=1888486 | ||
|
||
## Motivation | ||
|
||
### Objective | ||
|
||
Allow extensions to display UI in the user's system locale(s), even when this is distinct from the browser's UI locale (which is restricted to locales supported by the browser). | ||
|
||
#### Use Cases | ||
|
||
Extension authors might want to obtain the locale used by the user agent's host environment in order to format values (such as numbers, dates, and so forth) or do other locale-affected operations (such as list sorting) according to expectations of the user. For example, formatting the date `2024-06-15` varies between `en-US` (6/15/2024) and `en-GB` (15/6/2024), whereas `i18n.getUILanguage` might return only `en` (English). | ||
|
||
Extension authors might want to obtain the locale used by the user agent's host environment to better match the runtime environment's localization. For example, the operating system might be running in `ff-NG` (Fulani as used in Nigeria), but the user agent might not be localized for this locale and return `en` (English) for `i18n.getUILanguage`. | ||
|
||
Extension authors might want to obtain the locale used by the user agent's host environment in order to get the locales in it's purest form. For example, the operating system might be running in `es-AR` and a browser's closest equivalent is `es-419`. Having access to `es-AR` allows extension authors to provide better translations for all users. | ||
|
||
### Known Consumers | ||
|
||
Language-related extensions and extensions wanting to match the locale of the operating system more closely independent of the locale of the browser. | ||
|
||
## Specification | ||
|
||
### Schema | ||
|
||
`i18n.getPreferredSystemLanguages()` would asynchronously return a language priority list (ordered list of [BCP47 language tag](https://www.rfc-editor.org/bcp/bcp47.html) like `i18n.getAcceptLanguages()` does right now. | ||
|
||
```json | ||
{ | ||
"name": "getPreferredSystemLanguages", | ||
"type": "function", | ||
"description": "Gets the preferred languages of the operating system. This is different from the languages set in the browser; to get those, use $(ref:i18n.getAcceptLanguages).", | ||
"parameters": [], | ||
"returns_async": { | ||
"name": "callback", | ||
"parameters": [{ | ||
"name": "languages", | ||
"type": "array", | ||
"items": {"$ref": "LanguageCode"}, | ||
"description": "Array of LanguageCode" | ||
}] | ||
} | ||
} | ||
|
||
``` | ||
|
||
`i18n.getSystemUILanguage()` would synchronously return a [BCP47 language tag](https://www.rfc-editor.org/bcp/bcp47.html) like `i18n.getUILanguage()` does right now. | ||
|
||
The returned language tag can be different from the first entry returned by getPreferredSystemLanguages as the operating system could not support all languages specified by the user for its user interface. | ||
|
||
It would follow the following signature for [i18n.json](https://chromium.googlesource.com/chromium/src/+/4299ce68496b32ba309e2f012e0db5b4b8cd478a/extensions/common/api/i18n.json): | ||
|
||
```json | ||
{ | ||
"name": "getSystemUILanguage", | ||
"type": "function", | ||
"nocompile": true, | ||
"description": "Gets the current UI locale of the Operating System. This is different from $(ref:i18n.getUILanguage) which returns the UI locale of the web browser. This locale could include additional information like preferred datetime format and number system if supported by the OS.", | ||
"parameters": [], | ||
"returns_async": { | ||
"name": "callback", | ||
"parameters": [{ | ||
"type": "string", | ||
"description": "A BCP47 language tag such as en-US or pt-BR." | ||
}] | ||
} | ||
} | ||
``` | ||
|
||
### New Permissions | ||
|
||
As `browser.i18n.getUILanguage()` does not require a permission, browser.i18n.getSystemUILanguage and browser.i18n.getPreferredSystemLanguages also should not. | ||
|
||
### Manifest File Changes | ||
|
||
No new manifest fields | ||
|
||
## Security and Privacy | ||
|
||
### Exposed Sensitive Data | ||
|
||
The locale(s) of the system will be purposely exposed. | ||
|
||
## Alternatives | ||
|
||
### Existing Workarounds | ||
|
||
Currently, if an extension wants to offer locales outside not localised for by the browser, it must do so by presenting a user-facing options page. However, currently there is no way to reasonably detect a language code outside of the browser's UI language with existing APIs. | ||
|
||
### Open Web API | ||
|
||
To combat fingerprinting, this should not be an Open Web API, like browser.i18n.getUILanguage is not. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the "additional information" part a standard? I know Apple platforms can include it, but that isn't something we have had in web extensions before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xeenon yes, this is specified by unicode. This was discussed during the shared session with the WECG/I18NWG meeting at TPAC. However, giving a further look at this I see how this should not be part of the getSystemUILanguage. Updated the PR to reflect this. Still, providing this information can be useful, but it should be implemented using some other method / proposal.