Sep172009

LanguageChunk

I’m in Cameroon working on some multi-lingual web design projects using MODx. I will post the things I’ve learned here as the MODx wiki is a little tough to deal with.

I followed aceman3000’s very helpful tutorial to put together some basic multilingual support. I needed some way to automatically spit out different chunks depending on the language. That is, I have different chunks with suffixes on the name corresponding to the ISO two letter country code for the language (ie Sidebar_gb, Sidebar_fr, Sidebar_de). I created the following snippet to figure out the current language from the UltimateParent and then spit out the correct snippet. The following code assumes that the UltimateParent has an alias that is the ISO two letter country code.

<?php
//Make sure we got a chunk passed into us, otherwise return
if(!isset($name)){ return; }
//Get id for top parent
$up = $modx->runSnippet("UltimateParent");
//get the alias for that id
//echo $up;
$document=$modx->getDocument($up);
$alias=$document['alias'];
//Append alias to chunk
$name .= '_'.$alias;
//Output chunk
echo $modx->getChunk($name);
?>

To use this snippet, call it with the base name of chunk you want to output. Following the previous example of Sidebar_gb, Sidebar_fr etc you would call this snippet with:

[[LanguageChunk? &name=`Sidebar`]]

I hope this helps someone!

Write a comment


Comment sfkcgjc on : Mon March 29, 2010, 12:28:41
dPAmir <a href="http://cdciijjwwgxy.com/">cdciijjwwgxy</a>, [url=http://nfhthdbnbcjt.com/]nfhthdbnbcjt[/url], [link=http://vxosjngoakzl.com/]vxosjngoakzl[/link], http://auvktmwqrmhu.com/
Comment gkheityfqpu on : Thu January 14, 2010, 23:59:06
9gVBVA <a href="http://pllxhacxgnst.com/">pllxhacxgnst</a>, [url=http://gmskpcdqyssj.com/]gmskpcdqyssj[/url], [link=http://hgpprxpbwcgp.com/]hgpprxpbwcgp[/link], http://wpusgsyghelg.com/
Comment mqqlbjiopo on : Wed January 06, 2010, 07:55:20
z9YL5S <a href="http://syxdapknxppu.com/">syxdapknxppu</a>, [url=http://xbuqgngwmbye.com/]xbuqgngwmbye[/url], [link=http://tqcrukqhfzcg.com/]tqcrukqhfzcg[/link], http://juejengxujdg.com/