Maketext library

Colin Putney cputney at wiresong.ca
Mon Oct 15 21:27:27 UTC 2007


On Oct 15, 2007, at 1:53 AM, Bert Freudenberg wrote:

> It's not entirely bogus. But gettext has been extended to handle  
> these cases, see above. I guess the one case that it cannot handle  
> is if you have two numerals in the same phrase. Which can certainly  
> be worked around with by splitting the phrase in two.

I recently did some work to localize Dabble to Spanish. I started  
with the simplest possible thing and gradually added features to  
accomodate the situations I ran into. The result is not all that  
different from gettext or maketext (though I'm not intimately  
familiar with those libraries).

Briefly, it works like this:

Each language has a class, and each translation is a method on that  
class. Most of those methods just answer a string literal, but some  
answer a Phrase, which has methods for filing in parameters to the  
phrase or customizing the way it gets printed on a stream or rendered  
as HTML.

On top of that, there's a bit of infrastructure for creating  
translations easily. There's a TranslationBrowser built on  
OmniBrowser, and some code for compiling templates in to Smalltalk  
that returns a Phrase.


As you can see, it also allows different translations for plurals,  
with each language specifying which plural forms it has to support.  
We don't support more than one plural per phrase, and so far it  
hasn't been an issue. That could be just an oddity of Dabble's UI  
design, though.

The classic example would be something like this. Let say the phrase  
is '{bold:Alert!} We found {count} files.' We might render it in  
Seaside something like this:

renderFilesFoundOn: html
	(self language filesFound: 3)
		render: #bold with: [:text | html strong: text];
		renderOn: html

That would produce '<strong>Alert!</strong> We found 3 files.'

Or it could be printed to a stream:

printFilesFoundOn: aStream
	(self language filesFound: 3)
		print: #bold with: [:text | aStream nextPut: $*; nextPutAll: text;  
nextPut: $*];
		printOn: aStream]

Producing '*Alert!* We found 3 files'

To also report the number of directories, you'd have to combine two  
plural translations, embedding one inside the other:

(self language foundDirectoriesWithFiles: 3)
	set: #directories to: (self language directoriesFound: 2);
	printOn: aStream

All in all, it works reasonably well, and makes localization less  
painful, though not completely painless. It's pretty easy to  
implement, really.

Colin
-------------- next part --------------
Skipped content of type multipart/related


More information about the Squeak-dev mailing list