summaryrefslogtreecommitdiffstats
path: root/inc/dictionary.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2016-07-04 15:22:05 +0200
committerSimon Rettberg2016-07-04 15:22:05 +0200
commit75746e15880c72487864ed62b860052eedc224b6 (patch)
treed215f39a9303e35bf9d501af36abaa27352d33f8 /inc/dictionary.inc.php
parentdelete update.inc.php: Not used anymore (diff)
downloadslx-admin-75746e15880c72487864ed62b860052eedc224b6.tar.gz
slx-admin-75746e15880c72487864ed62b860052eedc224b6.tar.xz
slx-admin-75746e15880c72487864ed62b860052eedc224b6.zip
[translation] Improve module list; move baseconfig hook to baseconfig_bwlp
Diffstat (limited to 'inc/dictionary.inc.php')
-rw-r--r--inc/dictionary.inc.php33
1 files changed, 31 insertions, 2 deletions
diff --git a/inc/dictionary.inc.php b/inc/dictionary.inc.php
index 01651b88..cb23d0b2 100644
--- a/inc/dictionary.inc.php
+++ b/inc/dictionary.inc.php
@@ -56,10 +56,11 @@ class Dictionary
$file = Util::safePath("modules/{$module}/lang/{$lang}/{$path}.json");
if (isset(self::$stringCache[$file]))
return self::$stringCache[$file];
- $content = @file_get_contents($file);
+ if (!file_exists($file))
+ return array();
+ $content = file_get_contents($file);
if ($content === false) { // File does not exist for language
$content = '[]';
- error_log("getArray called for non-existent $file");
}
$json = json_decode($content, true);
if (!is_array($json)) {
@@ -156,6 +157,34 @@ class Dictionary
return $name;
}
+ /**
+ * Get an <img> tag for the given language. If there is no flag image,
+ * fall back to generating a .badge with the CC.
+ * If long mode is requested, returns the name of the language right next
+ * to the image, otherwise, it is just added as the title attribute.
+ *
+ * @param $caption bool with caption next to <img>
+ * @param $langCC string Language cc to get flag code for - defaults to current language
+ * @retrun string html code of img tag for language
+ */
+ public static function getFlagHtml($caption = false, $langCC = false)
+ {
+ if ($langCC === false) {
+ $langCC = LANG;
+ }
+ $flag = "lang/$langCC/flag.png";
+ $name = htmlspecialchars(self::getLanguageName($langCC));
+ if (file_exists($flag)) {
+ $img = '<img alt="' . $name . '" title="' . $name . '" src="' . $flag . '"> ';
+ if ($caption) {
+ $img .= $name;
+ }
+ } else {
+ $img = '<div class="badge" title="' . $name . '">' . $langCC . '</div>';
+ }
+ return $img;
+ }
+
}
Dictionary::init();