Detecting french variations on OSX systems?

Objective is to have an applescript installer program auto-detect if the system uses any form of French. If yes then it displays a french menu, otherwise the menu is english.

I was looking at http://macscripter.net/viewtopic.php?id=19528

I am not sure how many variations of french systems there are for OSX. Unless I am mistaken, Canadian French uses CA. So should I include that as a possibility? Or will FR cater for all french variations?

In the installer presently I am testing:

do shell script "defaults read .GlobalPreferences AppleCollationOrder"
if result is "fr" then
	display dialog ("      QUITTEZ ...")
else
	display dialog ("CLOSE ...")
end if

Or should I use something like

do shell script "defaults read .GlobalPreferences AppleCollationOrder"
if result starts with "fr"
	display dialog ("      QUITTEZ ...")
else
	display dialog ("CLOSE ...")
end if

Edited to remove error.
For the past year I have provided a separate installer for each of english and french. Ideally only one would be needed. Of course I could use a choose language menu but I would prefer to keep menu steps to a minimum.

fr will do for all francais then. Excellent!

Many thanks Tom :slight_smile:

Hello

I’m puzzled because on my French system (10.8.2),
do shell script “defaults read .GlobalPreferences AppleCollationOrder”
returns “root”.

For years I use :


do shell script "defaults read 'Apple Global Domain' AppleLocale"
if result starts with "fr_" then
	display dialog "Le système parle français"
else if result starts with "en" then
	display dialog "The system speaks English"
else
	"Oops, I don't know the "" & result & "" language"
end if

Yvan KOENIG (VALLAURIS, France) dimanche 25 novembre 2012 10:48:59

In the Language tab of the “Language & Text” preferences, there’s a pop-up menu called “Order for sorted lists:” (Obviously I’m using the English terms here.) If this is set to “Standard”, ‘do shell script “defaults read .GlobalPreferences AppleCollationOrder”’ returns “root”, otherwise it returns the language code for the sort language selected.

Which one should I use then?

Will the

do shell script "defaults read 'Apple Global Domain' AppleLocale"

work on all OSX versions?

Does my version have an issue with OSX 10.8 or with system language settings?

Edit: the applelocale version looks more reliable, according to Nigel Garvey’s response.

Our Francais moderator from France tested out the previous version and it worked on his system. I think he is using OSX 10.4 and 10.5. But we do have both members and users from Quebec and possibly also other countries such as in northern Africa and other places in the world whom might use Francais.

Perhaps use the AppleCollationOrder as the ‘else’ in Yvan Koenig’s version?

In all probability for sake of practicality I would use english if the system language cannot be detected.

Thanks everyone for their input into the topic above. :slight_smile:

If you only want to know if the user’s currently preferred first language is “any form of French”, I think this should do it:

set SystemLanguage to do shell script "defaults read .GlobalPreferences AppleLanguages | sed -En '/[a-z]{2}/ {s/^[^a-z]*([a-z]{2}).*$/\\1/p ; q ; }'"

It’s the GlobalPrefences script from the other thread with some “sed” to parse out the main, two-letter, lower-case language code. It returns “fr” with Canadian French.

Thanks Nigel :slight_smile: I had just minutes ago sent the French moderator a version with Yvan Koenig’s approach to test, but I will send him this version also. :smiley: All 3 in this thread have worked on my system. Thanks to Yvan for pointing out an unreliability with the first approach. Both of you I mean.

The sed approach works fine for the first menu but last menu is in english. :smiley:
I tested it to with en instead of fr and same thing.
The french moderator said the 2nd method worked fine.

I’ve no idea what you mean by any of that, but I’m glad you’ve got something that works for you. :slight_smile:

On a system running French from France, the locale is fr_FR.
It’s why in my code I test upon “fr_”.
If French from Canada returnf fr, the test must be changed to test only upon “fr”.

On a machine delivered in france, French from France is the standard setting.
This may explain why the collation pref returns root.

Is one of you able to tell were we may grab the list of available locale strings ?
I saw it once but forgot it.

Yvan KOENIG (VALLAURIS, France) lundi 26 novembre 2012 15:42:36

If I set “Français canadien” as my first preferred language in System Preferences, “defaults read .GlobalPreferences AppleLanguages” returns a text list of language codes, the first of which is “fr-CA” (with a dash), but “defaults read .GlobalPreferences AppleLocale” continues to return “en_GB” (with an underscore). Maybe the latter responds to some other setting or to a log-out, but I don’t want to fool around with either of these today as the computer’s doing other work.

