What I used when I was writing multi-lingual Support.
絮叨絮叨:好久不来写了,居然支持markdown 了。 我也是在项目里的wiki 里干刚接触了一些, 来这里也试试。然后悲催的发现,mac 电脑在markdown下直接上传图片有bug @2015-08-19 20:28:13。
一会试一下链接版的吧。我们的37度手环一不小心要卖到国外去了,自然要支持多国家多语言啦。 等卖到阿拉伯世界的时候,我会再补充RTL(Right To Left)相关的内容。
This article deals only with the Android client Implementation. The section of the server backend is not Described. This paper mainly introduces the use of text and pictures in multi-language, and how to change the Drop-down menu Spinner. Often used shell commands are also described in the process, with awk commands that work efficiently and live efficiently.
Android development itself has good support for multiple languages, especially in the new version of Android Studio, which also adds a direct addition to the multilingual Editor.
Dealing with multiple languages is an absolute artifact.
Support for official website [supporting Multi language][2]
Character translation
of course, Use the multi-language editor in artifact Studio
Figure 1 Editor Open location
Figure 2 Editor interface
Figure 3 Folder structure
Picture processing with text
The same principle as the Text. Create a picture folder for the respective language
For example, the corresponding drawable-xhdpi different language/region folder is
drawable-ko-xhdpi
drawable-zh-xhdpi
Figure 4 Picture Multi-Language folder
True multi-country Function--support multi-country SMS Verification code to prepare more than 1 countries area code
Country Code [country code][1]
Fetch is a big table, more than 200 lines. Organize your saved markdown files for easy viewing and editing later
The general copy is a tab \ t Cut. I replaced it with vim and changed the number of spaces and \ t into |. The operation commands for the detailed vim are as Follows:
#在vim 中多次运行,把全部的\t 换成 多个空格:%s/\t/ |/g#然后把多个空格 换成|:%s/ */|/g
This forms such as the following format
#Country Number tableCountries and Regions|国家或地区|时差|电话代码|国际域名缩写------------------------|-----------|-----------|-------|-----Angola|安哥拉|-7|244|AOAfghanistan|阿富汗|0|93|AFAlbania|阿尔巴尼亚|-7|355|AL
countries and regions |
Country or region | time
difference |
Phone Code |
International Domain abbreviation |
Angola |
Angola |
-7 |
244 |
AO |
Afghanistan |
Afghanistan |
0 |
93 |
Af |
Albania |
Albania |
-7 |
355 |
AL |
Prepare 2 country code for the String-array
Stored as String-array in the respective language/region resource Folders. This is handled using AWK. Obtain the country name and the corresponding country code, respectively.
Detailed shell commands such as the following
CountryNumber.md | awk -F‘|‘ ‘"<item>"$2"|"$4"</item>"}‘ > cn.txt$ cat CountryNumber.md | awk -F‘|‘ ‘"<item>"$1"|"$4"</item>"}‘ > en.txt
<string-array name="country_code"> <item>安哥拉|244</item> <item>阿富汗|93</item> <item>阿尔巴尼亚|355</item></string-array><string-array name="country_code"> <item>Angola|244</item> <item>Afghanistan|93</item> <item>Albania|355</item></string-array>
Java code parsing, and sorting
Since it is used | Cut. The next step is to parse the code and sort it before the SHOW.
publicStatic arraylist<country> getcountrycode (Context ctx) {arraylist<country> retlist =NewArraylist<> ();String[]Array= Ctx.getresources (). Getstringarray (R.Array. country_code); for(StringItem:Array) {String[] data = Item.Split("\\|"); Country Country =NewCountry (); Country.Name = data[0]; Country.code = data[1]; Retlist.add (country); } collections.sort (retlist); Return retlist; }
Sorting requires class country to implement the sort interface comparable
Use Collator when the system language is in Chinese. Be able to sort by the pinyin of the Chinese characters on their own Initiative.
public class country implements comparable<country> { publicString name; publicString code; @Override publicString toString () {stringbuffer buffer =NewStringBuffer ();returnBuffer.append (name). Append (", "). Append (code). toString (); } @Override public intCompareTo (country Another) {if(another = =NULL) {return-1; } Collator cmp = collator.getinstance (locale.getdefault ());returnCmp.compare ( this. name, another.name); }}
Define your own spinner Drop-down Select country Code
Let's take a look at the implementation effect, two styles of spinner
Figure Spinner
Nothing high-tech, is to let spinner according to their own meaning to SHOW. Two kinds are used in different places. Flexible use is not what the siege lion to do.
Spinner's interface changes are mainly two parts:
One is not expanded, in the GetView () changes, can change the Triangle picture, control the display position, etc.;
Another is the expanded state--changes in Getdropdownview () to control what is displayed after the Expansion.
The realization of Countryspinneradapter
public classCountryspinneradapter extends Arrayadapter<country> {PrivateContext context;PrivateArraylist<country> mcountrylist;PrivateSpinner mspinner;PrivateBoolean misfamilyspinner; public Countryspinneradapter(context context, Spinner Spinner, arraylist<country> countrylist, boolean isfamilyspinner) {super (context, r.layout.country_spinner_item, countrylist); this. Context = context; Mcountrylist = countrylist; Mspinner = spinner; this. Misfamilyspinner = isfamilyspinner; } public Countryspinneradapter(context context, Spinner Spinner, arraylist<country> countrylist) { this(context, spinner, countrylist,false); } @Override publicViewGetdropdownview(intposition, View convertview, viewgroup Parent) {if(convertview = =NULL) {convertview = view.inflate (getcontext (), misfamilyspinner? r.layout.country_spinner_layout_family:r.layout.country_spinner_layout,NULL); } Country Country = Mcountrylist.Get(position); TextView name = (TextView) Convertview.findviewbyid (r.id.country_name); TextView code = (TextView) Convertview.findviewbyid (r.id.country_code); Name.settext (country.name); Code.settext ("+"+ country.code);if(mspinner.getselecteditemposition () = = Position) {convertview.setselected (true); }Else{convertview.setselected (false); }returnconvertview; } @Override publicViewGetView(intposition, View convertview, viewgroup Parent) {if(convertview = =NULL) {convertview = view.inflate (getcontext (), misfamilyspinner? r.layout.country_spinner_item_family:r.layout.country_spinner_item,NULL); } Country Country = (country) Mspinner.getselecteditem ();if(misfamilyspinner) {TextView code = (TextView) Convertview.findviewbyid (r.id.country_code); Code.settext ("+"+ country.code); }Else{TextView name = (TextView) Convertview.findviewbyid (r.id.country_name); TextView code = (TextView) Convertview.findviewbyid (r.id.country_code); Name.settext (country.name); Code.settext ("+"+ country.code); }if(mspinner.getselecteditemposition () = = Position) {convertview.setselected (true); }Else{convertview.setselected (false); }returnconvertview; }}
Use the layout separately to Control:
Layout/country_spinner_item.xml
A horizontal layout includes
Two TextView display name and code respectively
A ImageView, ImageView used to show the Drop-down triangle
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" Android:layout_width="match_parent"android:layout_height="wrap_content" Android:gravity="center_vertical"android:background="@DRAWABLE/FAMILY_SPINNER_BG "android:orientation="Horizontal "> <TextView Android:id="@+id/country_name" Android:layout_marginleft="8dp" Android:layout_width="0dp" Android:layout_height="wrap_content" Android:layout_weight="1" Android:singleline="true" Android:text="@string/family_dialog_phone_number" Android:textcolor="@color/family_dialog_message" android:textsize="18sp"/> <TextViewandroid:id="@+id/country_code"android:layout_marginright= "8dp" android:layout_width="wrap_content"android:layout_height="wrap_content" Android:textcolor= "@color/family_dialog_message"android:textsize=" 18sp " /> <ImageViewandroid:layout_width="wrap_content"android:layout_height= "wrap_content" android:src="@drawable/country_spinner_arrow" /> </linearlayout>
Layout/country_spinner_layout.xml
A horizontal layout includes
Two TextView display name and code respectively
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"Android:layout_width="match_parent"android:layout_height="25dp"Android:background="@drawable/family_spinner_back"android:gravity="center_vertical"> <textview android:id="@+id/country_name"Android:layout_width="0dp"android:layout_height="wrap_content"android:layout_marginleft="8dp"android:layout_weight="1"Android:duplicateparentstate="false"Android:ellipsize="end"Android:singleline="true"android:text="@string/family_dialog_phone_number"Android:textcolor="@color/family_spinner_text"Android:textsize="18sp"/> <textview android:id="@+id/country_code"Android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginright="10dp"Android:duplicateparentstate="false"android:text="@string/family_dialog_phone_number"Android:textcolor="@color/family_spinner_text"Android:textsize="18sp"/></linearlayout>
能看到这里,说明也是缘分。广告一下。有缘人看过来:这里上有70后靠谱大叔CXO,下有90后萝莉鲜肉,前有各种博士搞定算法硬件,后有脸皮厚猥琐男拿下销售。
如今人手紧缺,安卓开发。IOS 开发,UI/UX。产品经理都须要人,活真的要干只是来了。希望自我驱动力强,能够平衡风险收益的同学欢迎来勾搭。鄙人37度手环安卓开发,扣扣:84365252。
[1]: Https://countrycode.org/country Code
[2]: http://developer.android.com/training/basics/supporting-devices/languages.html Support Multi languages
What I used when I was writing multi-lingual Support.