(or mimo's language extension GetText)
(C) Michael Moritz mimo/at/restoel.net
MLX Screenshots also has some screenshots for MLXGetText
This is a AA database driven gettext that allows to translate short strings (with parameters) similiar to GNU gettext. Nice about it is that it allows to edit translations in AA admin interface and secondly that it can automatically add items for unknown texts -- it can be trained.
Create a slice to hold the short texts
I have made a screen shot of what this should look like:
http://mimo.gn.apc.org/mlx-screenshots/46_mlxGetText_translations_slice_fields.png.
That was easy, now the complicated bit.
{mlx:addslice:(id of the slice you just created):Language:(some text to identify your MLXGetText domain):learn}
e.g. {mlx:addslice:3a0c44958b1c6ad697804cfdbccd8b09:EN:My Domain:learn}
'early' means that this has to be parsed by AA before {_m gets first used. It's probably worth creating an extra view just to make sure this is the case. I have noticed that if it is in the same view but before the first {_m it can still be parsed after the {_m. It will not work in this case. You can use ?errcheck=1 to check for these errors.
Note that you can add more than one slice containing translations to a domain. This is a nice feature as you can piece together subsections if needed. If you use more than one slice for translations and MLXGetText is set to learn new items will be added to the last slice added to the current domain.
It goes like this: once you use {_m:some text} MLX will automatically add an item to the slice. You can then edit the translations in AA admin. MLX makes sure it doesnt get added twice or overwritten. Using the MLX view parameter, MLXGetText will figure out which translation is available and print it accordingly. So in a view that has e.g. ?vid=11&set[11]=mlx-DE MLXGetText will automatically use the German translation from your translations slice if available.
Additional features:
MLXGetText supports unlimited number of parameters in strings. This goes like:
{_m:Today's date is %1.%2.%3:5.11.2004}
will print (in EN)
Today's date is 5.11.2004
in DE it will print
Das heutige Datum ist 5.11.2004
Change
{mlx:addslice:3a0c44958b1c6ad697804cfdbccd8b09:EN:My Domain:learn}
to:
{mlx:addslice:3a0c44958b1c6ad697804cfdbccd8b09:EN:My Domain}
You can use MLXGetText without domains. In that case the domain name will be 'global' for everything. To allow MLXGetText to 'learn' items use {mlx:addslice:slice id:EN:global:learn}
The concept of using domains in MLXGetText has two advantages:
MLXGetText always sets the current domain to that you used in the last addslice command. In order to set a different domain use
{mlx:setdomain:domain}
Note that this has similiar 'problems' to what I explained under 'early' above.
As usual, MLX is untested and I would appreciate any feedback.
Thanks to Honza who already programmed something very similiar before and gave me all of his code and Marek for discussing the idea with him in Cape Town.
Last edited on Friday 5 November 2004 18:24:13.
lib/pear/DB/common.php:741: Notice[8]: Only variable references should be returned by reference
lib/DB_Session.php:148: Notice[8]: Only variables should be assigned by reference
lib/pear/DB/common.php:741: Notice[8]: Only variable references should be returned by reference
lib/WikiUser.php:77: Notice[8]: Only variables should be assigned by reference
lib/pear/DB/common.php:741: Notice[8]: Only variable references should be returned by reference
lib/pear/DB/common.php:741: Notice[8]: Only variable references should be returned by reference
lib/pear/DB/common.php:741: Notice[8]: Only variable references should be returned by reference
lib/pear/DB/common.php:741: Notice[8]: Only variable references should be returned by reference
lib/Template.php:120: Notice[8]: Only variables should be assigned by reference
lib/Template.php:122: Notice[8]: Only variables should be assigned by reference
lib/Template.php (In template 'html'):120: Notice[8]: Only variables should be assigned by reference
lib/Template.php (In template 'html'):122: Notice[8]: Only variables should be assigned by reference
lib/Template.php (In template 'html'):120: Notice[8]: Only variables should be assigned by reference
lib/Template.php (In template 'html'):122: Notice[8]: Only variables should be assigned by reference
lib/Template.php (In template 'body') (In template 'html'):120: Notice[8]: Only variables should be assigned by reference
lib/Template.php (In template 'body') (In template 'html'):122: Notice[8]: Only variables should be assigned by reference
lib/Template.php (In template 'top') (In template 'body') (In template 'html'):120: Notice[8]: Only variables should be assigned by reference
lib/Template.php (In template 'top') (In template 'body') (In template 'html'):122: Notice[8]: Only variables should be assigned by reference
lib/Template.php (In template 'body') (In template 'html'):120: Notice[8]: Only variables should be assigned by reference
lib/Template.php (In template 'body') (In template 'html'):122: Notice[8]: Only variables should be assigned by reference
lib/pear/DB/common.php (In template 'navbar') (In template 'body') (In template 'html'):741: Notice[8]: Only variable references should be returned by reference
lib/Template.php (In template 'body') (In template 'html'):120: Notice[8]: Only variables should be assigned by reference
lib/Template.php (In template 'body') (In template 'html'):122: Notice[8]: Only variables should be assigned by reference
lib/pear/DB/common.php (In template 'browse') (In template 'body') (In template 'html'):741: Notice[8]: Only variable references should be returned by reference
lib/Template.php (In template 'body') (In template 'html'):120: Notice[8]: Only variables should be assigned by reference
lib/Template.php (In template 'body') (In template 'html'):122: Notice[8]: Only variables should be assigned by reference