Edit: After a bit of googling, it appears that “locale” refers to the “Formats” settings in the Language & Text preferences.

(1) Here AppleLanguages display :

fr, en, de, es-ES, it

(2) In IntlLanguages.prefpane, there is a resource embedding :

// we are not using politically correct alphabetical order in English
// except for English anymore.

// this is now marketing requested “marketing order” for tier 0, 1, and 2.

// tier 0 and 1 languages
// “English”, “Japanese”, “French”, “German”, “Spanish”, “Italian”, “Dutch”, “Simplified Chinese”
// “en”, “ja”, “fr”, “de”, “es”, “it”, “nl”, “zh-Hans”

// tier 2 languages
// “Portuguese”, “Swedish”, “Norwegian”, “Danish”, “Finnish”, “Korean”, “Traditional Chinese”, Portuguese (Brazil), Portugues (Portugal), Russian, Polish
// “pt”, “sv”, “nb”, “da”, “fi”, “ko”, “zh-Hant”, “pt-BR”, “pt-PT”, “ru”, “pl”

// tier 3 languages
// “Bulgarian”, “Ukrainian”, “Czech”, “Slovak”, “Hungarian”, “Thai”, “Arabic”, “Hebrew”, “Greek”, “Icelandic”, “Romanian”, “Turkish”
// “bg”, “uk”, “cs”, “sk”, “hu”, “th”, “ar”, “he”, “el”, “is”, “ro”, “tr”

(
“en”, “ja”, “fr”, “de”, “es”, “it”, “nl”,
“sv”, “nb”, “da”, “fi”, “pt”, “zh-Hans”, “zh-Hant”, “ko”, “ru”, “pl”, “pt-PT”,
“bg”, “uk”, “cs”, “sk”, “hu”, “th”, “ar”, “he”, “el”, “is”, “ro”, “tr”, “pt-BR”

)

As you may see, no fr_FR and no fr-CA so there must be an other resource somewhere.

Yvan KOENIG (VALLAURIS, France) lundi 26 novembre 2012 17:51:39

do shell script "cd /usr/share/locale ; ls -1 |  open -fg ; open -b \"com.apple.textedit\""

Indeed the key AppleLocale represents the current “Formats” settings,
AppleLanguages represents the language list in “Language” settings, current language on top,
and AppleCollationOrder represents the popup menu “Order for sorted lists” in “Language” settings (Standard = current language)

Edit: Returning from MacSedScripter to MacScripter :wink:


property requestedLanguage : "fr"

set globalPrefFilePath to (path to preferences folder as text) & ".GlobalPreferences.plist"
tell application "System Events"
	set globalPrefFile to property list file globalPrefFilePath
	set appleLanguages to value of property list item "AppleLanguages" of contents of globalPrefFile
end tell
set requestedLanguageIsAvailable to requestedLanguage is in appleLanguages


Nigel, my ‘dumb’ mistake with using your script was I put


If result starts with "fr_"

It works fine by just specifying

if result is "fr"

I have a test account and changed it to french-canadian. Your script worked fine on both menus. So did Yvan’s approach.

Edited to add ‘dumb’. :smiley:

Or maybe:

do shell script "locale -a | open -fg ; open -b \"com.apple.textedit\""

It produces a very slightly different result.

:wink:

Yes, I just showed the data foundation, the locale command, is very worth looking into. Thanks.

I’ts ideal for sed :wink:

This is interesting if one wants to explore the locales, if you don’t want to explore en_GB, just change the value to something else. :slight_smile:

do shell script "export LC_ALL=en_GB.UTF-8 ; locale -ck LC_ALL  | open -fg ; open -b \"com.apple.textedit\""
script aScript
	set a to current application's NSLocale's availableLocaleIdentifiers() as list
	set b to current application's NSLocale's preferredLanguages() as list
	set c to current application's NSLocale's componentsFromLocaleIdentifier_("fr-CA") as list
	set d to current application's NSLocale's componentsFromLocaleIdentifier_("fr") as list
	return {a, b, c, d}
end script

tell application id "au.com.myriad-com.ASObjC-Runner" -- ASObjC Runner.app
	run the script {aScript} with response
end tell

This might explain things a bit better:

developer.apple.com/library/mac/#documentation/CoreFoundation/Conceptual/CFLocales/Articles/CFLocaleConcepts.html