package com.esafirm.imagepicker.helper;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import java.util.Locale;

public class LocaleManager {

    private static String language;

    public static void setLanguage(String newLanguage) {
        language = newLanguage;
    }

    private static String getLanguage() {
        return language != null && !language.isEmpty()
                ? language
                : Locale.getDefault().getLanguage();
    }

    public static Context updateResources(Context context) {

        Locale locale = new Locale(getLanguage());
        locale = zhCheck(locale);
        Locale.setDefault(locale);

        Resources res = context.getResources();
        Configuration config = new Configuration(res.getConfiguration());
        if (Build.VERSION.SDK_INT >= 17) {
            config.setLocale(locale);
            context = context.createConfigurationContext(config);
        } else {
            config.locale = locale;
            res.updateConfiguration(config, res.getDisplayMetrics());
        }
        return context;
    }

    private static Locale zhCheck(Locale newLocaleLanguage) {
        final String ZH = "zh";
        final String TW = "TW";
        final String CN = "CN";

        Locale mLocale;
        String mNewLocaleLanguage = String.valueOf(newLocaleLanguage);

        if (mNewLocaleLanguage.length() == 5) {
            mLocale = new Locale(
                    mNewLocaleLanguage.substring(0, 2),
                    mNewLocaleLanguage.substring(3, 5).toUpperCase()
            );
            return mLocale;
        } else if (mNewLocaleLanguage.equals(ZH)) {
            if (Locale.getDefault().getCountry().equals(TW)) {
                mLocale = new Locale(ZH, TW);
            } else {
                mLocale = new Locale(ZH, CN);
            }
            return mLocale;
        } else {
            return newLocaleLanguage;
        }
    }
}

@@ -674,23 +674,31 @@
 ocale = 
-zhCheck
+normalizeLocale
 (locale)
@@ -1198,23 +1198,31 @@
 ale 
-zhCheck
+normalizeLocale
 (Locale 
 newL
@@ -1217,20 +1217,17 @@
 (Locale 
-newL
+l
 ocaleLan
@@ -1347,18 +1347,17 @@
  Locale 
-mL
+l
 ocale;%0A 
@@ -1370,18 +1370,17 @@
  String 
-mN
+n
 ewLocale
@@ -1405,20 +1405,17 @@
 valueOf(
-newL
+l
 ocaleLan
@@ -1431,26 +1431,25 @@
         if (
-mN
+n
 ewLocaleLang
@@ -1474,34 +1474,33 @@
 ) %7B%0A            
-mL
+l
 ocale = new Loca
@@ -1515,34 +1515,33 @@
                 
-mN
+n
 ewLocaleLanguage
@@ -1578,18 +1578,17 @@
         
-mN
+n
 ewLocale
@@ -1652,34 +1652,33 @@
          return 
-mL
+l
 ocale;%0A        %7D
@@ -1691,10 +1691,9 @@
 if (
-mN
+n
 ewLo
@@ -1790,34 +1790,33 @@
                 
-mL
+l
 ocale = new Loca
@@ -1864,18 +1864,17 @@
         
-mL
+l
 ocale = 
@@ -1930,10 +1930,9 @@
 urn 
-mL
+l
 ocal
@@ -1970,20 +1970,17 @@
  return 
-newL
+l
 ocaleLan

rename the function for the PR required.