Exemplo n.º 1
0
 /**
  * Used by Langstring::GetString() (and other functions) to help select the
  * best langstring_entry to display to the user.
  * @return A sql fragment
  */
 public static function getSqlCaseStringSelect($locale_id)
 {
     $decomposed_locale = WifidogLocale::decomposeLocaleId($locale_id);
     // The case will rate locales and choose the best one.
     $sql = " (CASE\n";
     // Look for part of the string or the full-length locale
     $sql .= " WHEN locales_id='{$decomposed_locale['0']}' THEN 1\n";
     // Look for a string or the language part of the locale (match generic language first)
     $sql .= " WHEN locales_id='{$decomposed_locale[1]}' THEN 2\n";
     // Look for the full string or any possible combination
     $sql .= " WHEN locales_id LIKE '{$decomposed_locale[1]}%' THEN 3\n";
     // Look for a string matching the language or the country of the user
     if (!empty($decomposed_locale[2])) {
         $sql .= " WHEN locales_id LIKE '%{$decomposed_locale[2]}' THEN 4\n";
     }
     // Look for a string with no locale associated, it's more likely to be readable than a random string
     $sql .= " WHEN locales_id IS NULL THEN 5\n";
     $sql .= "      ELSE 20 ";
     $sql .= "  END)\n";
     return $sql;
 }