From 2daea814d7473b2079172efa24b9d1dc12cdff13 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sun, 22 Nov 2015 22:54:51 +0100 Subject: [PATCH] WEB: Support for localized .xml files --- include/Controller.php | 2 ++ include/XMLParser.php | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/Controller.php b/include/Controller.php index 29960c907..9ab07d47b 100644 --- a/include/Controller.php +++ b/include/Controller.php @@ -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; diff --git a/include/XMLParser.php b/include/XMLParser.php index fc0b8ca6e..2c1b628a6 100644 --- a/include/XMLParser.php +++ b/include/XMLParser.php @@ -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)) {