The strongest multi-language internationalization in Android history, not only will it follow the system for the first time, but will also save the user's language settings

Source: Internet
Author: User

1. I wait for the cock to like the simple rough, first a picture


man, I'm from the mainland, of course. The default language is Simplified Chinese, but I just switched to traditional.


2. Look at the configuration file, follow this format, look at the picture bar, simple rough, don't ask why, you just follow this write, if you want to know why this write, as well as the detailed steps, please Baidu: Android multi-language

Arabic ar, German de, English en, Spanish es, French fr, Japanese ja, Korean ko, Portuguese pt, I am a big celestial and Hong Kong and Macao have skipped, do not explain,




3. Note that all language profiles String.xml text format is the same, but the language is different, the name is the same, the corresponding value is different



4. How to reference these bird things, is an Android developer will ... Let's just cut a picture,




5. Go to the best part of history Enter the app for the first time

First, the introduction of public methods, the code

public static final String system_locale_languague_string = "system_locale_languague_string";p ublic static final string system_locale_country_string = "system_locale_country_string";p ublic static final STRING ename[]={"zh", "en", "fr", "de "," ja "," Ko "," es "," PT "," ar "};
<pre name= "code" class= "java" >public static Locale Getsystemlacale (context context) {Sharedpreferences Sharedpreferences = getcurrentsharedpreferences (context); String str = sharedpreferences.getstring (system_locale_languague_string, "No_languague"); String strc = sharedpreferences.getstring (system_locale_country_string, ""); if ("No_languague". Equals (str)) {LOCALE L =locale.getdefault (); String def= "en"; for (int i = 0; i < ename.length; i++) {if (Ename[i].equals (L.getlanguage ())) {Def=ename[i];break;}} Locale nlocale=null;if ("zh". Equals (Def)) {if ("CN". Equals (L.getcountry ())) {Nlocale=locale.simplified_chinese;} else {Nlocale=locale.traditional_chinese;}} else {nlocale=new Locale (def);} Setsystemlacate (context, Nlocale); return nlocale;} return new Locale (STR,STRC);} public static void Setsystemlacale (Context context,locale Locale) {sharedpreferences sharedpreferences = Getcurrentsharedpreferences (context); Sharedpreferences.editor Editor = Sharedpreferences.edit (); Editor.putstring (systeM_locale_languague_string, Locale.getlanguage ()); Editor.putstring (system_locale_country_string, Locale.getcountry ()); Editor.commit ();}


I don't need to explain, get the system default Lacale, why do you write this? I will not explain, if you have a better way, the great god you are in the following comments!


Add a way to change the language

private void Reloadlanguageaction () {locale locale = staticfunction.getsystemlacate (mainactivity.this); Locale.setdefault (locale);          Configuration config = new configuration ();          Config.locale = locale;         Getbasecontext (). Getresources (). updateconfiguration (config, null);       Getbasecontext (). Getresources (). Flushlayoutcache ();       }


Where did you call it? This problem with learning excavator which strong is the same type of problem.






6. Language switch, which is the first picture you see, how does this function


Why do you want to jump directly to the homepage, not skip? iOS can not jump, iOS can send a notification, the global changed all of a sudden, Android I tried to use the Observer mode at the earliest, the egg broke the ground .... If you have done this with observer mode , please comment.

August 12, 2015 00:36:48, wipe, bitter force of the program Ape will work tomorrow








Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The strongest multi-language internationalization in Android history, not only will it follow the system for the first time, but will also save the user's language settings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.