Example #1
0
 public function test_get_list_of_locales()
 {
     // For a locale containing country code, we prefer
     // full locale name, but if that's not found, fall back
     // to the language only locale name.
     $this->assertEquals(array("sr_RS", "sr"), get_list_of_locales("sr_RS"));
     // If language code is used, it's the only thing returned.
     $this->assertEquals(array("sr"), get_list_of_locales("sr"));
     // There is support for language and charset only.
     $this->assertEquals(array("sr.UTF-8", "sr"), get_list_of_locales("sr.UTF-8"));
     // It can also split out character set from the full locale name.
     $this->assertEquals(array("sr_RS.UTF-8", "sr_RS", "sr"), get_list_of_locales("sr_RS.UTF-8"));
     // There is support for @modifier in locale names as well.
     $this->assertEquals(array("sr_RS.UTF-8@latin", "sr_RS@latin", "sr@latin", "sr_RS.UTF-8", "sr_RS", "sr"), get_list_of_locales("sr_RS.UTF-8@latin"));
     // We can pass in only language and modifier.
     $this->assertEquals(array("sr@latin", "sr"), get_list_of_locales("sr@latin"));
     // If locale name is not following the regular POSIX pattern,
     // it's used verbatim.
     $this->assertEquals(array("something"), get_list_of_locales("something"));
     // Passing in an empty string returns an empty array.
     $this->assertEquals(array(), get_list_of_locales(""));
 }
/**
 * Utility function to get a StreamReader for the given text domain.
 */
function _get_reader($domain = null, $category = 5, $enable_cache = true)
{
    global $text_domains, $default_domain, $LC_CATEGORIES;
    if (!isset($domain)) {
        $domain = $default_domain;
    }
    if (!isset($text_domains[$domain]->l10n)) {
        // get the current locale
        $locale = _setlocale(LC_MESSAGES, 0);
        $bound_path = isset($text_domains[$domain]->path) ? $text_domains[$domain]->path : './';
        $subpath = $LC_CATEGORIES[$category] . "/{$domain}.mo";
        $locale_names = get_list_of_locales($locale);
        $input = null;
        foreach ($locale_names as $locale) {
            $full_path = $bound_path . $locale . "/" . $subpath;
            if (file_exists($full_path)) {
                $input = new FileReader($full_path);
                break;
            }
        }
        if (!array_key_exists($domain, $text_domains)) {
            // Initialize an empty domain object.
            $text_domains[$domain] = new domain();
        }
        $text_domains[$domain]->l10n = new gettext_reader($input, $enable_cache);
    }
    return $text_domains[$domain]->l10n;
}
Example #3
0
/* default localization of Cacti */
$cacti_locale = "en";
$cacti_country = "us";

/* an array that will contains all textdomains being in use. */
$cacti_textdomains = array();

/* use a fallback if i18n is disabled (default) */
if (read_config_option('i18n_support') == 0) {
	load_fallback_procedure();
	return;
}

/* get a list of locale settings */
$lang2locale = get_list_of_locales();


/* determine whether or not we can support the language */
/* user requests another language */
if (isset($_GET['language']) && isset($lang2locale[$_GET['language']])) {
	$cacti_locale = $_GET['language'];
	$cacti_country = $lang2locale[$_GET['language']]['country'];
	$_SESSION['language'] = $cacti_locale;

	/* save customized language setting (authenticated users only) */
	set_user_config_option('language', $cacti_locale);

/* language definition stored in the SESSION */
}elseif (isset($_SESSION['language']) && isset($lang2locale[$_SESSION['language']])){
	$cacti_locale = $_SESSION['language'];
Example #4
0
/**
 * Utility function to get a StreamReader for the given text domain.
 */
function _get_reader($domain = null, $category = 5, $enable_cache = true)
{
    if (!isset($domain)) {
        $domain = domain::$default_domain;
    }
    if (!isset(domain::$text_domains[$domain]->l10n)) {
        // get the current locale
        $locale = _setlocale(LC_MESSAGES, 0);
        $bound_path = isset(domain::$text_domains[$domain]->path) ? domain::$text_domains[$domain]->path : './';
        $subpath = domain::$LC_CATEGORIES[$category] . '/' . $domain . '.mo';
        $locale_names = get_list_of_locales($locale);
        $input = null;
        foreach ($locale_names as $locale) {
            $full_path = $bound_path . $locale . '/' . $subpath;
            if (file_exists($full_path)) {
                $input = new FileReader($full_path);
                break;
            }
        }
        if (!isset(domain::$text_domains[$domain])) {
            // Initialize an empty domain object.
            domain::$text_domains[$domain] = new domain();
        }
        domain::$text_domains[$domain]->l10n = new gettext_reader($input, $enable_cache);
    }
    return domain::$text_domains[$domain]->l10n;
}