membersound membersound - 1 year ago 128
Android Question

How to load locale dependent strings in android programmatically?

In Android it's possible to define i18n strings with:

values/strings.xml
values-de/strings.xml


And use them in xml like:
android:text="@string/hello"


The local specific string is automatically resolved.

But: how can I achieve the same programmatically? Load the string from the styles definition, automatically in the correct localisation?

Answer Source

Whenever you retrieve the String using the Context it will return the locale dependent one.

context.getString(R.string.hello);

You can see more from the documentation here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download