Detect language - I am getting crazy...

Hi Folks,

I am getting crazy when I try to check the language of the system the user is using…


	set processor to system attribute "sysa"
	
	
	if processor is 2 then
		
		--Sprache herausfinden
		display dialog "You are having a PPC"
		set x to (do shell script "defaults read .GlobalPreferences AppleLanguages")
		set theString to x
		set languages_new to (characters 2 thru 3 of theString) as string
		set language_akt to languages_new
		display dialog language_akt
		
	else if processor is 10 then
		display dialog "You are having an Intel"
		set x to (do shell script "defaults read com.apple.dock loc")
		set theString to x
		set languages_new to (characters 1 thru 2 of theString) as string
		set language_akt to languages_new
		display dialog language_akt
	end if

On my Ibook the 2 is working, on another Intel (Macbook Pro) the 10 is working - and on another Intel (Macbook Pro) the 10 is not working… All machines are running on 10.4.8…

Please can you check the code on your machines and tell me where it is working and where not…

Thanks a lot,

Stefan

Perhaps one of these will help:


set hardware_descr to do shell script "system_profiler SPHardwareDataType | grep 'Model' | cut -c 22-"
set machine_hw_name to do shell script "uname -m"

Hi Adam,

thanks a lot - but is my script running on your machine?

thanks for your input…

Best regards,

Stefan

Hi, Stefan

try this:

set SystemLanguage to do shell script "defaults read .GlobalPreferences AppleCollationOrder"

it should work on Tiger machines

Hi Adam,

retrieving “sysa” is a good and working way to get the Processor type

from /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/Headers/Gestalt.h
enum {
gestaltSysArchitecture = ‘sysa’, /* Native System Architecture /
gestalt68k = 1, /
Motorola MC68k architecture /
gestaltPowerPC = 2, /
IBM PowerPC architecture /
gestaltIntel = 10 /
Intel x86 architecture */
};

Hi Stefan,

thanks a lot - it works on my ppc - but it is also working on an intel?

I have to check tomorrow at work, because at home I have an intel free zone…

Thanks and best regards,

Stefan

Hi Stefan,

this is not working on my Intel…


set SystemLanguage to do shell script "defaults read .GlobalPreferences AppleCollationOrder"

Is there a possibility to check more methods - something like this:


if processor is 2 then
       try 
       --Sprache herausfinden
       display dialog "You are having a PPC"
       set x to (do shell script "defaults read .GlobalPreferences AppleLanguages")
       set theString to x
       set languages_new to (characters 2 thru 3 of theString) as string
       set language_akt to languages_new
       display dialog language_akt
       on error

       set SystemLanguage to do shell script "defaults read .GlobalPreferences AppleCollationOrder"
    
   
       end try
       
   else if processor is 10 then

      try
       display dialog "You are having an Intel"
       set x to (do shell script "defaults read com.apple.dock loc")
       set theString to x
       set languages_new to (characters 1 thru 2 of theString) as string
       set language_akt to languages_new
       display dialog language_akt

      on error

      set SystemLanguage to do shell script "defaults read .GlobalPreferences AppleCollationOrder"


      end try
   end if



Side note: Do this instead:

set languages_new to text 2 thru 3 of theString

Hi Folks,

now I need a doctor…


set x to do shell script "defaults read com.apple.dock loc"

which is not running on my ppc (10.4.8) runs on a ibook 10.4.6…

and


set x to do shell script "defaults read .GlobalPreferences AppleLanguages"

which runs on my ppc is not running on the ibook


set x to do shell script "defaults read .GlobalPreferences AppleCollationOrder"

is not running on that ibook…

A fantastic phenomen…

Hi Folks,

I have upgraded the Ibook (G3) to 10.4.8 and now the


set x to do shell script "defaults read .GlobalPreferences AppleLanguages"

is working…

but


set x to do shell script "defaults read .GlobalPreferences AppleCollationOrder"

is not running on this G3 Ibook, but is running on my G4 Ibook…

Best Regards,

Stefan

Hi Folks,

now I trying this - could you please tell me, wheter this is a good solution?



if processor is 2 then

try set x to (do shell script "defaults read .GlobalPreferences AppleLanguages")
on error
  try 
   set x to do shell script "defaults read .GlobalPreferences AppleCollationOrder")
  on error
   set x to do shell script "defaults read com.apple.dock.loc"
  end try
end try

else if ....


Thanks for your help…

Stefan

Hello

It seems that there where some typos.
For me this one works:



try
	set x to text 2 thru 3 of (do shell script "defaults read .GlobalPreferences AppleLanguages")
on error
	try
		set x to do shell script "defaults read .GlobalPreferences AppleCollationOrder"
	on error
		set x to text 1 thru 2 of (do shell script "defaults read com.apple.dock.loc")
	end try
end try

In fact the three are working on my G5 under 10.4.8

I extract two chars so that the result is the same for every line of code: “fr” here.

Yvan KOENIG (from FRANCE vendredi 23 février 2007 16:00:07)

Hi,

I tried a few things on Jaguar, Panther and Tiger (on a PPC machine)

on my machine in all system versions the current selected language will be retrieved with

set Language to word 1 of (do shell script "defaults read .GlobalPreferences AppleLanguages")

but: in Jaguar and Panther, the result is “English” or “French” or “German” or others
in Tiger the result is “en” or “fr” or “de” or others

I haven’t read this thread carefully so forgive me if I’m repeating, but doesn’t this present an alternative:

property language : user locale of (system info)

user locale contains the language which has been chosen during a system installation process.
It doesn’t change when you change the language setting in the International pane

Hi Stefan,

on another Ibook (G4, 10.4.8) when I am using our script I get:

Can’t set language to word 1 of (do shell script “defaults read .GlobalPreferences AppleLanguages”). Access not allowed.

I thought that all Apples are similar, but it looks like that they are different…

Best Regards,

Stefan

The error message shows that you can not use the (key)word »Language«. Rename to »myLanguage« for a valid variable name and it works perfect:

tell application "System Events"
	set myLanguage to word 1 of ¬
		(do shell script "defaults read .GlobalPreferences AppleLanguages")
	if (myLanguage is in {"de", "German", "Deutsch"}) then
		set LANG to 1
	else
		set LANG to 2
	end if
end tell

Cheers
Tobias