summaryrefslogtreecommitdiffstats
path: root/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/LocaleUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/LocaleUtils.java')
-rw-r--r--mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/LocaleUtils.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/LocaleUtils.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/LocaleUtils.java
new file mode 100644
index 0000000000..8e4addc7b0
--- /dev/null
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/LocaleUtils.java
@@ -0,0 +1,32 @@
+/* -*- Mode: Java; c-basic-offset: 2; tab-width: 20; indent-tabs-mode: nil; -*- */
+/* vim: set ts=2 et sw=2: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.gecko.util;
+
+import android.text.TextUtils;
+import java.util.Locale;
+
+public class LocaleUtils {
+ // Locale.getLanguage() may return legacy language code until Java 17
+ // https://developer.android.com/reference/java/util/Locale#legacy_language_codes
+ public static String getLanguageTagForAcceptLanguage(final Locale locale) {
+ String language = locale.getLanguage();
+ if (language.equals("in")) {
+ language = "id";
+ } else if (language.equals("iw")) {
+ language = "he";
+ } else if (language.equals("ji")) {
+ language = "yi";
+ }
+ final StringBuilder out = new StringBuilder(language);
+ final String country = locale.getCountry();
+ if (!TextUtils.isEmpty(country)) {
+ out.append('-').append(country);
+ }
+ // e.g. "en", "en-US"
+ return out.toString();
+ }
+}