diff --git a/classes/Components/I18n/Bootstrap.php b/classes/Components/I18n/Bootstrap.php index f4a813f0..e0b5fd08 100644 --- a/classes/Components/I18n/Bootstrap.php +++ b/classes/Components/I18n/Bootstrap.php @@ -111,6 +111,19 @@ final class Bootstrap /** @var Database $db */ $db = $container->get('Database'); + $config=[]; + $firmaLang=null; + $firmaRegion=null; + // Get language from system settings and normalize to 3-letter-code and 2-letter-code + if ($firmaLang = self::findLanguage($app->erp->Firmendaten('preferredLanguage'))) { + $config[Localization::LANGUAGE_DEFAULT] = $firmaLang[Iso639\Key::ALPHA_3]; + } + + // Get region from system settings and normalize to 2-letter-code + if ($firmaLang && ($firmaRegion = self::findRegion($app->erp->Firmendaten('land')))) { + $config[Localization::LOCALE_DEFAULT] = "{$firmaLang[Iso639\Key::ALPHA_2]}_{$firmaRegion[Iso3166\Key::ALPHA_2]}"; + } + // Get User $usersettings = []; @@ -122,17 +135,17 @@ final class Bootstrap ); // Get language from user account and normalize to 3-letter-code and 2-letter-code - if ($lang = self::findLanguage($user->GetSprache())) { - $usersettings['language'] = $lang[Iso639\Key::ALPHA_3]; + if ($userLang = self::findLanguage($user->GetSprache())) { + $usersettings['language'] = $userLang[Iso639\Key::ALPHA_3]; } // Get region from user account and normalize to 2-letter-code - if ($lang && ($region = self::findRegion($userAddress['land']))) { - $usersettings['locale'] = "{$lang[Iso639\Key::ALPHA_2]}_{$region[Iso3166\Key::ALPHA_2]}"; + if ($userLang && ($userRegion = self::findRegion($userAddress['land']))) { + $usersettings['locale'] = "{$userLang[Iso639\Key::ALPHA_2]}_{$userRegion[Iso3166\Key::ALPHA_2]}"; } } // Create Localization object - return new Localization($request, $session, $usersettings); + return new Localization($request, $session, $usersettings, $config); } } diff --git a/classes/Components/I18n/Localization.php b/classes/Components/I18n/Localization.php index 853fc103..a29fb7f3 100644 --- a/classes/Components/I18n/Localization.php +++ b/classes/Components/I18n/Localization.php @@ -35,12 +35,12 @@ final class Localization implements LocalizationInterface - public function __construct(?Request $request, ?Session $session, array $usersettings = []) + public function __construct(?Request $request, ?Session $session, array $usersettings = [], array $config = []) { $this->request = $request; $this->session = $session; $this->usersettings = $usersettings; - $this->config = []; + $this->config = $config; $this->process(); } @@ -55,8 +55,6 @@ final class Localization implements LocalizationInterface $langAttrName = $this->config[Localization::LANGUAGE_ATTRIBUTE_NAME] ?? 'language'; $segmentName = 'i18n'; -// $session = $this->session; -// $request = $this->request; // Get the locale from the session, if available if ($this->session && ($locale = $this->session->getValue($segmentName, $localeAttrName))) {