New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix back-office translations when multishop and multiple languages #28392
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -221,8 +221,30 @@ | |
if (isset($cookie->id_lang) && $cookie->id_lang) { | ||
$language = new Language($cookie->id_lang); | ||
} | ||
if (!isset($language) || !Validate::isLoadedObject($language) || !$language->isAssociatedToShop()) { | ||
|
||
$isNotValidLanguage = !isset($language) || !Validate::isLoadedObject($language); | ||
// `true` if language is defined from multishop or backoffice (`$employee` variable defined) session | ||
$isLanguageDefinedFromSession = (isset($language) && $language->isAssociatedToShop()) || defined('_PS_ADMIN_DIR_'); | ||
|
||
$useDefaultLanguage = $isNotValidLanguage || !$isLanguageDefinedFromSession; | ||
if ($useDefaultLanguage) { | ||
|
||
// Default value for most cases | ||
$language = new Language(Configuration::get('PS_LANG_DEFAULT')); | ||
|
||
// if `PS_LANG_DEFAULT` not a valid language for current shop then | ||
// use first valid language of the shop as default language. | ||
if($language->isMultishop() && !$language->isAssociatedToShop()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fallback is legit in the current context because we have inconsistent configuration, we allow to define a default language which can be different from the languages associated to the shop, hence this forced fallback We need to open an issue to avoid this behaviour, in the language edition we should prevent unassociating the default language, thus forcing the user to change it accordingly before he unassociates it |
||
$shopLanguages = $language->getLanguages(true, Context::getContext()->shop->id, false); | ||
|
||
if(isset($shopLanguages[0]['id_lang'])) { | ||
$shopDefaultLanguage = new Language($shopLanguages[0]['id_lang']); | ||
|
||
if(Validate::isLoadedObject($language)) { | ||
$language = $shopDefaultLanguage; | ||
} | ||
} | ||
} | ||
} | ||
|
||
$context->language = $language; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the conditions are quite complex (double negation, OR with isNot on one side and Is on the other) splitting this into multiple lines with clear naming seems more human-readable to me