Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 21fc8ba3 authored by Narayan Kamath's avatar Narayan Kamath
Browse files

Support deprecated language codes.

Locale.toLanguageTag will transform the obsolete (and
deprecated) language codes "in", "ji" and "iw" to
"id", "yi" and "he" respectively.

All versions of android prior to "L" used the deprecated
language tags, so we will need to support them for backwards
compatibility.

bug: 13230947

Change-Id: Ib63567786bcbe780ceb0487d8f583b75a5452aea
parent 97ae5385
Loading
Loading
Loading
Loading
+36 −1
Original line number Original line Diff line number Diff line
@@ -1625,7 +1625,7 @@ public class Resources {


            String locale = null;
            String locale = null;
            if (mConfiguration.locale != null) {
            if (mConfiguration.locale != null) {
                locale = localeToLanguageTag(mConfiguration.locale);
                locale = adjustLanguageTag(localeToLanguageTag(mConfiguration.locale));
            }
            }
            int width, height;
            int width, height;
            if (mMetrics.widthPixels >= mMetrics.heightPixels) {
            if (mMetrics.widthPixels >= mMetrics.heightPixels) {
@@ -1712,6 +1712,41 @@ public class Resources {
        return locale.toLanguageTag();
        return locale.toLanguageTag();
    }
    }


    /**
     * {@code Locale.toLanguageTag} will transform the obsolete (and deprecated)
     * language codes "in", "ji" and "iw" to "id", "yi" and "he" respectively.
     *
     * All released versions of android prior to "L" used the deprecated language
     * tags, so we will need to support them for backwards compatibility.
     *
     * Note that this conversion needs to take place *after* the call to
     * {@code toLanguageTag} because that will convert all the deprecated codes to
     * the new ones, even if they're set manually.
     */
    private static String adjustLanguageTag(String languageTag) {
        final int separator = languageTag.indexOf('-');
        final String language;
        final String remainder;

        if (separator == -1) {
            language = languageTag;
            remainder = "";
        } else {
            language = languageTag.substring(0, separator);
            remainder = languageTag.substring(separator);
        }

        if ("id".equals(language)) {
            return "in" + remainder;
        } else if ("yi".equals(language)) {
            return "ji" + remainder;
        } else if ("he".equals(language)) {
            return "iw" + remainder;
        } else {
            return languageTag;
        }
    }

    /**
    /**
     * Update the system resources configuration if they have previously
     * Update the system resources configuration if they have previously
     * been initialized.
     * been initialized.