2012-11-30 00:21:03 +01:00
|
|
|
<?php
|
|
|
|
|
2017-03-23 23:01:20 +01:00
|
|
|
final class Application_Model_Locale
|
2012-11-30 00:21:03 +01:00
|
|
|
{
|
2021-10-14 19:58:14 +02:00
|
|
|
private static $domains = ['libretime'];
|
2021-10-11 16:10:47 +02:00
|
|
|
|
|
|
|
public static $locales = [
|
|
|
|
'en_US' => 'English (USA)',
|
|
|
|
'cs_CZ' => 'Český',
|
|
|
|
'de_AT' => 'Deutsch (Österreich)',
|
2021-10-17 00:20:03 +02:00
|
|
|
'de_DE' => 'Deutsch',
|
2021-10-11 16:10:47 +02:00
|
|
|
'el_GR' => 'Ελληνικά',
|
2021-10-17 00:20:03 +02:00
|
|
|
'en_CA' => 'English (Canada)',
|
|
|
|
'en_GB' => 'English (Britain)',
|
2021-10-11 16:10:47 +02:00
|
|
|
'es_ES' => 'Español',
|
|
|
|
'fr_FR' => 'Français',
|
|
|
|
'hr_HR' => 'Hrvatski',
|
|
|
|
'hu_HU' => 'Magyar',
|
|
|
|
'it_IT' => 'Italiano',
|
|
|
|
'ja_JP' => '日本語',
|
|
|
|
'ko_KR' => '한국어',
|
2021-10-17 00:20:03 +02:00
|
|
|
// 'nl_NL' => '',
|
2021-10-11 16:10:47 +02:00
|
|
|
'pl_PL' => 'Polski',
|
|
|
|
'pt_BR' => 'Português (Brasil)',
|
|
|
|
'ru_RU' => 'Русский',
|
|
|
|
'sr_RS' => 'Српски (Ћирилица)',
|
|
|
|
'sr_RS@latin' => 'Srpski (Latinica)',
|
2021-10-17 00:20:03 +02:00
|
|
|
// 'tr_TR' => '',
|
2021-10-11 16:10:47 +02:00
|
|
|
'zh_CN' => '简体中文',
|
|
|
|
];
|
|
|
|
|
2012-11-30 00:21:03 +01:00
|
|
|
public static function getLocales()
|
|
|
|
{
|
2014-08-26 19:32:35 +02:00
|
|
|
return self::$locales;
|
2012-11-30 00:21:03 +01:00
|
|
|
}
|
2013-01-10 00:03:23 +01:00
|
|
|
|
|
|
|
public static function configureLocalization($locale = null)
|
|
|
|
{
|
|
|
|
$codeset = 'UTF-8';
|
|
|
|
if (is_null($locale)) {
|
2021-10-11 16:10:47 +02:00
|
|
|
$lang = Application_Model_Preference::GetLocale() . '.' . $codeset;
|
2013-01-10 00:03:23 +01:00
|
|
|
} else {
|
2021-10-11 16:10:47 +02:00
|
|
|
$lang = $locale . '.' . $codeset;
|
2013-01-10 00:03:23 +01:00
|
|
|
}
|
2022-03-14 11:15:04 +01:00
|
|
|
// putenv("LC_ALL=$lang");
|
|
|
|
// putenv("LANG=$lang");
|
|
|
|
// Setting the LANGUAGE env var supposedly lets gettext search inside our locale dir even if the system
|
|
|
|
// doesn't have the particular locale that we want installed. This doesn't actually seem to work though. -- Albert
|
2021-10-11 16:10:47 +02:00
|
|
|
putenv("LANGUAGE={$locale}");
|
|
|
|
if (setlocale(LC_MESSAGES, $lang) === false) {
|
|
|
|
Logging::warn('Your system does not have the ' . $lang . ' locale installed. Run: sudo locale-gen ' . $lang);
|
2014-07-28 17:35:19 +02:00
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2014-11-04 22:57:40 +01:00
|
|
|
// We need to run bindtextdomain and bind_textdomain_codeset for each domain we're using.
|
|
|
|
foreach (self::$domains as $domain) {
|
|
|
|
bindtextdomain($domain, '../locale');
|
|
|
|
bind_textdomain_codeset($domain, $codeset);
|
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2021-10-14 19:58:14 +02:00
|
|
|
textdomain('libretime');
|
2013-01-10 00:03:23 +01:00
|
|
|
}
|
2021-10-11 16:10:47 +02:00
|
|
|
|
2014-11-05 23:24:54 +01:00
|
|
|
/**
|
2021-10-11 16:10:47 +02:00
|
|
|
* We need this function for the case where a user has logged out, but
|
2014-11-05 23:24:54 +01:00
|
|
|
* has an airtime_locale cookie containing their locale setting.
|
2021-10-11 16:10:47 +02:00
|
|
|
*
|
|
|
|
* If the user does not have an airtime_locale cookie set, we default
|
2014-11-05 23:24:54 +01:00
|
|
|
* to the station locale.
|
2021-10-11 16:10:47 +02:00
|
|
|
*
|
|
|
|
* When the user logs in, the value set in the login form will be passed
|
|
|
|
* into the airtime_locale cookie. This cookie is also updated when
|
2014-11-05 23:24:54 +01:00
|
|
|
* a user updates their user settings.
|
|
|
|
*/
|
2021-10-11 16:10:47 +02:00
|
|
|
public static function getUserLocale()
|
|
|
|
{
|
2014-11-05 23:24:54 +01:00
|
|
|
$request = Zend_Controller_Front::getInstance()->getRequest();
|
2014-11-05 23:36:58 +01:00
|
|
|
|
2021-10-11 16:10:47 +02:00
|
|
|
return $request->getCookie('airtime_locale', Application_Model_Preference::GetLocale());
|
|
|
|
}
|
2014-08-26 19:32:35 +02:00
|
|
|
}
|