<![CDATA[ What's the best way to use locale translation files with YAMS? - My Forums]]> https://forums.modx.com/thread/?thread=45635 <![CDATA[Re: What's the best way to use locale translation files with YAMS?]]> https://forums.modx.com/thread/45635/what-s-the-best-way-to-use-locale-translation-files-with-yams#dis-post-263972 thanks virtualgadjo for sharing]]> outre99 Aug 08, 2011, 08:44 AM https://forums.modx.com/thread/45635/what-s-the-best-way-to-use-locale-translation-files-with-yams#dis-post-263972 <![CDATA[Re: What's the best way to use locale translation files with YAMS?]]> https://forums.modx.com/thread/45635/what-s-the-best-way-to-use-locale-translation-files-with-yams#dis-post-263971
in order to work with lang files and yams i’ve written a little snippet called langfile
<?php
require( MODX_BASE_PATH . 'assets/snippets/langs/lang_'.$langId.'.php' );
return htmlentities($zilang[$text]);
?>

as you may have guessed have my lang files in a assets/snippets/langs directory, the langfile are called after YAMS langid, lang_fr.php, lang_en.php and so on

in the lang files i just set an array()
$zilang = array(); //not to conflict with a potential othe $lang var, but call it as you want :)


and then
$zilang['bonjour'] = "bonjour"; //in lang_fr.php
$zilang['bonjour'] = "hello";   //in lang_en.php


and, in the page, where you need it
[!langfile? &text=`bonjour` &langId=`(yams_id)`!]


though it may seem heavy to require the lang files many times in a page, honestly it is not as, being just an array to play with, php does this fingers in the nose smiley

i’ve tried other methods, for example using a snippet that parses the right lang file and then set placeholders for each word, of course, it seems smart as you only need to call the snippet once on top of the templates and then use [+bonjour+] in the body where needed but it is actually a bit heavier as you set a lot of placeholders you do not need when choosing an array index is really not memory gready

you could even write a plugin to do this onparsedocument but, once more, to my mind, it is heavier than a simple array parsing

have swing
]]>
virtualbear Aug 08, 2011, 04:24 AM https://forums.modx.com/thread/45635/what-s-the-best-way-to-use-locale-translation-files-with-yams#dis-post-263971
<![CDATA[What's the best way to use locale translation files with YAMS?]]> https://forums.modx.com/thread/45635/what-s-the-best-way-to-use-locale-translation-files-with-yams#dis-post-263970 I noticed that there’s a &get=`text` option but according to the manual the &from=`` should contain text itself not a path to a file. Also unfortunately Wiki leaves out the description of the proper syntax for the text.



]]>
outre99 Aug 08, 2011, 12:53 AM https://forums.modx.com/thread/45635/what-s-the-best-way-to-use-locale-translation-files-with-yams#dis-post-263970