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...

81 lines
1.6 KiB
PHTML

<?php
/**
* Return currently active locale
*
* @return string
*/
8 years ago
function locale()
{
return session()->get('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();
$session = session();
if ($request->has('set_locale') && isset($locales[$request->input('set_locale')])) {
$session->set('locale', $request->input('set_locale'));
} elseif (!$session->has('locale')) {
$session->set('locale', config('default_locale'));
8 years ago
}
8 years ago
gettext_locale();
bindtextdomain('default', app('path.lang'));
8 years ago
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()->get('locale');
8 years ago
}
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()
{
$request = app('request');
8 years ago
8 years ago
$items = [];
foreach (config('locales') as $locale => $name) {
$url = url($request->getPathInfo(), ['set_locale' => $locale]);
8 years ago
$items[] = toolbar_item_link(
htmlspecialchars($url),
8 years ago
'',
$name,
$locale == locale()
8 years ago
);
8 years ago
}
return $items;
}