First, if you possibly can, use
CFBundleCopyPreferredLocalizationsFromArray(), available on CarbonLib
1.1 and all versions of Mac OS X. It will handle the preference
fetching and canonicalization for you. It should work for almost all
reasons that people use AppleLanguages. Note that your application
does *not* need to be bundled to use
CFBundleCopyPreferredLocalizationsFromArray. It should work in any
Carbon application.
If you can't use this API, write to me and I'll try to figure out a
way you can. :-) But if you really can't, then you'll need to
canonicalize the language strings before comparing them. The issues are:
1. Before Apple standardized on ISO language tagging, we used legacy
codes like "English" and "Japanese". These need to be converted to
the appropriate ISO code ("en" and "ja" for these two examples).
This alignment is planned for a future release of Mac OS X, and will
affect some existing language tags. Namely:
Old tag New tag
zh_CN zh-Hans (Simplified Chinese is used
elsewhere than China; it is not the "P.R.C. dialect of Chinese")
zh_TW zh-Hant (Traditional Chinese is used
elsewhere than Taiwan; it is not the "Taiwan dialect of Chinese")
no nb (no is ambiguous and deprecated by
ISO; it can mean either nb or nn)
The first two were a stopgap because an official way of expressing
the difference between Simplified and Traditional Chinese was not
available at the time Mac OS X was initially released. Also, in
keeping with 3066bis, dialect versions of languages like British
English will use hyphens rather than underscores, e.g. en-GB instead
of en_GB.
For applications, the following is available:
Prior to Mac OS X 10.3: There is no API. You will need to implement
canonicalization on your own, using a table.
Mac OS X 10.3 or later: There is
CFLocaleCreateCanonicalLocaleIdentifierFromString. This will
canonicalize a locale ID This is not quite the same thing as a
language tag, though they use the same codes. The reason is that the
canonical form of language and locale IDs differ. On 10.3, they
happen to be the same, so you're safe using this API on 10.3. Your
code may not work when we make the canonicalization changes mentioned
under 2. above. You will need to handle those manually. Also, you
should treat hyphen (-) and underscore (_) as identical when
matching, to protect against the other canonicalization change.
Future release: We plan to introduce another API that is specifically
for canonicalizing language tags. This will do everything correctly,
when it is available.
In addition to canonicalization issues, you also need to worry about
handling dialect requests. For example, if the user requests en but
only en-GB is available, or vice versa. This has to be done carefully
as you do not want to substitute zh-Hant for zh-Hans, for example.
I hope you can now see why I am concerned about applications
accessing AppleLanguages directly. I again urge you to use
CFBundleCopyPreferredLocalizationsFromArray (or
CFBundleCopyLocalizationsForPreferences on 10.2 or later) if you can.
They will protect you from all of this.
Deborah Goldsmith
Internationalization, Unicode liaison
Apple Computer, Inc.
email@hidden
On Mar 8, 2005, at 9:39 AM, Deborah Goldsmith wrote:
Urgh. I wasn't aware it had actually been documented. That wouldn't
have been my preference (no pun intended).
OK, well, I guess it *is* supported, but you still need to worry
about canonicalization. I will try to note a "best practices"
approach in a reply later today.
Deborah Goldsmith
Internationalization, Unicode Liaison
Apple Computer, Inc.
email@hidden
On Mar 7, 2005, at 11:44 PM, Alexey Proskuryakov wrote:
On Mon, 7 Mar 2005 15:38:59 -0800 Deborah Goldsmith
<email@hidden> wrote:
On Mar 7, 2005, at 6:28 AM, Takehiko Abe wrote:
CFPreferencesCopyValue with the key "AppleLanguages"
I have to warn you: this preference is not documented and Apple
does not support this officially. I would not rank it high on a
list of risks, but I had to say it.
It appears in official documentation several times:
"You can programmatically retrieve the array of language
preferences from System Preferences using the key AppleLanguages"
- WBR, Alexey Proskuryakov
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden