Nicolas Moyroud
|
Re:Language files - 2005/12/01 15:27
Hello,
Very good idea Martin, thanks! I think I will use that kind of language file for my future developments. I like the idea to allow the users to keep their changes even when a new version is available. But it's a little boring to have to put if(!defined('NAME')) define... at each line of your language file. To alter the text, users have to edit this file and can make some mistakes when adding their own lines. I think about it for a while and I have an improvement to suggest. So I propose to use two separated ini files for one language and take the benefit of using the parse_ini_file PHP function. I give an example :
1) file english.ini (provided with the component) _GLOSSARY_TERM = Term _GLOSSARY_TERMS = Terms _GLOSSARY_AUTHOR = Author _GLOSSARY_GLOSSARY = Glossary ... 2) file english_custom.ini (created & edited by user) _GLOSSARY_AUTHOR = Creator ...
3) file language.php function loadLanguage($lang) { if (file_exists($lang.'_custom.ini')) { $tab2 = parse_ini_file($lang.'_custom.ini'); fillConstants($tab2); }
if (!file_exists($lang.'.ini')) { $lang = 'english'; } $tab = parse_ini_file($lang.'.ini'); fillConstants($tab); }
function fillConstants($array) { foreach ($array as $key=>$val) { if(!defined($key)) { define($key,$val); } } }
4) At the top of a file where your want to use your language file (for example glossary.php), just add : require_once 'language.php'; loadLanguage($lang); // $mosConfig_lang instead of $lang for Mambo-Joomla
Then users only have to edit english_custom.ini, french_custom.ini, etc... which are very simple file with no php code in them. When a new version of the component is available, users will keep unchanged their custom.ini files.
|