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

Attribute option translation #3117

Open
Nuranto opened this issue Nov 20, 2023 · 4 comments
Open

Attribute option translation #3117

Nuranto opened this issue Nov 20, 2023 · 4 comments
Assignees

Comments

@Nuranto
Copy link
Contributor

Nuranto commented Nov 20, 2023

Preconditions

Magento Version : 2.4.6-p3

ElasticSuite Version : 2.11.4.1

Steps to reproduce

  1. Create filterable attribute with custom source model : [ ['value'=>1, 'label' => __('Apple')->render()], ['value'=>2, 'label' => __('Car')->render()]. ]
  2. Add in fr_FR translation file : "Car,Voiture" and "Apple,Pomme"
  3. Reindex catalogsearch_fulltext
  4. Check filters on your fr_FR store

Expected result

  1. Filter options are in french (Pomme, Voiture)

Actual result

  1. Filter options are in english (Apple, car)

Additional informations

Quick fix I found is to manually load translations in my source model :

        $areaList = ObjectManager::getInstance()->get(\Magento\Framework\App\AreaList::class);
        $area = $areaList->getArea($this->appState->getAreaCode());
        $area->load(\Magento\Framework\App\Area::PART_TRANSLATE);

But that's obviously not a good solution, that should be done somewhere in smile module. I did not found the correct place to do it though, we should probably emulate store somewhere in index rebuilding process.

EDIT : This solution does not work, it loads the translations, yes, but does not reload it for each store. So it just solve the problem to one store, and move the issue to the other one. So we definitely need store emulation here.

@vahonc vahonc self-assigned this Nov 20, 2023
@vahonc
Copy link
Collaborator

vahonc commented Nov 28, 2023

Hello @Nuranto,

I was able to reproduce your issue. Indeed the attribute options translation does not work through any language (e.g. fr_FR) translation file no matter if it's using the custom source model or default. This is due to the fact that Elasticsearch indexes an Apple value, so if you try to search Pomme you don't find any products.

We're not a huge fan of adding an emulate store somewhere in the index rebuilding process. As an easy solution, Magento proposes a way to add translation via Admin Panel -> Attribute Properties -> Manage Options (Values of Your Attribute). Therefore I have a question, why you are using a custom source model and why is translation via Admin not suitable for you?

BR,
Vadym

@Nuranto
Copy link
Contributor Author

Nuranto commented Nov 29, 2023

Hi @vahonc,

It reminds me a similar question from Romain here : #2932

Here are some examples :

  • An attribute that you want custom methods for. For example, a month attribute explained in Facet sort order issue on attributes with custom source model #2932
  • An attribute that has a dynamic source. For example, you may want to create a Model/DB schema/CRUD for brands, and link those to products, so you can then easily, for instance, add a link to the custom brand page on product view, or display extra brand informations, etc.. Native attribute example : country_of_manufacture (Both example are not very relevant regarding translation, but you get the idea)
  • An attribute that you don't want administrators to mess with options. Native attribute examples :status, price_type, shipment_type, ...

Maybe store emulation is not necessary. Maybe locale emulation is enough (Magento\Framework\Locale\Resolver::emulate()) ?

@romainruaud
Copy link
Collaborator

  • An attribute that has a dynamic source. For example, you may want to create a Model/DB schema/CRUD for brands, and link those to products, so you can then easily, for instance, add a link to the custom brand page on product view, or display extra brand informations, etc.. Native attribute example : country_of_manufacture (Both example are not very relevant regarding translation, but you get the idea)

In any case, this is exactly what does these 2 modules :

https://github.com/Smile-SA/magento2-module-custom-entity
https://github.com/Smile-SA/magento2-module-custom-entity-product-link (this one requires Elasticsuite)

@Nuranto
Copy link
Contributor Author

Nuranto commented Dec 6, 2023

I wasn't aware about those modules, and it looks great. I'll definitely look into it, however that won't solves the other 2 cases

Nuranto added a commit to webcooking/elasticsuite that referenced this issue Dec 15, 2023
Nuranto added a commit to webcooking/elasticsuite that referenced this issue Dec 15, 2023
Nuranto added a commit to webcooking/elasticsuite that referenced this issue Jan 10, 2024
@vahonc vahonc removed their assignment Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants