Skip to content

Commit cb2cd70

Browse files
eemeliearo@mozilla.com
authored andcommitted
Bug 1760013 - Add intl/locale/rust/locale_service_glue/. r=hsivonen,bolsson
This uses icu_locale for the added functions, but does not migrate existing unic_langid usage to it. The initial data matches the current localized values. I'll be filing a follow-up PR in https://github.com/mozilla-l10n/documentation to add a section to the "Adding a new locale to Beta and Release builds" page (https://mozilla-l10n.github.io/documentation/products/firefox_desktop/adding_release.html) to give some additional visibility for needing to review these behaviours when adding a new locale. Differential Revision: https://phabricator.services.mozilla.com/D266753
1 parent 12bf2b1 commit cb2cd70

File tree

14 files changed

+569
-0
lines changed

14 files changed

+569
-0
lines changed

Cargo.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

intl/locale/LocaleService.cpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "mozilla/intl/AppDateTimeFormat.h"
1515
#include "mozilla/intl/Locale.h"
1616
#include "mozilla/intl/OSPreferences.h"
17+
#include "mozilla/intl/locale_service_glue_generated.h"
1718
#include "nsContentUtils.h"
1819
#include "nsDirectoryService.h"
1920
#include "nsDirectoryServiceDefs.h"
@@ -31,6 +32,9 @@
3132

3233
#define INTL_SYSTEM_LOCALES_CHANGED "intl:system-locales-changed"
3334

35+
#define ACCEPT_LANGUAGES_PREF "intl.accept_languages"
36+
#define FONT_LANGUAGE_GROUP_PREF "font.language.group"
37+
3438
#define PSEUDO_LOCALE_PREF "intl.l10n.pseudo"
3539
#define REQUESTED_LOCALES_PREF "intl.locale.requested"
3640
#define WEB_EXPOSED_LOCALES_PREF "intl.locale.privacy.web_exposed"
@@ -694,3 +698,78 @@ LocaleService::GetPackagedLocales(nsTArray<nsCString>& aRetVal) {
694698
aRetVal = mPackagedLocales.Clone();
695699
return NS_OK;
696700
}
701+
702+
NS_IMETHODIMP
703+
LocaleService::GetEllipsis(nsAString& aRetVal) {
704+
if (mAppLocales.IsEmpty()) {
705+
NegotiateAppLocales(mAppLocales);
706+
}
707+
ffi::locale_service_ellipsis(&mAppLocales[0], &aRetVal);
708+
return NS_OK;
709+
}
710+
711+
bool LocaleService::AlwaysAppendAccesskeys() {
712+
if (mAppLocales.IsEmpty()) {
713+
NegotiateAppLocales(mAppLocales);
714+
}
715+
return ffi::locale_service_always_append_accesskeys(&mAppLocales[0]);
716+
}
717+
718+
bool LocaleService::InsertSeparatorBeforeAccesskeys() {
719+
if (mAppLocales.IsEmpty()) {
720+
NegotiateAppLocales(mAppLocales);
721+
}
722+
return ffi::locale_service_insert_separator_before_accesskeys(
723+
&mAppLocales[0]);
724+
}
725+
726+
NS_IMETHODIMP
727+
LocaleService::GetAlwaysAppendAccesskeys(bool* aRetVal) {
728+
(*aRetVal) = AlwaysAppendAccesskeys();
729+
return NS_OK;
730+
}
731+
732+
NS_IMETHODIMP
733+
LocaleService::GetInsertSeparatorBeforeAccesskeys(bool* aRetVal) {
734+
(*aRetVal) = InsertSeparatorBeforeAccesskeys();
735+
return NS_OK;
736+
}
737+
738+
NS_IMETHODIMP
739+
LocaleService::GetAcceptLanguages(nsACString& aRetVal) {
740+
// if there is a user (or locked) value, use it
741+
if (Preferences::HasUserValue(ACCEPT_LANGUAGES_PREF) ||
742+
Preferences::IsLocked(ACCEPT_LANGUAGES_PREF)) {
743+
nsresult rv = Preferences::GetCString(ACCEPT_LANGUAGES_PREF, aRetVal);
744+
if (NS_SUCCEEDED(rv)) {
745+
return NS_OK;
746+
}
747+
}
748+
749+
// if we need to fetch the default value, do that instead
750+
if (mAppLocales.IsEmpty()) {
751+
NegotiateAppLocales(mAppLocales);
752+
}
753+
ffi::locale_service_default_accept_languages(&mAppLocales[0], &aRetVal);
754+
return NS_OK;
755+
}
756+
757+
NS_IMETHODIMP
758+
LocaleService::GetFontLanguageGroup(nsACString& aRetVal) {
759+
// if there is a user (or locked) value, use it
760+
if (Preferences::HasUserValue(FONT_LANGUAGE_GROUP_PREF) ||
761+
Preferences::IsLocked(FONT_LANGUAGE_GROUP_PREF)) {
762+
nsresult rv = Preferences::GetCString(FONT_LANGUAGE_GROUP_PREF, aRetVal);
763+
if (NS_SUCCEEDED(rv)) {
764+
return NS_OK;
765+
}
766+
}
767+
768+
// if we need to fetch the default value, do that instead
769+
if (mAppLocales.IsEmpty()) {
770+
NegotiateAppLocales(mAppLocales);
771+
}
772+
ffi::locale_service_default_font_language_group(&mAppLocales[0], &aRetVal);
773+
774+
return NS_OK;
775+
}

