I want to change the language of my app. At the moment I am doing it at the following way.
I have two buttons which are change the languages in NSUserDefaults. But before this affects my app I need to restart it.
Here is my code.
- (IBAction)changeDutch:(id)sender {
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:#"nl", #"en", nil] forKey:#"AppleLanguages"];
}
- (IBAction)changeEnglish:(id)sender {
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:#"en", #"nl", nil] forKey:#"AppleLanguages"];
}
This works fine. But I don't want every time to restart my app. Can anyone tell me how to do that?
Kind regards!
Check out HMLocalization: https://github.com/HeshamMegid/HMLocalization
It's a replacement for the default localisation framework. It has a demo showing how to change language without having to restart the app.
There is a method to change app language without restart mentioned this tutorial post I've tried it in an app and it works mostly but still if you are using system items like More tab in tabbar, Edit button on MoreNavigationController and Cancel button on UISearchBar and so on, there text can't be changed for selected language without restarting app. If there is no such item that is controlled by iOS instead of your app, this is a perfect solution for you.
If your data is in UITableView then you could use [tableView reloadData];.
You can even set the app languages in appDelegate, defined in Constants, keys, then on the IBAction call those keys then be stored in NSUserDefaults.
which way you're using for localization, I mean to ask is that native in which we just only maintain the folder structure or taken from Db.
Anyways, If you're using native part, then look at following link which may assist you as I think we can replace the language option there:
"http://stackoverflow.com/questions/3910244/getting-current-device-language-in-ios"
(Frankly speaking, I've no idea)
But if you are using the db part, then in that case you just use some enum based tact and according to which just fetch your data, that approach is simple as I've already applied in so many apps.
In any concern, just back to me. :)
Related
I am working on Localization of my App to support English and Spanish language.I have created the string files for both english and spanish.All the strings in my app are managed by
`NSLocalizedString(#"key", nil);`
and give the expected result.I have given an option for changing the language inside my app in a tableview.
NSUserDefaults *nsdefault=[NSUserDefaults standardUserDefaults];
nsdefault setObject:[NSArray arrayWithObject:#"en"] forKey:#"AppleLanguages"];
nsdefault synchronize];
1) I need to change the app name and icon depending on the selection of language in tableview.For app name i used "CFBundleDisplayName" = "Librairie";
so that the next time i launch the app the app name and icon should change.
2)for app name
`"CFBundleDisplayName" = "Librairie";`
.It works only if i go to iPhone's setting and change the language manually.Through code it doesn't work.
Please suggest me the approach i can follow so that when i choose spanish language from my tableview the name and icon gets replaced.
can i localize the app icon image also like we do for any image used in UIView ?
Any help would be appreciated
Thanks
You can't change neither the app icon, neither the display name. Both of those are read only once the app is installed, and even if you could, those would create a really bad user experience.
I've been doing some research and so far I've been unable to find out how to display a Settings.bundle inside an application. The guides that I found are:
http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/Preferences/Preferences.html
http://blog.webscale.co.in/?p=274
http://knol.google.com/k/iphone-sdk-application-preferences#
These all seem to skip a step: How to display the plist from a view in your application. I've got my view set up and my plist file set up, but I have no idea how to display the preferences plist from the view. Do I manually load everything and put them into labels, switches and whatnot?
This may seem like a stupid question but I honestly don't know. Would anyone be able to explain this to me?
Thanks in advance
EDIT: To clarify; I've found out that this allows me to access the preferences through the settings app. However I want to access these through a tab in the app itself.
http://knol.google.com/k/iphone-sdk-application-preferences#Step_4(3A)_Retrieving_Values_of_Settings appears to describe exactly how to access these...
It's a one-liner so i'll paste it here:
NSString* settingValue = [[NSUserDefaults standardUserDefaults] stringForKey:#"<Setting Key>"]
There's no magical setting key that you have to use. Use whatever you like, and it'll be there the next time the application loads.
I got the same problem; I have an application with a tabBarController as the RootController of my application and, separately, I have a settings menu (loaded from plist) available through the applications preferences of the device.
I do want to include this settings menu into my app as an other view for my tabBarController in order to avoid to have to exit my application to change the settings.
Finally, I have the plist file ready, I just want to know a way to do something like
[C#]
settingsController.View = UIView.LoadFromPList("settings.plist");
tabBarController.addController(settingsController);
... anybody knows ?
Lets say i have an application which has three text-fields, and i can type whatever i want into them, lets also assume that i have a checkbox and a button. And if the button is tapped while the checkbox is checked, the nsstring values in these textfields should get saved somehow. Lets say i power down my iPhone and restarted it, opened the app once again and wanted those values to be in their respective textfields.
How does one do this?
Is this a case for NSUserDefaults or something for Apple's own Keychain API to handle?
Cheers.
Edit: We used local declarations when setting and getting the values of the NSUserDefaults, which of course, doesnt work. It works perfectly now...
Yes you can make use of NSUserDefaults
Integrate a sqlite3 database into ur app.. save the textfields value in an array and sav it in the database. On starting of the apps just load from the database and retrieve the top most array and show the values back as output.. Hope it helps.. I am new also.. but cant think of anything else if u want to restart ur whole phone and still wants the fields to be filled.
Use NSUserDefaults for stuff that doesn't need to be stored securely and Keychain if it does.
You can use the NSUserDefaults or a PList or a database to save the content.
Example is given below:-
[[NSUserDefaults standardUserDefaults] setObject:#"Jayahari" forKey:#"userName"];
PList can be used for archiving, serilizing. Database also can be used for same purpose.
I'm writing an iOS app, where I want the user to be able to change the UI language independent of the iPhone's or iPad's language. The question is, how do I reload the appropriate NIB file for the currently displayed view when the language changes and how do I load the appropriate .strings file so that NSLocalizedString works appropriately?
This should do the trick, assuming that de is the new language selected by the user. Also assure that you are reinitiating the current view.
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:#"de", nil]
forKey:#"AppleLanguages"];
Personally, I don't like the idea of giving NIB files to translators. Instead, I design the NIBs so there is enough space for non-English languages (typically they will require 50% more room for text), and then I store all text resources in Localizable.strings files.
Then, in my code I set the text for each UI control.
[_myButton setTitle:NSLocalizedString(#"My button title",
#"My description for translation file, e.g. including chars limit")
forState:UIControlStateNormal];
I find this makes the translation process easier to manage.
To answer your original question, you would put this code in the viewWillAppear function of your UIView to ensure it is reloaded each time the UI reappears.
I've got application settings working just fine. However, I'd like to be able to change my app settings from within my app.
It seems as though there should be some kind of generic way to add this functionality to my app without having to recreate all the controls myself. I mean, the code is already written in apple's settings app.
Maybe someone wrote this code and open sourced it? (if it is not already available)
I prefer my own Settings class as I don't like to write the same stuff again and again. Therefore I am using a method like ...
- (void) setValue:(id)value forKey:(NSString *)aKey {
[[NSUserDefaults standardUserDefaults] setObject:value forKey:aKey];
[[NSUserDefaults standardUserDefaults] synchronize];
}
and fetching would be ...
- (id) valueForKey:(NSString *)aKey {
return [[NSUserDefaults standardUserDefaults] valueForKey:aKey];
}
A lot of people have thought the same; file a bug with Apple, and maybe eventually they'll listen.
I believe you're looking for NSUserDefaults. The documentation is available here.