Skip to content

Commit

Permalink
WEB: Added lang.ini support
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Dec 12, 2015
1 parent f868afb commit f348f46
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
14 changes: 14 additions & 0 deletions include/Controller.php
Expand Up @@ -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
*/
Expand All @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions include/Pages/NewsPage.php
Expand Up @@ -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';
Expand All @@ -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,
Expand All @@ -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();

Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions include/config.inc.php
Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions lang/lang.ini
@@ -0,0 +1 @@
newsTitle = "Latest Developments"
1 change: 1 addition & 0 deletions lang/lang.ru.ini
@@ -0,0 +1 @@
newsTitle = "Последние новости"

0 comments on commit f348f46

Please sign in to comment.