You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
engelsystem/includes/helper/internationalization_helper...

77 lines
1.6 KiB
PHTML

<?php
/**
* Return currently active locale
*
* @return string
*/
8 years ago
function locale()
{
return $_SESSION['locale'];
}
/**
* Returns two letter language code from currently active locale
*
* @return string
*/
8 years ago
function locale_short()
{
return substr(locale(), 0, 2);
}
/**
* Initializes gettext for internationalization and updates the sessions locale to use for translation.
*/
8 years ago
function gettext_init()
{
$locales = config('locales');
$request = request();
if ($request->has('set_locale') && isset($locales[$request->input('set_locale')])) {
$_SESSION['locale'] = $request->input('set_locale');
8 years ago
} elseif (!isset($_SESSION['locale'])) {
$_SESSION['locale'] = config('default_locale');
8 years ago
}
8 years ago
gettext_locale();
bindtextdomain('default', realpath(__DIR__ . '/../../locale'));
bind_textdomain_codeset('default', 'UTF-8');
textdomain('default');
}
/**
* Swich gettext locale.
*
8 years ago
* @param string $locale
*/
8 years ago
function gettext_locale($locale = null)
{
if ($locale == null) {
$locale = $_SESSION['locale'];
}
8 years ago
8 years ago
putenv('LC_ALL=' . $locale);
setlocale(LC_ALL, $locale);
}
/**
* Renders language selection.
*
* @return array
*/
8 years ago
function make_langselect()
{
$url = $_SERVER['REQUEST_URI'] . (strpos($_SERVER['REQUEST_URI'], '?') > 0 ? '&' : '?') . 'set_locale=';
8 years ago
8 years ago
$items = [];
foreach (config('locales') as $locale => $name) {
8 years ago
$items[] = toolbar_item_link(
htmlspecialchars($url) . $locale,
8 years ago
'',
'<img src="pic/flag/' . $locale . '.png" alt="' . $name . '" title="' . $name . '"> ' . $name
);
8 years ago
}
return $items;
}