svn:/site/Views/Snippets - Give me the current language 2letter code for the template localization, requires UltimateParent * * Required snippets: UltimateParent * * @author Renoir Boulanger * @date 2008-06-25 * * 1. Very the config * 2. Add [[Lang]] snipet call where you need to know what's the current language.! **/ /** * IMPORTANT * 1. Check the acceptable languages * (search for 1.0 ) * 2. Check the MODx container, generally it is 'pagetitle' * (search for 1.1 ) * 3. Check for your preffered "default" language * (search for 1.2 ) **/ /** * 1.0 The acceptables languages * ARRAY of acceptable lang in two letter codes format **/ $acceptableLanguages = array( 'en', 'fr' ); /** * 1.1 The MODx container * it will provide a two letter code title container... should be "pagetitle" * or anywhere you could had put it in your contents page of your top level * container * * NOTE: You MUST have at the root your current content duplicated in each * languages respect with their own two letter languages. */ $selector = 'pagetitle'; /** * 1.2 Default lang **/ $defaultLang = 'fr'; /* ****** /Some config ****** */ /* ************** End of configuration, start the actual plugin **************** */ $lStrDocId = ($docid) ? $docid : false; $id = $modx->runSnippet("UltimateParent"); /** * Get absolute parent page (aka, the Lang!!) * Source: http://wiki.modxcms.com/index.php/API:getPageInfo * array = getPageInfo($pageid= -1, $active= 1, $fields= 'id, pagetitle, description, alias'); **/ $getPagetitle = $modx->getPageInfo($id,0,$selector); $lang = $getPagetitle[$selector]; $lang = ( in_array($lang, $acceptableLanguages) ) ? $lang : $defaultLang; //echo 'Lang:'.$lang.' / vs acceptablesLanguages'."\n"; //print_r($acceptableLanguages); //var_dump( in_array($lang, $acceptableLanguages) ); return( trim($lang) ); ?>