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

Proposal: i18n-system-languages #569

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
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 Mar 18, 2024
7ed4c53
Update proposals/i18n-getOSLanguage.md
carlosjeurissen Mar 28, 2024
916f91d
Update proposals/i18n-getOSLanguage.md
carlosjeurissen Mar 28, 2024
30fbed6
Update workaround description
carlosjeurissen Mar 28, 2024
1339056
Add back Sponsoring Browser with TBD
carlosjeurissen Mar 28, 2024
b7781f4
Add Bugzilla bug to related issues
carlosjeurissen Mar 28, 2024
ae8e4e2
Add Author GitHub link
carlosjeurissen Mar 28, 2024
0c352e8
Add bcp47 link
carlosjeurissen Mar 28, 2024
15fde77
Rephrase objective
carlosjeurissen Mar 28, 2024
1bf297c
Rename IETF tags to BCP47 language tags
carlosjeurissen Mar 30, 2024
b9ab150
Remove > from title
carlosjeurissen Mar 31, 2024
da34a81
Replace chromium source reference with a permalink
carlosjeurissen Mar 31, 2024
6107700
Update proposals/i18n-getOSLanguage.md
carlosjeurissen Apr 19, 2024
38e9f39
Update proposal to include both getPreferredSystemLanguages and getSy…
carlosjeurissen May 23, 2024
4eb3df1
Rename proposal file to better reflect the proposal
carlosjeurissen May 23, 2024
280efb5
Fix proposal title
carlosjeurissen Jun 6, 2024
90dec9b
Update proposals/i18n-system-languages.md
carlosjeurissen Jun 14, 2024
1d995e9
Update proposals/i18n-system-languages.md
carlosjeurissen Jun 14, 2024
89f08b3
Clarify the type of list returned by getPreferredSystemLanguages
carlosjeurissen Jun 14, 2024
76acf81
Rewrite sentences to use locale instead of language when it makes sense
carlosjeurissen Jun 14, 2024
395c02e
Add purest form use-case
carlosjeurissen Jun 14, 2024
07b64c9
Update proposals/i18n-system-languages.md
carlosjeurissen Sep 23, 2024
e8ae3a9
Clarify additional subtags on getSystemUILanguage
carlosjeurissen Sep 24, 2024
7e3c88f
Update getSystemUILanguage to be async
carlosjeurissen Sep 24, 2024
64b942d
Clarify getPreferredSystemLanguages callback parameter
carlosjeurissen Sep 24, 2024
42f71ae
Clarify getPreferredSystemLanguages would not insert less specific lo…
carlosjeurissen Oct 2, 2024
7ac0a42
Remove additional subtags note on getSystemUILanguage
carlosjeurissen Oct 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions proposals/i18n-system-languages.md
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.",
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

"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.