getIdentifier(), $path, $tag);
}
public static function translate($tag, $returnTagOnMissing = false)
{
$string = self::translateFile('module', $tag);
if ($string !== false)
return $string;
$string = self::translateFileModule('main', 'global-tags', $tag);
if ($string !== false || !$returnTagOnMissing)
return $string;
return '{{' . $tag . '}}';
}
public static function getMessage($module, $id)
{
$string = self::translateFileModule($module, 'messages', $id);
if ($string === false) {
return "($id) ({{0}}, {{1}}, {{2}}, {{3}})";
}
return $string;
}
public static function getCategoryName($category)
{
if ($category === false) {
return 'No Category';
}
if (!preg_match('/^(\w+)\.(.*)$/', $category, $out)) {
return 'Invalid Category ID format: ' . $category;
}
$string = self::translateFileModule($out[1], 'categories', $out[2]);
if ($string === false) {
return "!!{$category}!!";
}
return $string;
}
/**
* Get all supported languages as array.
*
* @param boolean $withName true = return assoc array containinc cc and name of all languages;
* false = regular array containing only the ccs
* @return array List of languages
*/
public static function getLanguages($withName = false)
{
if (!$withName)
return self::$languages;
if (self::$languagesLong === false) {
self::$languagesLong = array();
foreach (self::$languages as $lang) {
if (file_exists("lang/$lang/name.txt")) {
$name = file_get_contents("lang/$lang/name.txt");
}
if (!isset($name) || $name === false) {
$name = $lang;
}
self::$languagesLong[] = array(
'cc' => $lang,
'name' => $name
);
}
}
return self::$languagesLong;
}
public static function getLanguageName($langCC)
{
if (file_exists("lang/$langCC/name.txt")) {
$name = file_get_contents("lang/$langCC/name.txt");
}
if (!isset($name) || $name === false) {
$name = $langCC;
}
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 = '
';
if ($caption) {
$img .= $name;
}
} else {
$img = '