Localization in code

Richard A. O'Keefe ok at atlas.otago.ac.nz
Fri Sep 28 01:46:16 UTC 2001


"Andreas Raab" <Andreas.Raab at gmx.de> wrote:
	I've deliberately chosen my example of what I *don't* want to do because
	I've done localization on Windows and, man, it's a pain in the neck to have
	all these steps whenever you want to write some string that you eventually
	want to be localized:
	* define some name you can eventually remember (more often than not you
	can't)
	* perhaps even give it some numeric ID manually (haven't done any of that
	stuff recently so I don't know if MSVC and companions got any smarter in
	this respect)

There are a couple of ways that UNIX does/has done this:

	msg = catgets(Open_Message_Catalogue_Descriptor,
                      Message_Set_Number, Message_Number,
                      Default_String_To_Use_If_Not_Defined_In_Catalogue);

That's the kind of interface where you have to invent a number.

	msg = gettext(Default_Message_String);

is the kind of interface where you don't:  the default string is itself
all the identifier you need.  There is also

	msg = dgettext(Domain_Name, Default_Message_String);

where Default_Name is a string playing the same role as Message_Set_Number.

If I just had to consider UNIX, I would set up some kind of Locale class,
where
	Locale default	=> the "C" locale
	Locale native	=> same as what setlocale("") gives you
	Locale for: '<lang>[_<region>][.<char encoding>]'

	aLocale getText: 'Default Message String'
	aLocale getText: 'Default Message String' inDomain: 'Domain Name'
	aLocale domain	=> the name of the current domain
	aLocale domain: 'Domain Name'
and then I might whack getText: into Smalltalk with the definition
	getText: aString
	    ^Locale native getText: aString

Locale objects would also handle character classification, time and
date conversion, number and money formatting, following the GRASP "Expert"
pattern.

Then the first step of internationalisation would just be
to replace
	'Quit'
with
	Smalltalk getText: 'Quit'
and so on.

None of the C compilers I've used on MacOS, up to MacOS 8.6 (I've refused
an upgrade to 9.x), has supported C locales nontrivially.
What does MacOS X do?




More information about the Squeak-dev mailing list