From f348f46dfccc9bb88b3eadaa5d697c06e99c8a49 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sun, 6 Dec 2015 20:31:45 +0100 Subject: [PATCH] WEB: Added lang.ini support --- include/Controller.php | 14 ++++++++++++++ include/Pages/NewsPage.php | 8 ++++++-- include/config.inc.php | 1 + lang/lang.ini | 1 + lang/lang.ru.ini | 1 + 5 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 lang/lang.ini create mode 100644 lang/lang.ru.ini diff --git a/include/Controller.php b/include/Controller.php index 6abef56c8..f11403f9a 100644 --- a/include/Controller.php +++ b/include/Controller.php @@ -24,6 +24,10 @@ public function __construct() { /* Create a Smarty object. */ $this->_smarty = new Smarty(); + # Stick it globally so we could refer the translations + global $Smarty; + $Smarty = $this->_smarty; + /** * Multilanguage suppot */ @@ -36,6 +40,16 @@ public function __construct() { $lang = 'ru'; $this->_smarty->template_dir = array("templates_$lang", 'templates'); $this->_smarty->compile_id = $lang; + $this->_smarty->config_dir = "."; + + # First we read English, so al defaults are there + $this->_smarty->config_load(DIR_LANG . "/lang.ini"); + + # Now we try to read translations + if (is_file(($fname = DIR_LANG . "/lang.$lang.ini")) + && is_readable($fname)) { + $this->_smarty->config_load($fname); + } /* Configure smarty. */ $this->_smarty->compile_dir = SMARTY_DIR_COMPILE; diff --git a/include/Pages/NewsPage.php b/include/Pages/NewsPage.php index 1c90083b5..ecd3558d6 100644 --- a/include/Pages/NewsPage.php +++ b/include/Pages/NewsPage.php @@ -27,6 +27,8 @@ public function index() { /* Display a specific news item, or all news items. */ public function getNews($date = null) { + global $Smarty; + if ($date == null) { $news_items = NewsModel::getAllNews(); $date = 'archive'; @@ -43,7 +45,7 @@ public function getNews($date = null) { return $this->renderPage( array( 'title' => 'Home', - 'content_title' => 'Latest Developments', + 'content_title' => $Smarty->_config[0]['vars']['newsTitle'], 'show_intro' => false, 'news_items' => $news_items, 'news_archive_link' => false, @@ -55,6 +57,8 @@ public function getNews($date = null) { /* Display the main page with limited news items and intro text. */ public function getNewsIntro() { + global $Smarty; + $news_items = NewsModel::getLatestNews(NEWS_ITEMS); $random_shot = ScreenshotsModel::getRandomScreenshot(); @@ -73,7 +77,7 @@ public function getNewsIntro() { return $this->renderPage( array( 'title' => 'Home', - 'content_title' => 'Latest Developments', + 'content_title' => $Smarty->_config[0]['vars']['newsTitle'], 'show_intro' => true, 'news_items' => $news_items, 'news_archive_link' => true, diff --git a/include/config.inc.php b/include/config.inc.php index 532e70af8..a318d658b 100644 --- a/include/config.inc.php +++ b/include/config.inc.php @@ -31,6 +31,7 @@ define('DIR_DATA', 'data'); define('DIR_IMAGES', 'images'); define('DIR_NEWS', 'data/news'); +define('DIR_LANG', 'lang'); define('DIR_COMPAT', 'data/compatibility'); define('DIR_DOWNLOADS', 'downloads'); define('DIR_SCREENSHOTS', 'data/screenshots'); diff --git a/lang/lang.ini b/lang/lang.ini new file mode 100644 index 000000000..644dad67c --- /dev/null +++ b/lang/lang.ini @@ -0,0 +1 @@ +newsTitle = "Latest Developments" diff --git a/lang/lang.ru.ini b/lang/lang.ru.ini new file mode 100644 index 000000000..b9377d3af --- /dev/null +++ b/lang/lang.ru.ini @@ -0,0 +1 @@ +newsTitle = "Последние новости"