Issue
I have an android app that targets the SDK Version 25 and the min SDK 17. This is app is supposed to be in 4 languages : French, Swahili, English and Kirundi.
But for some android devices, all four languages work properly but for some others, all other languages work except Kirundi when the user switches to it.
Here is my code:
public class LanguageSwitcher extends AppCompatActivity {
//Variables declaration
private TextView bdi,en,fr,sw;
private Resources res;
private DisplayMetrics dm;
android.content.res.Configuration conf;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_language_switcher);
bdi = (TextView)findViewById(R.id.bdi); //Kirundi textview
fr = (TextView)findViewById(R.id.fr); //francais textview
en = (TextView)findViewById(R.id.en); //english textview
sw = (TextView)findViewById(R.id.sw); //swahili textview
res = getResources();
dm = res.getDisplayMetrics();
conf= res.getConfiguration();
//getting the sharedPreferences
SharedPreferences sharedPreferences=getSharedPreferences("profile", Context.MODE_PRIVATE);
String lang = sharedPreferences.getString("lang","");
final SharedPreferences.Editor editor = sharedPreferences.edit();
bdi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
conf.locale = new Locale("rn"); // API 17+ only.
editor.putString("lang","rn");
editor.apply();
res.updateConfiguration(conf, dm);
startActivity(new Intent(getApplicationContext(),Acceuil.class));
}
});
fr.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
conf.locale = new Locale("fr"); // API 17+ only.
editor.putString("lang","fr");
editor.apply();
res.updateConfiguration(conf, dm);
startActivity(new Intent(getApplicationContext(),Acceuil.class));
}
});
sw.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
conf.locale = new Locale("sw"); // API 17+ only.
editor.putString("lang","sw");
editor.apply();
res.updateConfiguration(conf, dm);
startActivity(new Intent(getApplicationContext(),Acceuil.class));
}
});
en.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
conf.locale = new Locale("en"); // API 17+ only.
editor.putString("lang","en");
editor.apply();
res.updateConfiguration(conf, dm);
startActivity(new Intent(getApplicationContext(),Acceuil.class));
}
});
}
}
I don't know where I am wrong with my code. I need your help
Solution
I made some researches and found that unlike other languages, Kirundi resources should be under res/values-rn-rBI folder instead of res/values-rn folder. rn as ISO 639-1 language code like for any other language in Android and BI the ISO 3166-1 Alpha-2 Code for the country (Burundi) and that worked.
Answered By - Gratien Asimbahwe
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.