I have been going through the process of localizing my apps and in doing so I temporarily set the language to Chinese like this:
ApplicationLanguages.PrimaryLanguageOverride = "zh-CN";
However, after commenting out the line and rebuilding / re-deploying, now my app is still stuck in Chinese instead of what my development machine's default language at the OS level (English)!
How do I reset this to go back to the default OS setting?
Just assign an empty string to the PrimaryLanguageOverride property :
ApplicationLanguages.PrimaryLanguageOverride = string.Empty;
The PrimaryLanguageOverride setting is persisted between sessions. It
should not be set each time the app is loaded. It should only be set
based on user input presented in settings UI. The property can be read
at any time. If the property has never been set, it returns an empty
string.
So if you set the property to an empty string, the app will use the default language.
Related
I want to get value of time sets by user or automatically , is there any way to do it in ios ?
Value that i want for :
Settings > General > Date&Time > Set Automatically
or
I'm looking get correct time while there is no internet connection.When i'm set the automatically in settings,the time sets correctly by phone so is it a way that same value.
Thanks
No, you cannot access that setting value. You need to rely upon a network based time to be sure of actual time.
is there a way to set the text of a Label (Toybox.WatchUi.Text) with a localized string programmatically at runtime? I know how to set a localized string for a label from within the user interface XML files and was wondering if this is also possible from within a Monkey C file, e.g. label.setText("#Strings.localization_key")?
I discovered the Github Account of Garmin where they also provide some example code of Applications and I found the solution in one of the projects.
It's simply Rez.Strings.<string_id> with the ID and the respective translation in one of the string resource files.
However, it does not seem to work to concatenate the localized String with another string and put the concatenation as text in the label. Obviously, the internal String-ID is then displayed rather than the actual string. This behavior occurred for me with the Connect IQ SDK 1.2.5.
Here's the scenario. I have a set of settings in an app. For example consider my app as a video player. So there are settings like allow full screen, display subtitles etc. All these settings have boolean values since you either turn on or off them.
These settings should display inside the app in a table view. And if any of them are activated or when the user taps on them to activate/deactivate, you show it by setting the checkmark accessory view of that cell.
Since I need the settings to be displayed this way and only within the app, I cannot simply use Settings bundles. There's also another catch. I need these settings to be localized.
What I initially thought was to have separate plists for the languages I support.
Settings_en.plist (English)
Settings_sv.plist (Swedish)
Then fetch the plist name depending on the system language and display its values.
let filePath = NSBundle.mainBundle().bundlePath.stringByAppendingPathComponent(NSLocalizedString("SETTINGS_PLIST", comment: ""))
But this is not ideal because say I'm running in Swedish and I change the Subtitles setting to on. Now i have to update this in both plists. This will quickly become even messier if I add more languages in the future.
Is there a better way to store settings which is easier to save and fetch and also supports localization?
I was able to find an answer elsewhere. Here are the steps taken to resolve this issue.
Instead of multiple plists, create one plist and have the keys in English language.
Then have the localized strings in your string files with the same English keys.
Localizable.strings (English)
FULL_SCREEN = "Full Screen";
SUBTITLES = "Subtitles";
Localizable.strings (Swedish)
FULL_SCREEN = "Helskärm";
SUBTITLES = "Undertexter";
In the code when you're displaying the values in a table view, refer to them by that key.
let setting = settings[indexPath.row] as [String: Bool]
let title = setting.keys.first
cell.textLabel?.text = NSLocalizedString(title!, comment: "")
I've got an app that used a multi value menu in the settings bundle to configure the rate at which the on-screen map is refreshed. The panel is set up like this:
When I run the app on my phone, I immediately go to the settings app and the menu reads "1 sec" as I expect. When I return to my app and attempt to initiate the map update the app crashes with "fatal error: unexpectedly found nil while unwrapping an Optional value" and highlights an EXC_BREAKPOINT, when I step back through the code I am taken to the settings for my multi value menu. Also, if I go to the settings app first and manually re-selct the same value the app runs perfectly. The highlighted code looks like this:
Have I incorrectly set up the default value?
Based on the fact that there is an error unwrapping the optional, I bet that NSUserDefaults.standardUserDefaults.stringForKey("mapUpdate") is nil. You should double check that.
If that's the case, you'll need to register your plist file for use with NSUserDefaults. See How to set initial values for NSUserDefault Keys? for defailts on how to do that.
In desktop applications when talking about a config file sometimes it's about letting the end client change some parameters according to his systems - for example entering his system IP or other parameters that can not be hardcoded, and must change by him because the user doesn't want you to know them.
I read about the option to create a settings.plist and reaching the value from NSBundle but how can the end client change the values in it?
You're talking about implementing a settings bundle. Once you've done that, the user will be able to adjust the values in the main iOS Settings app - there will be a section for your app.
There are many Preference control types available. You can use a Text field.
The text field type displays a title (optional) and an editable text field. You can use this type for preferences that require the user to specify a custom string value.
The key for this type is PSTextFieldSpecifier.
To retrieve the edited value at run time, use the below code.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *iPAdress = [defaults objectForKey:#"IP address"];
Once these all done, Go To your iPad default Setting App-> You can view your application name listed under Apps section. Tap on it.