Joomla template creation, Joom!Fish language detection.
February 19th, 2007 by
ltz
Creating a Joomla template might be rather simple, when involving different languages on the text-level it all seems simple aswell. However when we want 100% of our website to change language when we swith languages, this requires a workaround. The Joom!fish component is very powerful, however you control 95% of the website content from Joom!fish, the rest should be handled some other way. I find it easy to manipulate these parts from ithin the template, creating a few language files containing the rest of the phrases/imagesfiles/meta tags etc that you whish to translate. Some example code below.
Retrieving the current language setting.
Given that the Joom!Fish component is installed, the following code in your template index.php should do the trick.
< ?php
/**
* @author Pierre Norraeus
*
* Return the current language. This variable is controlled by
* the Joom!Fish Joomla component. Having this function should enable
* a potential change in the Joom!Fish functionality.
*
*
*/
function getCurrentLanguage() {
global $mosConfig_lang;
return $mosConfig_lang;
}
/**
* @author Pierre Norraeus
*
* Detect the current language, for now only accept swedish, and if
* not swedish lets make english the default.
*
* @todo extend more languages..
*
*/
if (getCurrentLanguage() == "swedish") {
include_once ('language_texts_se.php');
} else {
include_once ('language_texts_en.php');
}
? >
Example language file.
The variablenames below should of course be according to your coding standard (aswell as the rest of this example..:) ).
< ?php
/*
* @author Pierre Norraeus
* English language file.
*
*/
define(main_userid, 'Username');
define(main_password, 'Password');
? >
HTML examples..
Importing a language-based javascript file..
..script language="JavaScript" type="text/javascript" src="< ?php echo $mosConfig_live_site;?>/templates/Templatename/js/menu_< ?php echo getCurrentLanguage();? >.js”>
Language specific image
...img src="< ?php echo $mosConfig_live_site;? >/templates/templatename/images/buttons/search_< ?php echo getCurrentLanguage();? >.gif” alt=”" /…
The rest should be handled by the Joom!Fish component, very smooth.
Posted in Programming, Comp, Joomla |
No Comments »
