Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Localize app name

I want to localize (values-ru) strings values: textview and app_name. App localizes only textview ("Привет мир") but app_name still the same ("Localization"). What's the problem with app_name localization?

App label name & activity label name in Manifest refer to the appropriate string value.

Manifest:

 <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.local.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

String res/values-ru:

<resources>
<string name="hello_world">Привет мир</string>
<string name="app_name">Локализация</string>
</resources>

Java:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String languageToLoad  = "ru";
    Locale locale = new Locale(languageToLoad); 
    Locale.setDefault(locale);
    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext().getResources().updateConfiguration(config, 
    getBaseContext().getResources().getDisplayMetrics());

    setContentView(R.layout.activity_main);
}
like image 505
Andrew Avatar asked Aug 02 '26 16:08

Andrew


1 Answers

This will change the Locale of your application locally not the mobile. And Manifest pick the value of your application name as per the device locale, not application locale. So you need to set it from settings of your mobile device.

like image 65
skygeek Avatar answered Aug 04 '26 05:08

skygeek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!