Skip to content
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

Merged

Conversation

MeKeyCool
Copy link

@MeKeyCool MeKeyCool commented May 2, 2022

Questions Answers
Branch? 1.7.8.x
Description? Multishop translations interfered with BO ones
Type? bug fix
Category? BO
BC breaks? no
Deprecations? no
Fixed ticket? Fixes #27617
Related PRs Na.
How to test?
  • 1.- Make a fresh installation of prestashop with two languages, for example English and Spanish.
  • 2.- configure the user's language in Spanish. All BO menus appear in Spanish.
  • 3.- activate the multistore
  • 4.- Set up a second store.
  • 5.- configure English only for store 1
  • 6.- configure Spanish only for store 2
  • 7.- You should have all translations Ok (menus, pages, etc. for BO and every shops).
Possible impacts? This change could impact translations for multishop (FO and BO)

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,

  • If you have only one language available, it will be used.
  • If you have several languages allowed,
    • If default Prestashop language is one of them, it will be used.
    • If default Prestashop language is not allowed for this shop, the first time you visit, it may be "random" language but once you select your language, it will be taken from your session.

@PrestaShop/product-team , are you Ok with this behavior ?

@MeKeyCool MeKeyCool requested a review from a team as a code owner May 2, 2022 15:05
@prestonBot prestonBot added 1.7.8.x Branch Bug fix Type: Bug fix labels May 2, 2022
$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] )

Copy link
Member

@PululuK PululuK May 2, 2022

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);

Copy link
Author

@MeKeyCool MeKeyCool May 2, 2022

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.

@MeKeyCool MeKeyCool force-pushed the bugfix/27617_fix_bo_translations branch 2 times, most recently from 1c9c2b4 to 106ca04 Compare May 2, 2022 15:46
$isLanguageDefinedFromCustomSession = (isset($language) && $language->isAssociatedToShop()) || isset($employee);

