Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,25 @@ function is_really_writable(string $file): bool
*/
function lang(string $line, array $args = [], string $locale = null)
{
return Services::language($locale)
->getLine($line, $args);
$language = Services::language();

//Get active locale
$activeLocale = $language->getLocale();

if ($locale && $locale != $activeLocale)
{
$language->setLocale($locale);
}

$line = $language->getLine($line, $args);

if ($locale && $locale != $activeLocale)
{
//Reset to active locale
$language->setLocale($activeLocale);
}

return $line;
}
}

Expand Down
19 changes: 19 additions & 0 deletions tests/system/Language/LanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,25 @@ public function testBaseFallbacks()

//--------------------------------------------------------------------

/**
* Test if after using lang() with a locale the Language class keep the locale after return the $line
*/
public function testLangKeepLocale()
{
$this->lang = Services::language('en', true);

lang('Language.languageGetLineInvalidArgumentException');
$this->assertEquals('en', $this->lang->getLocale());

lang('Language.languageGetLineInvalidArgumentException', [], 'ru');
$this->assertEquals('en', $this->lang->getLocale());

lang('Language.languageGetLineInvalidArgumentException');
$this->assertEquals('en', $this->lang->getLocale());
}

//--------------------------------------------------------------------

/**
* Testing base locale vs variants, with fallback to English.
*
Expand Down