Re: Localized Internals of AppleScript (date Class for example)
Re: Localized Internals of AppleScript (date Class for example)
- Subject: Re: Localized Internals of AppleScript (date Class for example)
- From: has <email@hidden>
- Date: Fri, 15 Apr 2005 18:34:33 +0100
Emile Schwarz wrote:
>The AppleScript Language Reference pdf I use date from 1996;
Current version is dated May 1999.
>There is a difference between the way to set the date (French) and the way to get the date constants back (English) and I do that in the same script, a two lines script.
Hard truth: AppleScript's localisation support is a weak and ill-conceived mess. While it might sound good in theory, having localised date strings as the sole method of constructing date objects is a really bad idea in practice, due to all the portability and reliability problems it causes.
A saner language would take a much simpler approach that's completely independent of system settings, like supplying a command that takes a list of numbers representing year, month, day, hour, etc.; e.g. date(2005, 4, 15, 17, 41). It would also provide additional commands for performing complex tasks like parsing and formatting localised date strings with much greater flexibility and user-control.
Unfortunately, AppleScript tries to pretend that all these complex, messy issues don't exist, and in trying to hide them from users just ends up causing all sorts of new problems as well. It's just something you have to deal with, or else find yourself a better language to work in.
>Of course, I do not use Mac OS X like the domestic users do: I use the French language thus French setting, but why the US constants ?
Because AppleScript, like the great majority of programming languages, uses an English-based syntax. Consider it an accident of history.
>If the Language is able to do one part why not the second part ?
Because AppleScript language structures are not data, and vice-versa. Localising language keywords would mean changing the language itself, which is a non-trivial task and has all sorts of implications for code portability. [1]
Anyway, I'm going to skip the longer rant and just suggest you go try AppleMods' Date library <http://applemods.sourceforge.net/mods/Data/Date.php> for working with dates. It's reasonably powerful, well documented and easy to use, and will probably do for your needs. Examples:
-- [library loading code omitted for clarity]
_Date's recordToDate({year:2005, month:4, day:14})
--> date "jeudi 14 avril 2005 0:00:00"
_Date's dateToRecord(date "jeudi 14 avril 2005 0:00:00")
--> {weekday:Thursday, day:14, month:April, year:2005, hours:0, minutes:0, seconds:0}
_Date's monthToInteger(April)
--> 4
set q to _Date's makeParserForLanguage("dddd dd mmmm yyyy, hh:MM:SS tt (z)", "French")
q's parseText("Mardi 30 mai 2000, 03:30:00 am (+0200)")
--> {date "Tuesday, May 30, 2000 3:30:00 am", 7200}
set f to _Date's makeFormatterForLanguage("mmmm", "French")
f's currentDate()
--> "avril"
If you've not used AppleMods' libraries before, you'll need to download and install AppleMods' Loader system first <http://applemods.sourceforge.net/getstarted.html>. Run the Loader installer, then download and add the Date library to the ASLibraries folder. You can use the LoaderWizard applet to generate the library loading code to paste at the top of your script.
HTH
has
[1] In fact, AppleScript was originally designed to support multiple syntaxes - French, German, Japanese, C-style, etc. - but this feature was dropped early on, due (IIRC) to the high cost of localising not just the AppleScript language but the terminology resources of every scriptable application as well.
--
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden