3

How would I store some language independent values like website address in an Android project. I am currently storing it inside my strings.xml. This does not look good as if I add another language and translations, this entry will still have the same value and will be duplicated.

I would also like to get some tips on creating Android projects with I18N in mind.

4 Answers 4

5

You don't need to create the same keys in the translated xml file again. If Android does not find link in the German/Spanish/Whatever language file, it will fall back to the original key stored in the default string.xml.

I suggest to implement the English version first and after that let someone translate it.

Sign up to request clarification or add additional context in comments.

3 Comments

Ok, I didn't know of this feature. So no code change required in such cases.
The basic idea behind that is obvious in case of the application name. You don't need to put the "Awesome" into all language files.
You'll also want to tweak your lint settings in preferences to avoid warning messages.
0

for i18n-format, you can create some resources folder for one local :

/res/values <- default locale /res/values-fr <- values for french locale ... 

For more examples, read documentation : http://developer.android.com/guide/topics/resources/localization.html

Comments

0

For language independent Strings just create a class with constants :

public class MyIndependentStrings { public static final String SOME_STRING = "Value"; } 

Usage :

tvMyTextView.setText(MyIndependentStrings.SOME_STRING); 

In this case you will use constants and not i18n Strings from ../values/strings.xml

2 Comments

this way he cannot use them in xml files
"In this case you will use constants and not i18n Strings from ../values/strings.xml" - I mentioned it.
0

Try putting language independent strings in:

\res\values-nodpi\strings.xml 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.