mario595
mario595

Reputation: 3761

Using strings from @android:string

I am a bit noob in Android and recently I found out that I can use the predefined string that Android provides as @android:string/cancel or @android:string/ok. At first I thought it was a good idea to use them because is a way to reuse code, but now I am not so sure about that.

What if somebody with a device configured with a language that I don't support install my app? I assume that the app will use a default language, probably english, but those string from @android:string will get translated to the user's language, so he will end up with a mix of languages.

It this true? What do you think about use @android:string?

Thanks!

EDIT: Apparently my question hasn't been understood properly. I am NOT asking about how to support different languages. My question is about the convenience of use strings defined on @string:android, if it is correct to use them or can be lead to undesirable situation like a mix up of languages in the same application.

Upvotes: 5

Views: 256

Answers (3)

scottt
scottt

Reputation: 8371

The android: values (strings, icons, themes, etc.) will differ between devices and Android versions. If you want to use them, it's safest to copy them into your project. So for strings, you wouldn't have to worry about partial translation.

Upvotes: 1

marius
marius

Reputation: 172

In the ressource folder of your app (res), ther is a folder "values" in it, and in this folder is the string ressource xml (strings.xml).

Usually, your app selects the strings from this file. But you can add other value folders like this: Just create a new folder and name it "values-countryCode", for example "values-ch" for Switzerland ;)

Your app automaticly chooses the right string ressource, depending on your device's langague settings. If the langague of your device isn't available, it just takes the sting ressource of the default "values" folder.

A list if the country-codes is here. Further information can be found here.

Hope I helped, and this is what you're looking for!

Upvotes: 0

Matt Antonelli
Matt Antonelli

Reputation: 119

To ensure that your strings are appearing properly on devices configured with different languages, you'll want to create different values directories for different languages. For example, your default string values would be kept under values/strings.xml and French string values would be kept under values-fr/strings.xml.

The Android Developer website gives you plenty of information for supporting different languages in your application. http://developer.android.com/training/basics/supporting-devices/languages.html

Upvotes: 3

Related Questions