I'm working on an app which should create an NSLocale object based NOT on the user's region (which should remain at the user's preferred language for most interface elements), but on the physical location of the traveler, to format currency. However, to build an NSLocale I need to concatenate the language (e.g. 'en') and the location (e.g. 'US') to initWithLocaleIdentifier:#"en_US", and thus to get the currency conventions into the formatter.
I can get the ISOcountry code from the CLPlacemark, but the language information... is harder to identify. Is there a lookup table of language options for each country, or some other option for initializing an NSLocale object based only upon the 'country' information?
I've made a cheap concatenation of #"us_US" which seems to work as well as #"de_DE" (!), but I don't know if I can count on that in all cases.
Thanks,
Tim
For what it's worth, it seems that the NSLocales can in fact be initialized -- at least for the purpose of obtaining currency information -- with 'gb_GB' or 'us_US' locale identifier. I haven't found exceptions in the locations offered by Xcode.
Related
I am starting this discussion to gather more info on localization practices for APIs. It seems HTTP does NOT provide sufficient guidance and even the state of practice is not sufficient enough.
The basic problem is that APIs may need to provide content that is dependent on the user culture, country, language and timezone. For example a German user would like to read messages in German language, with European metric dates, numbers, units, using Euro currency and in Central European Timezone.
Reading through RFC 7231 Section 5.3.5 Accept-Language and further into RFC 4647 one may think Accept-Language is sophisticated enough and is what should be done. There are several notable shortcomings though:
Language tags may not be precise enough e.g. user may only request language without country code and thus leave ambiguity as: "de, en;q=0.8"
Even if the user supplies both language and country preferences it is not clear how to tie the selection of message locale and value formatting locale. For example if a user requests: "hu_HU, en_US;q=0.9" while the application lacks Hungarian messages and is written in Java that knows how to format date in Hungarian. So should the app use English messages with Hungarian dates or rather provide English messages with US dates? The actual situation may be more complex.
Timezone is not present in the language tags. There is no HTTP standard header for this it seems.
I see Microsoft have thought about #2 in ASP.Net and introduce the notion of Culture and UICulture to separate selection of message language from formatting.
In Java world Spring have introduced TimeZoneAwareLocaleContext to address #3
W3c have issued guideline to Accept-Language used for locale setting. This more or less says that Accept-Language is not enough
So what is your thinking?
Do you know of APIs tat solve this problem in comprehensive way? Pointers?
Should APIs accept multiple values for selecting message language, value formatting locale and timezone?
Should Accept-Language be used at all?
Ok guys,
here is a summary of how I answer my question. I hope this helps future API authors.
The fundamental requirements for an UI based on top of API excluding currency presentation seem to be:
Select the best language out of the available product translations using RFC 4647 list of language ranges
Select the best data format out of the available using RFC 4647 list of language ranges
Allow clients to provide distinct preferences for translation and format. There will be cases where people will not find the best translation and yet prefer to see the proper formatting aligned with their culture.
Allow clients to specify a timezone using IANA TZDB identifiers
Format data elements using Unicode CLDR http://cldr.unicode.org/
Use named placeholders in localization bundles e.g. "{drive} is corrupt" is easier to translate properly than "{1} is corrupt"
On the REST HTTP headers I suggest use of 3 headers
accept-language - used for selecting translation and following the guidelines of RFC 7231 https://www.rfc-editor.org/rfc/rfc7231#section-5.3.5
format-locale - used to select data formatting style if different from the translation language preferences. Again list of language range elements. Defaults to accept-language if omitted.
timezone - used to select timezone for rendering date and time values. This should be valid timezone ID from the IANA TZDB https://www.iana.org/time-zones
Implementation wise it seems Java 8 and later have full capability to implement a globalized application. Other languages and older Java versions seem to have varying degrees of issues.
I would keep all data in a universal locale independent format. For numbers using . as a decimal separator, date and time using ISO 8601 and in UTC, etc.
Provide localized text only if it absolutely necessary. In that case get the locale from accept-language header field, and if you have the localized string pass that. If not fallback to the string you have.
For example, you might a multilingual product database that contains product data in several languages. When you write an API for the database you can select the product data in user's language (if any).
Here is a sample.
I need to get to the time zone array using Chinese,but ,use TimeZone.knownTimeZoneIdentifiers get is English array
TimeZone.knownTimeZoneIdentifiers returns a list of IDs from the IANA TZ Database. A comprehensive list is available here.
These are not to be translated. They are identifiers, passed as parameters to code to identify a time zone. They are always in English, and their exact spelling, casing, and punctuation should remain intact. If you were to translate it, you would find they are not usable in any API.
If your goal is to display a human-readable translated string in a UI, then you should use the localized names provided by the Unicode CLDR project. I am not an iOS developer, so I can't be certain, but from reading the docs, I believe these are already available to you by using the localizedName instance method of the TimeZone class.
In my application it's possible to store a price for every object and the user can also choose its preferred currency.
What is the best way to store and manage number with currency in iPhone SDK?
More infos about my app:
It uses Core Data.
Number that can be stored must be of type xxx.xx (e.g. 100.00).
How can I sort these numbers ascending or descending?
What kind of attribute I must set in my entity to store a number like this?
Have you got links, docs, source or guides to show me examples? I never user number with currency, then I've got some problems with them :)
Thanks a lot,
Matthew
Store it in GP (gold pieces) with a conversion factor ;)
It doesn't look like there's a datatype for currency, so storing the number and decimal part, and a setting for the current currency, is probably as good as you're going to get. See this: HowTo for newbie: Managing currency in iPhone app
I wrote my first program almost fifty years ago (yes, coding is still a blast, managing big projects with many programmers was not), but my Von Neumann thinking gets in the way.
I want to (a) load default values and (b) account for multiple languages more elegantly (?) than 60-plus iterations of NSLocalizedString. Can I park all of this data into what amounts to a record with fields like this: (key value stuff), (tweak-able user prompt / screen name / whatever), (tasteful default), (user-supplied value)? NSUserDefault has worked well so far; Core Data looks like overkill (?), and sql lite, well, where's Oracle when you need it?
It is certainly possible to store this information in plists and make them localizable; right-click the plist in the Groups & Files window -> get info then select 'Add Localization' at the bottom left.
Enter the country code you would like to support and xCode will go ahead and create a language specific version of the resource.
Your code doesn't need to know about any of this since your app will know it supports a language (when you make the file localized) so any plist key value requests that exist already will be mapped to the appropriate value (depending on the current language).
Same applies for your xibs etc.
Personally, I use NSLocalizedString for strings generated inside the code and plists for resources, since it is easier to get the strings I need translated to the translators this way (Can't assume they can edit a plist).
Hope this helps
I've been searching for a definitive answer to this, and the XML schema data types document seems to suggest that timezones are accepted, yet I found at least one implementation which does not properly convert time zones ( NUSOAP ).
To make sure that the problem is not at my end, I'd like to know if a format such as 2009-11-05T11:53:22+02:00 is indeed valid and should be parsed with timezone information, i.e. as 2009-11-05T13:53:22.
Given the following sentences from the w3c schema documentation:
"Local" or untimezoned times are
presumed to be the time in the
timezone of some unspecified locality
as prescribed by the appropriate legal
authority;
and
When a timezone is added to a UTC
dateTime, the result is the date and
time "in that timezone".
it does not sound like there is a definitive answer to this. I would assume that it is the usual ambiguity: Both versions are principally valid, and the question of what version to use depends on the configuration/behavior/expectations of the system one is interfacing with.
And even if there where a definitive answer, I would definitely not rely on it, but rather expect that every other web service and library had its own way of dealing with this :/
You converted the timezone incorrectly.
2009-11-05T11:53:22+02:00
is equivalent to
2009-11-05T09:53:22Z
Is that what NUSOAP did?