intl/locale/LocaleService.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ class LocaleService final : public mozILocaleService,
168168
*/
169169
bool IsAppLocaleRTL();
170170

171+
/**
172+
* If true, accesskeys should always be appended for the current app locale.
173+
*/
174+
bool AlwaysAppendAccesskeys();
175+
176+
/**
177+
* If true, accesskeys should always be separated from the label.
178+
*/
179+
bool InsertSeparatorBeforeAccesskeys();
180+
171181
static bool LanguagesMatch(const nsACString& aRequested,
172182
const nsACString& aAvailable);
173183

intl/locale/moz.build

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ if CONFIG["COMPILE_ENVIRONMENT"]:
7777
"fluent_langneg_ffi_generated.h",
7878
inputs=["/intl/locale/rust/fluent-langneg-ffi"],
7979
)
80+
CbindgenHeader(
81+
"locale_service_glue_generated.h",
82+
inputs=["/intl/locale/rust/locale_service_glue"],
83+
)
8084
CbindgenHeader(
8185
"oxilangtag_ffi_generated.h", inputs=["/intl/locale/rust/oxilangtag-ffi"]
8286
)
@@ -86,6 +90,7 @@ if CONFIG["COMPILE_ENVIRONMENT"]:
8690

8791
EXPORTS.mozilla.intl += [
8892
"!fluent_langneg_ffi_generated.h",
93+
"!locale_service_glue_generated.h",
8994
"!oxilangtag_ffi_generated.h",
9095
"!unic_langid_ffi_generated.h",
9196
]

intl/locale/mozILocaleService.idl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,33 @@ interface mozILocaleService : nsISupports
174174
* Example: ["en-US", "de", "pl", "sr-Cyrl", "zh-Hans-HK"]
175175
*/
176176
readonly attribute Array<ACString> packagedLocales;
177+
178+
/**
179+
* The unicode ellipsis char "…", or "...", depending on the current app locale.
180+
*/
181+
readonly attribute AString ellipsis;
182+
183+
/**
184+
* If true, accesskeys should always be appended for the current app locale.
185+
*/
186+
readonly attribute boolean alwaysAppendAccesskeys;
187+
188+
/**
189+
* If true, accesskeys should always be separated from the label.
190+
*/
191+
readonly attribute boolean insertSeparatorBeforeAccesskeys;
192+
193+
/**
194+
* A comma-separated list of valid BCP 47 language tags.
195+
*/
196+
readonly attribute ACString acceptLanguages;
197+
198+
/**
199+
* The initial setting of the language drop-down menu
200+
* in the Fonts and Colors > Advanced preference panel.
201+
*
202+
* Takes one of the values of the menuitems in the "selectLangs" menulist in
203+
* https://searchfox.org/firefox-main/source/browser/components/preferences/dialogs/fonts.xhtml
204+
*/
205+
readonly attribute ACString fontLanguageGroup;
177206
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
edition = "2021"
3+
name = "locale_service_glue"
4+
version = "0.1.0"
5+
license = "MPL-2.0"
6+
authors = ["Eemeli Aro <eemeli@mozilla.com>"]
7+
8+
[dependencies]
9+
nsstring = { path = "../../../../xpcom/rust/nsstring" }
10+
11+
[dependencies.icu_locale]
12+
version = "~2.0.0"
13+
default-features = false
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
header = """/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */"""
4+
autogen_warning = """/* DO NOT MODIFY THIS MANUALLY! This file was generated using cbindgen. See RunCbindgen.py */
5+
#ifndef mozilla_intl_locale_MozLocaleBindings_h
6+
#error "Don't include this file directly, instead include MozLocaleBindings.h"
7+
#endif
8+
"""
9+
include_version = true
10+
braces = "SameLine"
11+
line_length = 100
12+
tab_width = 2
13+
language = "C++"
14+
namespaces = ["mozilla", "intl", "ffi"]
15+
16+
[parse]
17+
parse_deps = true
18+
include = ["icu_locale"]

0 commit comments

Comments
 (0)