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
Fix back-office translations when multishop and multiple languages #28392
Conversation
config/config.inc.php
Outdated
$use_default_language = !isset($language) || // if language not defined | ||
!Validate::isLoadedObject($language) || // or if language object is not valide | ||
( !$language->isAssociatedToShop() && !isset($employee) ); // or if ( language is not associated to shop [FO] AND employee not defined [BO] ) | ||
|
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.
I suggest to use variables name instead comments, something like :
$isNotValidLanguage = !isset($language) || !Validate::isLoadedObject($language);
$isNotAssociatedToShop = !$language->isAssociatedToShop();
$isEmployeeUndefined = !Validate::isLoadedObjet($employee);
$useDefaultLanguage = $isNotValidLanguage || ($isNotAssociatedToShop && $isEmployeeUndefined);
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.
Looks good for me ^^
Let me change this :)
☝️ I think I'll keep some comments cause I think the key pain point is about multishop and BO mixed behavior.
1c9c2b4
to
106ca04
Compare
config/config.inc.php
Outdated
$isLanguageDefinedFromCustomSession = (isset($language) && $language->isAssociatedToShop()) || isset($employee); | ||
|
||
$useDefaultLanguage = $isNotValidLanguage || !$isLanguageDefinedFromCustomSession; | ||
if ( $useDefaultLanguage ) { |
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.
I'm surprised we don't have a code styling rule for this, but as we usually don't put spaces for simple if
, I suggest you to remove them.
if ( $useDefaultLanguage ) { | |
if ($useDefaultLanguage) { |
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.
@atomiix ,
I took some time to search if I could configure something to help (cause I'll never be able to be attentive to this alone ^^') and I found that :
PHP-CS-Fixer/PHP-CS-Fixer#5709
and
https://packagist.org/packages/superdj/spaces-in-parentheses-php-cs-fixer
But it seems this fixer isn't compatible with version we used ^^'
Should be had the link to some roadmap ? Where can I find this ?
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.
Actually, the rule is used, but the config of php-cs-fixer
omit the config/
folder.
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.
Oh ! I'll check this then ^^
Thanks for information
106ca04
to
193d423
Compare
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.
Thank you for exploring the bug and for the nice and clear bugfix @MeKeyCool well done!
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.
Small feedback
Hi @MeKeyCool Thank you for your PR, I tested it and all pages on the BO seems to be translated as we wish except merchant expertise (maybe because it's a module ?) as you can see : (I put it in french, it's better for me) but there is another issue following this pr, you can see it on this video : Untitled_.May.6.2022.2_42.PM.mp4Currently, my shop name "deuxième" should be in french, and when I go on it, it's in english, even if some words are already translated on BO like the catogories or anything else. Moreover, you can't change the languages on the website because you doesn't allow it |
Well done @AureRita , I did those tests but not from BO link 🤔 Maybe as you are still logged in BO it is detected. |
Does the bug happen if no multishop configured ? |
As you can see, on a single shop, you can't disable languages, if you have two of them, they could be selected on the FO : Untitled_.May.6.2022.5_40.PM.mp4 |
193d423
to
1d151ce
Compare
$useDefaultLanguage = $isNotValidLanguage || !$isLanguageDefinedFromSession; | ||
if ($useDefaultLanguage) { |
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.
$useDefaultLanguage = $isNotValidLanguage || !$isLanguageDefinedFromSession; | |
if ($useDefaultLanguage) { | |
if ($isNotValidLanguage || !$isLanguageDefinedFromSession) { |
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
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.
A last comment
@MeKeyCool what's the status of this PR? |
We reviewed it with @jolelievre yesterday and he added few comments. I think he forgot to apply his review ^^ |
config/config.inc.php
Outdated
|
||
$isNotValidLanguage = !isset($language) || !Validate::isLoadedObject($language); | ||
// `true` if language is defined from multishop or backoffice (`$employee` variable defined) session | ||
$isLanguageDefinedFromSession = (isset($language) && $language->isAssociatedToShop()) || isset($employee); |
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.
$isLanguageDefinedFromSession = (isset($language) && $language->isAssociatedToShop()) || isset($employee); | |
$isLanguageDefinedFromContext = (isset($language) && $language->isAssociatedToShop()) || defined('_PS_ADMIN_DIR_'); |
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.
@MeKeyCool friendly reminder for this replacement and then I will approve the PR 😉
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.
Sorry, I forgot this one ^^'
$useDefaultLanguage = $isNotValidLanguage || !$isLanguageDefinedFromSession; | ||
if ($useDefaultLanguage) { |
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
|
||
// 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 comment
The 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
1db61f7
to
226bc4f
Compare
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.
Thanks @MeKeyCool
hi @MeKeyCool, Thank you for your modification, currently the bad behaviour is corrected, but I find another issue thank to that, as you can see on this video : Untitled_.Jun.28.2022.11_50.AM.mp4at the end, when you return to a single shop and you can't modiy if a languages is enabled or not |
Hi @AureRita , is it possible that you apply all scenari you think are necessary to describe #27617 issue and to share them all in one raw ? I agree it is important to clean the wall feature but it is really a waste of time and energy to wait for your tests one by one. |
Hi @MeKeyCool, As I said "I find another issue thank to that". Sorry to not have all possible tests in my mind. Well I tested if I find this issue without your PR and it's currently not because of your PR, so I can say that your PR is QA Approved Thank you and sorry for wasting your time |
QA approved, well done! Message to the maintainers: do not forget to milestone it before the merge. |
Thanks @MeKeyCool & @AureRita |
My bad, sorry if I have been rude, I thought you asked me to fix another problem ^^' ... |
Thanks @AureRita for finding another issue
When you setup multishop, default Prestashop language is applied to every shop even if it is not available to those shops.
As no "default language" attribute is defined for shops in multishop, I solved this inconsistency by taking the first language available I find for the shop. This way,
@PrestaShop/product-team , are you Ok with this behavior ?