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?.
Related
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.
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.
OK so I have been working on an app that will be available in multiple languages.
I have managed to get it working in the main languages, such as French, German, Spanish and English.
I have also now managed to get the app to use different regions within a language such as en_GB, en_US etc etc so all is good - thanks to this guide:
http://hamishrickerby.com/2010/07/23/iphone-ipad-localizations-regions/
One of the most important languages for me is Welsh. Apple allows me to set my iPhone to welsh by choosing British English as my language and region format as Welsh (United Kingdom).
I have created the Welsh language localisation within my app and translated my bits but I don't seem to be able to apply it.
My idea was that if the users language was set to British English that I could have a button on the main view that would allow the user to chose Welsh. Is this possible and what would be the best way to implement it.
Ideally if the user has already set their language to British english and has the region format to welsh they will get the welsh language version of the app just like the french would automatically get the french language version and the spanish will get the spanish version of the app etc but as most welsh speaking users will have their phone set to United Kingdom as they are not aware of the Welsh Region setting in iOS.
I would like the app to detect if the current language is British English and display a button on the home screen where the user can switch to Welsh Language. I have managed to display this button (only if user language is British English) but have no idea how to link it to change the language?
Anyone have any ideas or maybe a suggestion on the best way to implement my goal.
Thanks in advance.
Unfortunately, as you've identified, Welsh isn't a fully supported language on iOS. Until Apple supports it properly, you'll have to implement a bit of a workaround.
It seems as though the main solution is to have both English and Welsh .strings files (like you would with other languages), but manually load the required language, using
[[NSBundle mainBundle] localizedStringForKey:yourString value:#"" table:#"Welsh"];
#"Welsh" could be another language there, depending on what you want to load. You'll have to implement some control within your app so that users can change the language themselves. Check out the example project linked to in this blog post by translation company Applingua - it shows one way of encapsulating this code into a language provider class.
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.
Thanks to #Jano, I know how to localize application strings based on the country in which the application is running - in my question : How to localize text based on criterion other than language. The answer is to take these strings out of the Settings.bundle and bring them into the application, where they can be localized in whatever manner the developer requires.
My question now is: is it possible to localize the application name (the name under the app icon) using a criterion other than language? I think that doing this on a language basis is well understood - there are several questions and answers on Stack Overflow and elsewhere which discuss localizing the BundleDisplayName.
But my customer would like to give the application a different name in the various European countries in which he expects to market it, and some of these countries (Germany, Austria, Switzerland), share a language.
Xcode allow you to add de-AT, de-DE and de-CH localization files, but I have just tried this out and looks like it has no effect. I tried to change device language to German and then switch region format between Austria, Germany and Switzerland, but the bundle display name didn't change from English. When I added de (without a -XX suffix for country) it changed to German name, again ignoring region format. I'm a bit confused as I was under impression we could use those country-specific localizations like that. I hope someone offers a better solution, but until then I would suggest a workaround: building 3 targets, one for each country, and submitting them to AppStore and only making them available in their respective countries.