From 05d9908d2f5b02d91af0ac9082e8bb918f534175 Mon Sep 17 00:00:00 2001 From: Tony Rankin Date: Mon, 13 Jul 2015 22:27:39 -0700 Subject: [PATCH] Updating ActionBar title. Save button is now Undo. --- .../wordpress/android/util/StringUtils.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/WordPressUtils/src/main/java/org/wordpress/android/util/StringUtils.java b/WordPressUtils/src/main/java/org/wordpress/android/util/StringUtils.java index 68e3113c3d5d..6f73e6dd6ad2 100644 --- a/WordPressUtils/src/main/java/org/wordpress/android/util/StringUtils.java +++ b/WordPressUtils/src/main/java/org/wordpress/android/util/StringUtils.java @@ -11,6 +11,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Locale; public class StringUtils { public static String[] mergeStringArrays(String array1[], String array2[]) { @@ -228,6 +229,28 @@ public static String replaceUnicodeSurrogateBlocksWithHTMLEntities(final String return out.toString(); } + /** + * Used to convert a language code ([lc]_[rc] where lc is language code (en, fr, es, etc...) + * and rc is region code (zh-CN, zh-HK, zh-TW, etc...) to a displayable string with the languages + * name. + * + * The input string must be between 2 and 6 characters, inclusive. An empty string is returned + * if that is not the case. + * + * If the input string is recognized by {@link Locale} the result of this method is the given + * + * @return + * non-null + */ + public static String getLanguageString(String languagueCode, Locale displayLocale) { + if (languagueCode == null || languagueCode.length() < 2 || languagueCode.length() > 6) { + return ""; + } + + Locale languageLocale = new Locale(languagueCode.substring(0, 2)); + return languageLocale.getDisplayLanguage(displayLocale) + languagueCode.substring(2); + } + /** * This method ensures that the output String has only * valid XML unicode characters as specified by the