I am making an app where I want to detect the language of the current country that the iPhone is in. By this I don't mean the locale (which doesn't change if you're vacationing in a foreign country). Ex: If I live in the US and travel to Mexico, I want the detected language to be Spanish.
I am willing to use the GoogleMaps pod if necessary. Just wondering if there's an easier way built into the iOS frameworks. I see a lot of SO questions / answers using NSLocale but people warning that it's only for the phone setting.
p.s. I'm using Swift
You can use CLLocation Manager, to obtain current country (by using placemarks). But then you need to somehow check if you have the language for particular country is available in your app (for example create a dictionary of all languages and compare it, as you mentioned in the comment). There are no frameworks to get current country language in iOS. You need to build your own logic.
you are better off defaulting to the language setting of the device. Let the device dictate the language as that is the language the user wants to use.
Related
By Default WatchOS's presentTextInputController is recognizing in english language, we can change the recognizing language using deep touch.How to get the language code when user changes language using deep touch while recognizing?
I don't think this is possible at the moment. Looking at the documentation of WatchKit, there doesn't seem to be an API for this.
However, you can call presentTextInputControllerWithSuggestions(forLanguage:allowedInputMode:completion:) if you want to specify what language you can handle. See the official documentation.
I have a picker view which I want it to change the language of the app, I have localized my app with 3 languages and it switches to different languages when I change device language but how can I use the picker view to change the language of the app ?
I'm using Xcode 7 and swift 2.1
Short answer: You can't. The system is starting your localized app according to the device settings, which you cannot override.
Side note: If you opt to not use any localization features provided by apple and implement everything yourself, you may provide whatever means to change your own language setting in-app. But that is a real pain and you are likely to make mistakes, not taking into account anything.
If you want to go down that road, see semanticContentAttribute to help with problems regarding RTL languages.
Also, please note that this might become a problem in review. Most apps should not need to reinvent the wheel here.
We are migrating our app from iOS6 to iOS7 and we use programmatic way of creating view (rather from storyboard or nibs).
We are trying to support multiple countries with different languages.
Example,
English for - China, India, US
Simplied Chinese for- Taiwan, China
There can be custom override's for specfic country from the basic language localization set.
Now I need to have a common base for language bundles and country specific bundles.
Common Language Bundles: (base language bundles)
en.lproj
zh_hans.lproj
Country Specific Override Bundles: (if i have custom text for each specific countries)
ch(ina)_en.lproj
ch(ina)_hans.lproj
us_en.lproj
Problem:
Resource files (Translations) have to be duplicated for each countries(chinese, taiwan) with english, chinese. How can we avoid this ?. Images are also duplicated sometimes, it is a maintenance problem, if we start support more than 10 countries.
Android supports delta overrides of translations for each language translation per country, do we have anything in iOS similar to that ?.
I know it is not supported out of the box from iOS. What is the right way to achieve the same without duplicating the resources ?. Any hints or ideas to achieve the same ?.
Thanks,
Alex
I hope I've understood correctly.
1a.Image files will only need to be duplicated per language if they contain text or "imagery" that requires translation otherwise there should only be one version. From memory, you select which image files you want to be translated.
2a.A translation is needed for each language you want to support - there is no way round this (obviously). These usually live in "strings" files which you send off for translation.
2b.If you don't supply a specific translation for a string it defaults to the "base" translation. Unfortunately, I don't know how this would work with two "base" translations or even if this is possible as usually the base translation is the language you developed in. You will need to investigate further.
2c.You will need to manage deltas to your strings file yourself - through GIT perhaps? This is annoying but do-able although there may be third-party products that can do this.
I am in the process of developing an iOS application that needs to tell the server it communicates with the current language being used on the iPhone/iPad. I am currently using:
[[NSLocale preferredLanguages] objectAtIndex:0]
However because the App is a word based game in the case of English being used (en) this is not enough to go on, I need to be able to distinguish between en_GB and en_US (and potentially other languages in the future).
Currently I have two ways of doing this:
1) Use the currentLocale setting to get the current country code of the device and combine that with the preferredLanguage, however this is rather hacky.
2) Roll my own page to allow the user to change the language in App.
I am leaning towards option 2 but it will involve a fair chunk of work.
My question is, is there a better way of achieving this?
iOS does include British English (en_GB), as opposed to US English (en), so in this particular example you could rely on the user's iOS language setting alone. If the user has selected British English and your application includes it in its list of localizations, then you should see en_GB using your line of code.
But of course, if you wish to support a language that iOS doesn't itself expose, you're stuck with having to provide your own picker.
On an iPhone, when the user sets their Language to French and their Region Format to United States, the CurrentCulture represents en-US.
Only when the user sets their Region Format to France do I get fr-FR;
How can I determine the language if the user has set their Langauge, but not their Region Format?
You want to look at NSLocale, e.g. NSLocale.CurrentLocale.Identifier to get a string like en-US. That will give you the exact values that iOS is using.
Both .NET and iOS have similar, but subtly different, API to get those values. It's difficult to be fully compatible with .NET by using only iOS data (it's not a perfect fit). In some case, e.g. RegionInfo, we have been able to bootstrap the .NET classes using iOS provided data. As more features becomes available we might be able to do the same for other types in the future.
NSLocale.CurrentLocale gives the region format, not the language.
To get the language, use NSLocale.PreferredLanguages[0] instead. The result will be a string like fr or en-US for the language that is selected.
For more info, see Getting current device language in iOS?.