Fix language if it is not found in the i18n. Reported by le_

This commit is contained in:
Sébastien Lucas 2013-07-29 10:10:54 +02:00
parent 4aa3529131
commit c84cec9516
3 changed files with 15 additions and 4 deletions

View file

@ -169,8 +169,11 @@ function localize($phrase, $count=-1) {
$translations = array_merge ($translations_en, $translations); $translations = array_merge ($translations_en, $translations);
} }
} }
if (array_key_exists ($phrase, $translations)) {
return $translations[$phrase]; return $translations[$phrase];
} }
return $phrase;
}
function addURLParameter($urlParams, $paramName, $paramValue) { function addURLParameter($urlParams, $paramName, $paramValue) {
$start = ""; $start = "";

View file

@ -227,7 +227,7 @@ class Book extends Base {
$result->execute (array ($this->id)); $result->execute (array ($this->id));
while ($post = $result->fetchObject ()) while ($post = $result->fetchObject ())
{ {
array_push ($lang, localize("languages.".$post->lang_code)); array_push ($lang, Language::getLanguageString($post->lang_code));
} }
return implode (", ", $lang); return implode (", ", $lang);
} }

View file

@ -27,6 +27,14 @@ class language extends Base {
return self::ALL_LANGUAGES_ID.":".$this->id; return self::ALL_LANGUAGES_ID.":".$this->id;
} }
public static function getLanguageString ($code) {
$string = localize("languages.".$code);
if (preg_match ("/^languages/", $string)) {
return $code;
}
return $string;
}
public static function getCount() { public static function getCount() {
$nLanguages = parent::getDb ()->query('select count(*) from languages')->fetchColumn(); $nLanguages = parent::getDb ()->query('select count(*) from languages')->fetchColumn();
if ($nLanguages == 0) return NULL; if ($nLanguages == 0) return NULL;
@ -40,7 +48,7 @@ class language extends Base {
$result = parent::getDb ()->prepare('select id, lang_code from languages where id = ?'); $result = parent::getDb ()->prepare('select id, lang_code from languages where id = ?');
$result->execute (array ($languageId)); $result->execute (array ($languageId));
if ($post = $result->fetchObject ()) { if ($post = $result->fetchObject ()) {
return new Language ($post->id, localize("languages.".$post->lang_code)); return new Language ($post->id, Language::getLanguageString ($post->lang_code));
} }
return NULL; return NULL;
} }
@ -57,7 +65,7 @@ order by languages.lang_code');
while ($post = $result->fetchObject ()) while ($post = $result->fetchObject ())
{ {
$language = new Language ($post->id, $post->lang_code); $language = new Language ($post->id, $post->lang_code);
array_push ($entryArray, new Entry (localize("languages.".$language->lang_code), $language->getEntryId (), array_push ($entryArray, new Entry (Language::getLanguageString ($language->lang_code), $language->getEntryId (),
str_format (localize("bookword", $post->count), $post->count), "text non", str_format (localize("bookword", $post->count), $post->count), "text non",
array ( new LinkNavigation ($language->getUri ())))); array ( new LinkNavigation ($language->getUri ()))));
} }