Skip to content

Commit

Permalink
WEB: Support for localized .xml files
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Dec 12, 2015
1 parent b7747aa commit 2daea81
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/Controller.php
Expand Up @@ -31,6 +31,8 @@ public function __construct() {
$_SESSION['lang'] = empty($_GET['lang']) ? 'en' : $_GET['lang'];
}

global $lang;

$lang = 'de';
$this->_smarty->template_dir = array("templates_$lang", 'templates');
$this->_smarty->compile_id = $lang;
Expand Down
18 changes: 18 additions & 0 deletions include/XMLParser.php
Expand Up @@ -48,6 +48,24 @@ public function XMLParser() {
* @throws ErrorException
*/
public function parseByFilename($filename) {
global $lang;

if ($lang != 'en') {
$fname = substr($filename, 0, strrpos($filename, '.'));
$fext = strrchr($filename, '.' );

$localized = $fname . "." . $lang . $fext;

if (is_file($localized)) {
if (!is_readable($localized)) {
$file = "\n\nFilename: " . basename($localized) . "\n";
throw new ErrorException(self::FILE_NOT_FOUND . $file);
} else {
$filename = $localized;
}
}
}

$file = "\n\nFilename: " . basename($filename) . "\n";
/* If we can't read the file there is nothing we can do. */
if (!is_file($filename) || !is_readable($filename)) {
Expand Down

0 comments on commit 2daea81

Please sign in to comment.