David Galstyan
David Galstyan

Reputation: 71

Android implement multi-language support

Best way to implement multi-language support on android 1. Using string.xml file 2. Getting language translations from server side?

And have a way getting xml from backend and save in resources? Back end developer suggest me getting language translations from server.

Upvotes: 1

Views: 504

Answers (2)

Mark JW
Mark JW

Reputation: 496

I use the Android framework for all my Apps in China. The steps are:

  1. maintain a list of all your strings.
  2. Do not hard code your stings in your Android Java, refer to the XML.
  3. You can use server sites like Google translate or Baidu Fanyi (translate) or equivalent for the translations.

For example, here is a sample of my activity code to reference a string:

tx1 = (TextView) findViewById(R.id.your_textview);
tx1.setText(R.string.msg_about_feedback);

Here is excerpt of the res>values>strings.xml

<string name="msg_about_feedback">Feedback</string>
<string name="msg_about_filesource">File Source</string>
<string name="msg_about_cloudIP">Server</string>
<string name="msg_about_localIP">Server</string>
<string name="msg_about_serverIP">Server</string>

And here is the res>values-zh>strings.xml

<string name="msg_about_feedback">反馈</string>
<string name="msg_about_filesource">文件源</string>
<string name="msg_about_cloudIP">服务器</string>
<string name="msg_about_localIP">服务器</string>
<string name="msg_about_serverIP">服务器 IP</string>

You have to make sure the entries in each of the language files match up. Android Studio will flag an error if one of the strings is missing in the files. Using this approach, everything is handled by Android.

If you are not familiar with the secondary language(s) then it is best to have someone check the translations. Often time you don't get a correct when you blindly take the output of the translate servers due to context, grammar, etc.

Upvotes: 2

Ratish Bansal
Ratish Bansal

Reputation: 2442

Best way is to use string.xml files.That's great framework support from Android for I18n handling ,and enterprise apps are build using that.

Upvotes: 1

Related Questions