$useDefaultLanguage = $isNotValidLanguage || !$isLanguageDefinedFromCustomSession;
if ( $useDefaultLanguage ) {
Copy link
Contributor

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.

Suggested change
if ( $useDefaultLanguage ) {
if ($useDefaultLanguage) {

Copy link
Author

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 ?

Copy link
Contributor

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.

Copy link
Author

@MeKeyCool MeKeyCool May 4, 2022

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 ☺️

@MeKeyCool MeKeyCool force-pushed the bugfix/27617_fix_bo_translations branch from 106ca04 to 193d423 Compare May 4, 2022 11:03
atomiix
atomiix previously approved these changes May 4, 2022
@matks matks changed the title Fix bo translations Fix back-office translations when multishop and multiple languages May 4, 2022
matks
matks previously approved these changes May 4, 2022
Copy link
Contributor

@matks matks left a 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!

@matks matks added the Waiting for QA Status: action required, waiting for test feedback label May 4, 2022
config/config.inc.php Outdated Show resolved Hide resolved
Copy link
Contributor

@Progi1984 Progi1984 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small feedback

@AureRita AureRita self-assigned this May 5, 2022
@AureRita
Copy link
Contributor

AureRita commented May 6, 2022

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)
image

but there is another issue following this pr, you can see it on this video :

Untitled_.May.6.2022.2_42.PM.mp4

Currently, 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

@MeKeyCool
Copy link
Author

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) image

but there is another issue following this pr, you can see it on this video :
Untitled_.May.6.2022.2_42.PM.mp4

Currently, 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.
I'll investigate more ^^

@AureRita
Copy link
Contributor

AureRita commented May 6, 2022

It's maybe because of this option select :

(it's on another pr, that why the default country is Canada)
image

Currently my browser is in Canadian ( that allow me to have the english languages select in first and the french in the second part ) that maybe have a priority on the selection of the store's language ?

@MeKeyCool
Copy link
Author

It's maybe because of this option select :

(it's on another pr, that why the default country is Canada) image

Currently my browser is in Canadian ( that allow me to have the english languages select in first and the french in the second part ) that maybe have a priority on the selection of the store's language ?

Hmmm 🤔 ...
Yes this option looks suspect ... How should we manage if we have to set language from browser with default language en and shop is configured to take french or spanish language ?

@MeKeyCool
Copy link
Author

MeKeyCool commented May 6, 2022

Does the bug happen if no multishop configured ?

@AureRita
Copy link
Contributor

AureRita commented May 6, 2022

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

@MeKeyCool MeKeyCool dismissed stale reviews from matks and atomiix via 1d151ce May 9, 2022 07:51
@MeKeyCool MeKeyCool force-pushed the bugfix/27617_fix_bo_translations branch from 193d423 to 1d151ce Compare May 9, 2022 07:51
@MeKeyCool MeKeyCool mentioned this pull request May 9, 2022
2 tasks
@Progi1984 Progi1984 removed the Waiting for QA Status: action required, waiting for test feedback label May 10, 2022
Comment on lines +229 to +230
$useDefaultLanguage = $isNotValidLanguage || !$isLanguageDefinedFromSession;
if ($useDefaultLanguage) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$useDefaultLanguage = $isNotValidLanguage || !$isLanguageDefinedFromSession;
if ($useDefaultLanguage) {
if ($isNotValidLanguage || !$isLanguageDefinedFromSession) {

Copy link
Contributor

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

Copy link
Contributor

@Progi1984 Progi1984 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A last comment

@matks
Copy link
Contributor

matks commented Jun 14, 2022

@MeKeyCool what's the status of this PR?

@MeKeyCool
Copy link
Author

@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 ^^
For me the PR is okay, I juste received some comments about wording that I want to fix.


$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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$isLanguageDefinedFromSession = (isset($language) && $language->isAssociatedToShop()) || isset($employee);
$isLanguageDefinedFromContext = (isset($language) && $language->isAssociatedToShop()) || defined('_PS_ADMIN_DIR_');

Copy link
Contributor

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 😉

Copy link
Author

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 ^^'

Comment on lines +229 to +230
$useDefaultLanguage = $isNotValidLanguage || !$isLanguageDefinedFromSession;
if ($useDefaultLanguage) {
Copy link
Contributor

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()) {
Copy link
Contributor

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

@MeKeyCool MeKeyCool force-pushed the bugfix/27617_fix_bo_translations branch from 1db61f7 to 226bc4f Compare June 23, 2022 09:49
Copy link
Contributor

@jolelievre jolelievre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @MeKeyCool

@matthieu-rolland matthieu-rolland added the Waiting for QA Status: action required, waiting for test feedback label Jun 24, 2022
@AureRita
Copy link
Contributor

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

at the end, when you return to a single shop and you can't modiy if a languages is enabled or not

@AureRita AureRita added Waiting for author Status: action required, waiting for author feedback and removed Waiting for QA Status: action required, waiting for test feedback labels Jun 28, 2022
@MeKeyCool
Copy link
Author

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

at 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 ?
Then I'll fix them all in one round.

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.
(And IMO it is not a good way to promote contributions)

@AureRita
Copy link
Contributor

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

@AureRita AureRita added QA ✔️ Status: check done, code approved and removed Waiting for author Status: action required, waiting for author feedback labels Jun 29, 2022
@prestonBot
Copy link
Collaborator

QA approved, well done! Message to the maintainers: do not forget to milestone it before the merge.

@Progi1984 Progi1984 added this to the 1.7.8.7 milestone Jun 29, 2022
@Progi1984 Progi1984 merged commit 02d4bb7 into PrestaShop:1.7.8.x Jun 29, 2022
@Progi1984
Copy link
Contributor

Thanks @MeKeyCool & @AureRita

@MeKeyCool
Copy link
Author

MeKeyCool commented Jun 29, 2022

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

My bad, sorry if I have been rude, I thought you asked me to fix another problem ^^' ...
Thanks for your precise analysis ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.7.8.x Branch Bug fix Type: Bug fix QA ✔️ Status: check done, code approved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants