Skip to content

Commit 05d9908

Browse files
committed
Updating ActionBar title. Save button is now Undo.
1 parent fcf0b6f commit 05d9908

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

WordPressUtils/src/main/java/org/wordpress/android/util/StringUtils.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.ArrayList;
1212
import java.util.Arrays;
1313
import java.util.List;
14+
import java.util.Locale;
1415

1516
public class StringUtils {
1617
public static String[] mergeStringArrays(String array1[], String array2[]) {
@@ -228,6 +229,28 @@ public static String replaceUnicodeSurrogateBlocksWithHTMLEntities(final String
228229
return out.toString();
229230
}
230231

232+
/**
233+
* Used to convert a language code ([lc]_[rc] where lc is language code (en, fr, es, etc...)
234+
* and rc is region code (zh-CN, zh-HK, zh-TW, etc...) to a displayable string with the languages
235+
* name.
236+
*
237+
* The input string must be between 2 and 6 characters, inclusive. An empty string is returned
238+
* if that is not the case.
239+
*
240+
* If the input string is recognized by {@link Locale} the result of this method is the given
241+
*
242+
* @return
243+
* non-null
244+
*/
245+
public static String getLanguageString(String languagueCode, Locale displayLocale) {
246+
if (languagueCode == null || languagueCode.length() < 2 || languagueCode.length() > 6) {
247+
return "";
248+
}
249+
250+
Locale languageLocale = new Locale(languagueCode.substring(0, 2));
251+
return languageLocale.getDisplayLanguage(displayLocale) + languagueCode.substring(2);
252+
}
253+
231254
/**
232255
* This method ensures that the output String has only
233256
* valid XML unicode characters as specified by the

0 commit comments

Comments
 (0)