Localization
Localization is an important aspect of Android development, as applications often need to support multiple languages and regions to reach a global audience. Android provides several features to support localization, such as string resources, locale-specific layouts, and locale-aware formatting.
Here's an example of how to use string resources to support localization:
// In res/values/strings.xml
<string name="hello_world">Hello, world!</string>
// In res/values-fr/strings.xml
<string name="hello_world">Bonjour, le monde !</string>
// In code
String hello = getString(R.string.hello_world);
In the above example, we define a string resource called "hello_world" in the default strings.xml file, with an English message. We then define the same string resource in a French-specific strings.xml file, with a French message. Finally, we retrieve the localized string in code using the getString method, which will return the appropriate string based on the device's current locale.
No comments:
Post a Comment