Skip to content

Commit

Permalink
Merge pull request Yink#46 from alexsh/master
Browse files Browse the repository at this point in the history
Add Locale support include region code and variants.
Thank you for your work!
  • Loading branch information
Yink authored Oct 19, 2017
2 parents edde9f8 + 4d4e89b commit 57935ef
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions app/src/main/java/com/example/yink/amadeus/LangContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,20 @@ public static ContextWrapper wrap(Context context) {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());

String lang = settings.getString("lang", "en");

Locale locale = new Locale(lang);
String[] langArr = lang.split("-");
Locale locale;
switch(langArr.length){
case 3:
locale = new Locale(langArr[0],langArr[1], langArr[2]);
break;
case 2:
locale = new Locale(langArr[0],langArr[1]);
break;
default:
locale = new Locale(langArr[0]);
break;
}
Locale.setDefault(locale);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
setSystemLocale(config, locale);
} else {
Expand Down

0 comments on commit 57935ef

Please sign in to comment.