summaryrefslogtreecommitdiffstats
path: root/inc
diff options
context:
space:
mode:
authorSimon Rettberg2014-08-15 13:10:56 +0200
committerSimon Rettberg2014-08-15 13:10:56 +0200
commitfe7412bdaf02e00699fd6654f74838c4cbe38bf9 (patch)
tree1975feb934a3d68abf2f243580cf1bd7d1c8f683 /inc
parent[i18n] Sanity checks, introduced subdir for template language files (diff)
downloadslx-admin-fe7412bdaf02e00699fd6654f74838c4cbe38bf9.tar.gz
slx-admin-fe7412bdaf02e00699fd6654f74838c4cbe38bf9.tar.xz
slx-admin-fe7412bdaf02e00699fd6654f74838c4cbe38bf9.zip
Find messages and hardcoded-messages in php files, fix editing of messages
Diffstat (limited to 'inc')
-rw-r--r--inc/dictionary.inc.php24
-rw-r--r--inc/message.inc.php14
2 files changed, 21 insertions, 17 deletions
diff --git a/inc/dictionary.inc.php b/inc/dictionary.inc.php
index 5ac0d569..14305c99 100644
--- a/inc/dictionary.inc.php
+++ b/inc/dictionary.inc.php
@@ -3,7 +3,7 @@
class Dictionary
{
- private static $messageArray;
+ private static $messageArray = array();
private static $languages;
private static $templateCache = array();
private static $hardcodedMessages = false;
@@ -48,14 +48,18 @@ class Dictionary
}
define('LANG', $language);
- self::$messageArray = json_decode(file_get_contents("lang/" . LANG . "/messages.json"), true);
}
public static function getArrayTemplate($template, $lang = false)
{
+ return self::getArray('templates/' . $template, $lang);
+ }
+
+ public static function getArray($section, $lang = false)
+ {
if ($lang === false)
$lang = LANG;
- $file = "lang/" . $lang . "/templates/" . $template . ".json";
+ $file = Util::safePath("lang/" . $lang . "/" . $section . ".json");
if (isset(self::$templateCache[$file]))
return self::$templateCache[$file];
$language = array('lang' => $lang);
@@ -71,17 +75,25 @@ class Dictionary
public static function translate($string)
{
if (self::$hardcodedMessages === false)
- self::$hardcodedMessages = @json_decode(@file_get_contents("lang/" . LANG . "/messages-hardcoded.json"), true);
+ self::$hardcodedMessages = json_decode(file_get_contents("lang/" . LANG . "/messages-hardcoded.json"), true);
if (!isset(self::$hardcodedMessages[$string]))
return "(missing: $string :missing)";
return self::$hardcodedMessages[$string];
}
- public static function getMessages()
+ public static function getMessage($id)
{
- return self::$messageArray;
+ if (self::$messageArray === false)
+ self::$messageArray = json_decode(file_get_contents("lang/" . LANG . "/messages.json"), true);
+ if (!isset(self::$messageArray[$id]))
+ return "(missing: $id :missing)";
+ return self::$messageArray[$id];
}
+ /**
+ * Get all supported languages as array
+ * @return array List of languages (2 char id)
+ */
public static function getLanguages()
{
return self::$languages;
diff --git a/inc/message.inc.php b/inc/message.inc.php
index 3fbff874..0e054846 100644
--- a/inc/message.inc.php
+++ b/inc/message.inc.php
@@ -1,9 +1,5 @@
<?php
-// TODO: Move to extra file
-global $error_text;
-$error_text = Dictionary::getMessages();
-
class Message
{
private static $list = array();
@@ -41,8 +37,6 @@ class Message
*/
private static function add($type, $id, $params)
{
- global $error_text;
- if (!isset($error_text[$id])) Util::traceError('Invalid message id: ' . $id);
self::$list[] = array(
'type' => $type,
'id' => $id,
@@ -58,11 +52,10 @@ class Message
*/
public static function renderList()
{
- global $error_text;
// Ajax
if (AJAX) {
foreach (self::$list as $item) {
- $message = $error_text[$item['id']];
+ $message = Dictionary::getMessage($item['id']);
foreach ($item['params'] as $index => $text) {
$message = str_replace('{{' . $index . '}}', '<b>' . htmlspecialchars($text) . '</b>', $message);
}
@@ -74,7 +67,7 @@ class Message
// Non-Ajax
if (!self::$flushed) Render::openTag('div', array('class' => 'container'));
foreach (self::$list as $item) {
- $message = $error_text[$item['id']];
+ $message = Dictionary::getMessage($item['id']);
foreach ($item['params'] as $index => $text) {
$message = str_replace('{{' . $index . '}}', '<b>' . htmlspecialchars($text) . '</b>', $message);
}
@@ -92,10 +85,9 @@ class Message
*/
public static function asString()
{
- global $error_text;
$return = '';
foreach (self::$list as $item) {
- $message = $error_text[$item['id']];
+ $message = Dictionary::getMessage($item['id']);
foreach ($item['params'] as $index => $text) {
$message = str_replace('{{' . $index . '}}', $text, $message);
}