From 75746e15880c72487864ed62b860052eedc224b6 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 4 Jul 2016 15:22:05 +0200 Subject: [translation] Improve module list; move baseconfig hook to baseconfig_bwlp --- inc/dictionary.inc.php | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'inc/dictionary.inc.php') 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 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 + * @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 = '' . $name . ' '; + if ($caption) { + $img .= $name; + } + } else { + $img = '
' . $langCC . '
'; + } + return $img; + } + } Dictionary::init(); -- cgit v1.2.3-55-g7522