Changing the locale for a device is done in the settings, and can't be done by an app AFAIK.
I know how to force my own app to a specific locale, described e.g. here:
http://www.tutorialforandroid.com/2009/01/force-localize-application-on-android.html
So now to my question. Can I force, programatically, the local of an activity that isn't mine?
I can imagine 2 ways this could be possible:
Specifying the locale in an Intent used to start the activity.
Access and manipulate the configuration of running activities (in the same way as I can modify my own activities' configurations).
Any thoughts? Is it possible? Is it reasonable?
I guess 2. would be more direct, but require some kind of permission (e.g. the modified atcitiy must allow it in the manifest file). But I'd settle for 1. or similar.
What I want is to be able to see certain apps in a different language, but rather not change the system locale. E.g. the Android Market, that only displays comments in one language. Can't think of other things right now.
Can't find much written on Locale in the documentation, what is and isn't possible. But hoping some undocumented feature might enable this :)
You can't unless the activity you are calling accepts a special locale parameter.
So, you can implement this with two of your own apps, or with the app of your friend, but there's no general way of doing this.
The only way I can imagine is to programatically change the locale of the whole device.
But I think you can only open up the preference screen and need the user to choose the correct locale before starting the app.
Related
In our Android app, we have an option for the user to change the language, which means he can select whether he want to use English or Sinhala. The default is always in English. We have one string.xml for English and another for Sinhala.
I was referring Android documents about "localization" but that is not exactly what I am looking for, I can't ask the user to change his phone settings. I also noticed programmatic localization which is discussed in here but most users do not recommend it due to loads of errors (anyway these posts are pretty old)
So, what's the best way of changing the String?XML file, with the preferred language of a user? It seems not easy on Android.
Or, is this is simply not a good idea?
I'm finally trying out some localization stuff on our application, and I've seem some posts regarding changing the application locale, and changing the System locale.
I've wondered if within the scope of our application, does it matters if I change the System locale or the application locale?
As far as I could notice, changing the application or the system Locale is not different with a side note that one would have to refresh the views.
I've wrote a post about my experience with Multi-Languages... leave your comments at the bottom.
I need my app to have all UIs refreshed to use the new locale that the user just switches to without the need of restarting the app, is there a way to do it?
When I tested my app, for example, I was using English and now I change to use French, some UIs did get updated to display in French while some remains in English. Is there anything I could have been missing?
Thanks!
If locale is changed via device settings, then default behavior for activities is they are recreated/restarted by the system automatically, giving them a chance to use proper string resources (if an app has different string resouces for different locales, of course).
This is called Сonfiguration changes. Other types of config change would be device rotation, font size change, etc. But programmers can override the default behavior iether stating in AndroidManifest.xml what confic changes to bypass OR overriding Activity.onConfigurationChanged().
So, make sure (1) you have a dedicated string resources for each supported by your app locale and (2) you don't prevent the default on config change behaviour for this type of config change.
In my android app I need to do something like this: I have 5 languages. When app starts the user choose one of them from a spinner list. For each language there is a string.xml file. The question is: there is possible what I'm trying to do or not?
Implement the tutorial for localization.
It's only only a few steps and well-explained.
A setup like that would be unneccessary as the Android system handles this. Having your different language xml files will suffice (make sure you name them correctly, see the link posted by Raz). Android picks out the right file based on the language selected by the user within the Android OS settings.
Yes, you can do this by changing the Locale of the application. There's a similar question in here, see Changing Locale within the app itself
Yes, it is. Details: http://developer.android.com/guide/topics/resources/localization.html
I have an unusual problem. I need to force-localize an app -- i.e., force it to load in a specific language, regardless of the phone's language setting.
What our client wants basically is to create language-specific builds of our app. We have all of the resources defined for different languages, and can therefore build an app that will automatically localize based on the phone's settings. But he also wants separate builds for specific languages. Before you say it: yes, I know that this is fighting against Android's Localization system. Yes, we did explain that and try to talk him out of it. But this is what he wants, so it's what we have to do.
I have found some good tutorials on doing this using Locale.setDefault() and the android:configChanges="locale" tag in the Manifest, and that seems to work just fine for setting the language inside Activities. But it has one shortcoming: it doesn't effect the app icon or the app label (i.e., what shows in the launcher), because those are retrieved from the Manifest at compile time.
So I'm trying to find the easiest way to handle this. I know if all else fails, I can write a Bash script that will just move the localized versions of those resources into the default directory before compiling. And if it comes to that, that's what I'll do. But I want to see first if there is a more elegant way that I'm overlooking.
Anyone have any suggestions?