More ideas for translation support (long)

From: Date: Thu, 19 Jul 2001 09:00:14 +0000
Subject: More ideas for translation support (long)
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-1196@lists.php.net to get a copy of this message
Hi, as reported previously, I use config strings ( {#....#} ) to support translation. My templates [1] load a different config file for each language. I assign a variable $LANG and load config file="$LANG.inc" (I actually have several config files per language, to keep them small enough). This works well, except: - config strings are one liners, difficult for long text, I use language specific templates when I have to - language strings can't contain smarty variables, I can't do "Please contact {$EMAIL} for support" in several languages. So I was thinking of doing it another way and wanted so feedback before I got going: I'll add a template resource 'lang' using 'register_resource'. Then I access templates using 'file="lang:$LANG.foo.tpl"' In the resource handler, I strip the first part of the template name to get the requested language (I need to do it this way since I can't pass parameters to the resource handler). I use what is left to get the actual template file from somewhere. Then, I can translate that file using which ever Smarty independant method I want. I would probably build a map of token to string conversions, define a syntax to embed tokens in the templates (like {%alangstring%}) and use strtr() to convert the tokens to actual strings. Then I return the result to Smarty so it can compile it. What I like about this way of doing: - translated templates would compiled to different versions, so translation would have only compile time overhead [2] instead of having to do all the {#...#} translation each time the page is displayed - since we do the translation before compiling, translated strings can contain smarty variables or artibrary smarty template code - I have total freedom on what to put in translated strings, I am no longer limited to one liners - I have total freedom on how I do the translations, it is totally independant of Smarty [3] - you can mix languages: {include file="en.foo.tpl"} {include file="de.foo.tpl"} would show the same content in two languages What do you think? Does this sound reasonable? Regards, Mike Krus [1] http://www.newsisfree.com/ [2] to tell Smarty whether to recompile the template or not,
    I would set the time stamp to the most recent modification
    date of the base template and the language string table.
[3] provided it doesn't mungle the text too much, and if I
    wanted a good laugh, I could probably use an XML-RPC
    or SOAP webservice to do the translation automatically
    using Babel fish or whatever... See:
    http://www.salcentral.com/asp/srch.asp?SRCH=translation


« previous php.smarty.general (#1196) next »