0

I am trying to do localization to my android application. The error message is not changed unless i force stop the app and start it after the language is changed.

public interface ApplicationConstants {

Resources res = MyActivity.getInstance().getAppContext().getResources();
public static final String NETWORK_ERROR_MESS=res.getString(R.string.str_network_error);
public static final String AUTH_ERR=res.getString(R.string.str_auth_error);

 }

In res-> values folder

Strings.xml

 <string name="str_network_error"> Network Error english.</string>
<string name="str_auth_error">Authentication failure english.</string>

In res-> values-fr folder

Strings.xml

 <string name="str_network_error"> Network Error france.</string>
<string name="str_auth_error">Authentication failure france.</string>
GrIsHu
  • 29,068
  • 10
  • 64
  • 102
sundeep
  • 601
  • 1
  • 8
  • 21

2 Answers2

1

Try this way: when your main activity load

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

And get the String in your activity like

String NETWORK_ERROR_MESS=youractivity.this.getString(R.string.str_network_error);
String AUTH_ERR=youractivity.this.getString(R.string.str_auth_error);
M D
  • 47,665
  • 9
  • 93
  • 114
  • I have tried to set the local language and my code is reaching that particular part of the code, so now the language is set. But still the message is not changed. – sundeep Mar 11 '14 at 11:23
0

IMHO, all your problems appears due incorrect use of interfaces.
For more information read this answer

Community
  • 1
  • 1
Dima
  • 1,490
  • 16
  • 25