Localization by Location or Region? - ios

How can I make the localization independent on the OS settings?
For example, if the device language is en-US,
But I want the user to be able to set the app to work using Hebrew localization.
In my case – I have an app that in emergency cases the user (in Israel) need to call a number (101).
I made localization to hebrew & english for that app, & when the user is switching to english lang' the dial number & pic' is changing to 911,
But what if a user in Israel wants to use english lang' on his iphone? he doesn't need 911, he needs 101.
I thought maybe to create tableview with all the numbers rather than a specific number but the access to the numbers list will not be quick and easy for dialing because of the multiple numbers.
Is it possible to make localization by location or any other way for doing that?
I appreciate the help.

query NSLocale for the NSLocaleCountryCode. The values from [NSLocale currentLocale] do not depend on the language setting, they depend on the region settings.
These are the values for my currentLocale. Language is set to english and region is set to germany.
NSLocaleIdentifier : de_DE
NSLocaleLanguageCode : de
NSLocaleCountryCode : DE
preferredLanguages are:
en,
fr,
de,
ja,
[...]
more fanciness: use geolocation to figure out the actual location of the device. It's possible that your users travel outside of their country ;-)

Related

How to get iOS language + region codes

I can retrieve all language codes like so:
Locale.isoLanguageCodes
And all region codes:
Locale.isoRegionCodes
But I would like a list of all language ID's. There is a short example list described in the Apple Language and Locale IDs reference
en-AU for English as used in Australia
en-GB for English as used in United Kingdom
fr-FR for French as used in France
fr-CA for French as used in Canada
de-AT for German as used in Austria
de-CH for German as used in Switzerland
I'm hoping there's some standard list so I wouldn't list all possible permutations of Language + Region. Then I'll get combinations like, Italian as used in Mongolia. Anyone know of a source or method to produce a standard list of language ID's?
Bonus Question - Does anyone know how to get a list of the full spelling of the languages or regions and not just the code?

Use a different region notation than the system's region notation

On iOS, an app can use a different language than the system language if the developer passes the NSLocale to the right instances, or else if the proper values are written to NSUserDefault's AppleLanguages key.
I don't seem to find a way to do this also for the region, the part that takes care of number formatting.
The use case here is that I want a UITextfield's DecimalPad keyboard to show a comma for a decimal no matter what the system's region is set to.
Is this possible?
You can use AppleLocale instead of AppleLanguages.
E.g. -AppleLocale nl_BE will set the locale to Dutch with region Belgium.

Standard for specifying Locale in the URL

Is there a standard for specifying the Locale (Country+Language) in the URL. I have seen:
example.com/fr-fr/page
example.com/page?locale=fr-fr
fr.example.com/page
example.com/page^fr_fr
I'm not sure if there's a standard in place, this is usually free of choice and depending on the project scope.
I think it matters more to put the language first because many countries use the same language. So you specify the language first and then the 'region' to narrow down.
Answering the following questions can help choosing the format:
do you need to support multi-languages per country (ex. dutch in belgium: nl/be & dutch in the Netherlands: nl/nl) ? This is usually when you need to track analytics per country/language.
do you just need to support the main languages (en, de, fr, es, pt, jp,...) and not care about the regions ?
does SEO matter ?
what looks better visually ?
I usually go by www.url.com/{LANG}/{COUNTRY}/ or www.url.com/{LANG}-{COUNTRY}/

How to detect correctly language user of device objective-c?

I have a query about iOS. I want to detect language of my device, for change any texts in my app if language is english and other if isn't english. But when I detect language, always detect region and not detect language. In others words if I go to change language, this don't change. If I change region, language changes.
My code is:
NSString *userLocale = [[NSLocale currentLocale] localeIdentifier];
NSString *userLanguage = [userLocale substringToIndex:2];
NSLog(#"%#", userLanguage); // return format "en", "es"... (english or spanish)
Could be that this problem appear because with [NSLocale currentLocale] get en_Us and this parameters depends of region?
Thanks!
If you want the language try
[NSLocale preferredLanguages];
It will return an array of the user's language preference and the most preferred language will be the first in the list.
NSLocale encapsulates a lot more than just the current language. Things like currency identifier and what to use for the decimal separator are just a few. A Spanish speaking user in the northwestern United States may want to see things in Spanish but would probably still expect to see the $ for currency.
With that said I suspect what your really looking for is full fledged localization support in which case there is tons of information out there on how to localize your app. The macro
NSLocalizedString
and its siblings allow you to write language agnostic code (for the most part).

NSDateFormatter: Only show localized dates if app is localized for the language

I'm currently writing an app for the iPhone that heavily works with dates. I'm using NSDateFormatter to convert dates to strings. Conveniently, NSDateFormatter automatically creates strings in the user's language based on the region format.
Because I can't localize my app in all possible languages and regions, the app is only localized in English, German, Spanish and a few others.
When the app is running for a French user for example, the app defaults to English. That is fine, but the dates will still be converted using the French language. This results in strings like "Month: Juillet" instead of "Month: July".
How can I make the NSDateFormatter always use the language the app runs in?
I know that I could use NSLocalizedString() to localize NSLocale identifiers, but this will yield in incorrect region settings.
When the user usually uses a "en_GB" region and my app is localized for English in general, I want the NSDateFormatter to use "en_GB" and not just "en" or "en_US". When the user runs French, I want the locale to be "en" and if he runs the app in the "de_DE" region, I want the date formats to be "de_DE", too, because the app supports German.
Regards,
Fabian
When you create the date formatter, it initialises it's style from the current locale, but you can override this.
[not tested]
You can get the best locale from the users list and your available locale using
NSBundle:
+ (NSArray *)preferredLocalizationsFromArray:(NSArray *)localizationsArray
NSFormatter:
+ (NSString *)dateFormatFromTemplate:(NSString *)template options:(NSUInteger)opts locale:(NSLocale *)locale
Should give you a localised format string for the specified locale.
You can then use setDateFormat to override the initial date format for the formatter.

Resources