-
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
Introducing browser.i18n.getOSLanguage
#252
Comments
This sounds fine to me for Safari. |
Why not use |
It isn't available in service workers, IIRC. |
It seems like it should be available given That said, I believe As I understand it we have:
So (3) is not really a replacement for (1), or (2) for that matter. I'm a little bit concerned that adding (1) might lead to a worse user experience when add-on authors don't appreciate the difference between (1) and (2). For example, a lot of users are on a non-English OS but deliberately install an English browser, or vice-versa. I'm afraid if extension authors reach for |
@xeenon Because navigator.language(s) represents the user's preferred language(s), which is the same concept as OS language preference, I don't think that By default, browsers uses the language settings of the operating system. And users can change it in browser settings independently. |
I think It's quite common to have the accept languages ( For example, I need to set |
This is a common i18n issue. Websites that supports multiple languages usually have a menu for users to change website's language. The priority order of deciding the language is as follows:
Yes, this is why there is a Browser extensions can also supply a language-select menu for users in the extension's settings if it supports multiple languages. Note: currently |
Yes, I think we're on the same page here -- I agree that (And I also agree that |
@hanguokai As I was trying to state in the first post, the OS language is different from the browser UI language. For example, windows supports 87 languages while Google Chrome only supports 54 languages. And there are is always 1:1 maping. For example, Google Chrome doesn't support Galician. Instead it probably uses Portuguese. However, as extension you want to know the original language before it gets mapped to the language a browser supports. One additional use-case on top of the already named ones is the ability to use exactly the same language between an extension and their native companion app. @hanguokai @birtles The ability to get a specified message in a specified language using |
Gotcha, that makes sense. For what browsers does such a mapping exist? In the case of something like Firefox, the browser localization is simply whatever language the user chose to download. In that situation, it's hard to determine which language the user actually prefers. My concern is that extension developers, when presented with |
This is not an extension-specific issue. All websites also face this problem. I think this should be discussed in a more general group in W3C.
Chrome UI maybe only support 54 languages. But UI languages does not equal
In order to choose the best language, extensions can check both |
@birtles When it comes to Firefox, the user can actually change the language of the browser UI in the Firefox settings. So this even increases the use-case for As for the confusion between Thus it seems best to stick with @hanguokai Making the OS language available to ordinary websites has different considerations and will take a lot more time and my personal estimate is it will not make it. Implementing it for browser extensions first seems like the right path to me. Just like we did with |
Counting Developers may not be able to make choices for users, so I know some developers offer language options to users (not only extension developers face this problem, desktop and mobile app developers also support this way). This allows the user to choose a language they prefer, which may be neither How to integrate |
In addition, there is another way to use i18n messages in manifest.json and CSS files, |
They simply use the one which works best in their situation.
It is not about developers making choices for users. If users prefer choice, developers can use the setCurrentLanguage proposal as mentioned here: #258. The
See your own proposal, #258
Why should they be? If the complete extension language should be changed, this should be done with #258. In there, we can discuss whether or not these |
The API proposal suggests one return value. Should we suggest an array of values instead, in case a user has configured multiple languages? I don't have a strong preference either way. |
@Rob--W Good point. This would also solve any potential confusion raised in by @birtles in #252 (comment) with i18n.getUILanguage. @xeenon @rdcronin Do you have any opposition in changing this to |
Some operating systems do allow setting up multiple languages, the first of which is used as the OS UI language, like macOS and Android. It is similar to What results are returned depends on what the API is actually used for.
|
@carlosjeurissen I'm not sure. Now that I look at it, I think In out implementation that will effectively be the same result as |
@xeenon From what I understand it seems Safari derives it's Say
|
@hanguokai Thanks for your thoughts shared in #569 (comment) To keep the discussion in one thread, replying in this issue. You are right about the difference between the OS preferred languages and the language the OS actually picks. It is not always the first language. In macOS, when selecting "Georgian" as primary language, it will skip it in search for a language the OS actually supports. This means we can not simply assume the first language returned by Considering this having two different methods, Using @Rob--W in reply to your comment #569 (comment) |
The new parameter is optional and has a default value, so it is backwards compatible. Here the OS and the browser use the similar and overlapped concept (one UI language and a list of accept languages), IMO it makes sense that they share the same methods. Otherwise using four new methods as I described in #569 (comment) , whose names are symmetrical and clear, so developers will not confuse their functionality. |
@hanguokai Good point! Seems for @xeenon do you have an idea on how doable it is to find out what the language of the UI of the OS actually is? (versus the first system language, as this might not be true when your first system language is Georgian for example). |
@carlosjeurissen We have a method to get the single device (OS) locale on Apple platforms. So I would prefer this method stay as returning a single string, not an array. Given an accept languages array of |
That could also be turned into a single-value array. It is however not possible to put multiple values in one string. I don't feel very strongly about either approach, but from the API design POV, an array would make sense if there are systems with multiple values. |
Indeed! I'm fine with a single value array for flexibility. |
@xeenon @Rob--W Then I conclude ideally extensions would be offered two additional APIs. One, [ "bn-IN", "en-IN"] And another which gives the language the os actually uses as a string. As far as I know this would only be one value. Tho I am fine with this returning an array with a single value just in case.
This way an extension can both match their native app as well as the language the OS actually uses. This is also helpful for a bunch of other usecases in which the user needs to be given certain instructions to be followed in the OS. |
@carlosjeurissen Why is one method |
@xeenon we can use OS or System for both. I do not feel very strongly about the naming as long as the functionality is there. To me "OS" feels more UI like while System feels more under the hood like. @Rob--W how do you feel about naming? |
I'm fine either way on |
Returning an array or a string ? As I said at #569 (comment) , we can support both, because they are different concepts. Personally, we can use the existing methods with a new optional parameter.
|
https://bugs.webkit.org/show_bug.cgi?id=280586 Reviewed by NOBODY (OOPS!). WECG issue: w3c/webextensions#252 WECG proposal: w3c/webextensions#569 Also changed the i18n APIs to return `"und"` instead of `undefined` when there is no language code. * Source/WebKit/Platform/spi/Cocoa/FoundationSPI.h: * Source/WebKit/Shared/Extensions/WebExtensionUtilities.mm: (WebKit::toWebAPI): Return "und" where then is no language code. * Source/WebKit/WebProcess/Extensions/API/Cocoa/WebExtensionAPILocalizationCocoa.mm: (WebKit::WebExtensionAPILocalization::getPreferredSystemLanguages): (WebKit::WebExtensionAPILocalization::getSystemUILanguage): * Source/WebKit/WebProcess/Extensions/API/WebExtensionAPILocalization.h: * Source/WebKit/WebProcess/Extensions/Interfaces/WebExtensionAPILocalization.idl: * Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPILocalization.mm: (TestWebKitAPI::localeStringInWebExtensionFormat): Return "und". (TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18n)): (TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18nWithFallback)): (TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18nWithoutMessages)): (TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18nWithoutDefaultLocale)):
https://bugs.webkit.org/show_bug.cgi?id=280586 Reviewed by Brian Weinstein. WECG issue: w3c/webextensions#252 WECG proposal: w3c/webextensions#569 Also changed the i18n APIs to return `"und"` instead of `undefined` when there is no language code. * Source/WebKit/Platform/spi/Cocoa/FoundationSPI.h: * Source/WebKit/Shared/Extensions/WebExtensionUtilities.mm: (WebKit::toWebAPI): Return "und" where then is no language code. * Source/WebKit/WebProcess/Extensions/API/Cocoa/WebExtensionAPILocalizationCocoa.mm: (WebKit::WebExtensionAPILocalization::getPreferredSystemLanguages): (WebKit::WebExtensionAPILocalization::getSystemUILanguage): * Source/WebKit/WebProcess/Extensions/API/WebExtensionAPILocalization.h: * Source/WebKit/WebProcess/Extensions/Interfaces/WebExtensionAPILocalization.idl: * Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPILocalization.mm: (TestWebKitAPI::localeStringInWebExtensionFormat): Return "und". (TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18n)): (TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18nWithFallback)): (TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18nWithoutMessages)): (TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18nWithoutDefaultLocale)): Canonical link: https://commits.webkit.org/284637@main
Motivation
As browsers often don't directly use the OS language but some reflection of it based on what languages are supported by the browser UI. Having the original OS language is useful for language-related extensions and for extensions who want to provide translations more true to the OS language (like be able to adapt to a specific sub-language, like Belgium-Dutch (nl-BE). While
i18n.getUILanguage
would return 'nl'.Syntax
i18n.getOSLanguage()
would synchronously return anIETF tag
just likei18n.getUILanguage()
does right now.It would follow the following signature for i18n.json:
See proposal: #569
The text was updated successfully, but these errors were encountered: