MLXGet Text

(or mimo's language extension GetText)

(C) Michael Moritz mimo/at/

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.


That was easy, now the complicated bit.

  • In one of the 'early' views of your slice add this:

{mlx:addslice:(id of the slice you just created):Language:(some text to identify your MLXGetText domain):learn}


{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.

  • You should be ready to start using {_m:bla} in views etc.

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

  • Finally, once your site is finished and no further gettext translations need adding you should disable MLXGetText learning to imrpove performance. Example:


{mlx:addslice:3a0c44958b1c6ad697804cfdbccd8b09:EN:My Domain:learn}


{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:

  • Performance: having fewer items per domain improves performance and keeps tables small.
  • Confusion: You might have different translations for the same text in different sections of your site.

MLXGetText always sets the current domain to that you used in the last addslice command. In order to set a different domain use


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.