Skip to content

Instantly share code, notes, and snippets.

@hutt
Created November 13, 2012 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hutt/4066262 to your computer and use it in GitHub Desktop.
Save hutt/4066262 to your computer and use it in GitHub Desktop.
Sharebase's translation functions.
function selectLangfile(){
$dir = opendir("sources");
while ($element = readdir($dir)) {
if (($element != '.') && ($element != '..')) {
if ((is_file('sources/'.$element)) && (substr('sources/'.$element, -3) == 'xml')) {
$langfile[] = $element;
}
}
}
closedir($dir);
return $langfile[0];
}
function t($tr_id) {
$langfile_name = selectLangfile();
if(is_file("sources/".$langfile_name)){
$langfile = simplexml_load_file("sources/".$langfile_name);
}else{
echo '<!Doctype html><html><head><meta http-equiv="refresh" content="0; URL=error.php?e=lang_file">';
exit;
}
$path = "/lang/exp[@id=\"$tr_id\"]";
$res = $langfile->xpath($path);
echo $res[0]->tr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment