
/*
**      Newton Developer Technical Support Sample Code
**
**      CreatingALocale  -  Changing the Newton's locale to 24 hour
**                          and making day & month lower case
**
**      by Henry Cate, Newton Developer Technical Support
**
**      Copyright © 1996 by Apple Computer, Inc.  All rights reserved.
**
**      You may incorporate this sample code into your applications without
**      restriction.  This sample code has been provided "AS IS" and the
**      responsibility for its operation is 100% yours.  You are not
**      permitted to modify and redistribute the source as "DTS Sample Code."
**      If you are going to re-distribute the source, we require that you
**      make it clear in the source that the code was descended from
**      Apple-provided sample code, but that you've made changes.
**
**
**      This creates a locale bundle which changes the time format
**      to 24 hour format, and makes the day of the week & month of the
**      year appear appear in lower case text.
**
**      Check the Newton Programmer's Guide for more information about locales
**      and check the article "Newton still needs the card you removed." for
**      more information about how to handle the card being pulled problem
*/

constant kLocaleName := "MyLocale:PIEDTS";


InstallScript :=
func(partFrame, removeFrame)
begin 
	// Get the current locale bundle, so if this is deleted 
	// we can restore to the previous locale
	local currentLocale := GetLocale();
	local newLocale := EnsureInternal ( {	// Have as internal so can survive card removal 
		_proto: nil,						// Create the slot name internal
		title: kLocaleName,					// Have to be internal, when do RemoveLocale, check for title match
		timeFormat: {
			_proto: nil,	
			timeCycle: kCycle24,			// change to 24 hour cycle
			},
		longDateFormat:{
			_proto: nil,
			longDofWeek: ["sunday", "monday", "tuesday", "wednesday", "thrusday", "friday", "saturday"],
			abbrDofWeek: ["sun", "mon", "tue", "wed", "thr", "fri", "sat"],
			terseDofWeek: ["su", "mo", "tu", "we", "th", "fr", "sa"],
			shortDofWeek: ["s", "m", "t", "w", "t", "f", "s"],
			longMonth: ["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"],
			abbrMonth: ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"],
			},
		});
		
	// Set proto's so get the built-in system slots and all the defaults
	newLocale._proto := currentLocale;		
	newLocale.timeFormat._proto := currentLocale.timeFormat;	
	newLocale.longDateFormat._proto := currentLocale.longDateFormat;
		
	// Done creating the locale, so add it to the system collection, then set	
	call kAddLocaleFunc with (newLocale);	
	SetLocale(kLocaleName);			
	
	// Do EnsureInternal so if the card gets pulled, can clean up gracefully 
	removeFrame.(EnsureInternal('OldLocaleTitle)) := EnsureInternal(currentLocale.title);
end;

RemoveScript :=
func(removeFrame)
begin
 	SetLocale (removeFrame.OldLocaleTitle); 	
 	// If the OldLocale is no available, RemoveLocale will 
 	// pick the first built-in locale 
 	call kRemoveLocaleFunc with (kLocaleName);	 
end;