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

Cannot translate the values of "Custom Product Attributes" of "Variable Product" in Woocommerce #277

Closed
herrvigg opened this issue Jun 22, 2018 · 30 comments
Labels
bug Something isn't working, reproducible legacy issue Legacy issue imported from original repo need info The submitter must provide more info

Comments

@herrvigg
Copy link
Collaborator

Issue by ventouris
Saturday Oct 03, 2015 at 09:56 GMT
Originally opened as qTranslate-Team/qtranslate-x#277


I installed the latest version of both qtranslate-x and Woocommerce for qtranslate-x. However, I cannot translate the values of the attributes in Woocommerce. I use the following for the label:

[:en]Action[:de]Vorgang[:]

and this one for the values:

[:en]Renting | Return[:de]Anmietung | Rückgabe[:]

The label works like a charm :) The values doesn't work. I don't have any error on the console.

The HTML result is this one:

<select id="vorgang" class="" name="attribute_vorgang" data-attribute_name="attribute_vorgang"><option value="">Choose an option</option><option value="[:en]Renting" class="attached enabled">Renting</option><option value="Return[:de]Anmietung" class="attached enabled">(DE) ReturnAnmietung</option><option value="Rückgabe[:]" class="attached enabled"></option></select>

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Sunday Oct 04, 2015 at 21:26 GMT


I have not tried to reproduce, but my guess would be that the problem is in '|' character. Do you have the problem if you remove it? I remember some fields in Woocommerce may have multiple values separated by '|', so it may interfere. You would have to escape it if needed. Please, let me know if my guess is correct.

@herrvigg herrvigg added bug Something isn't working, reproducible legacy issue Legacy issue imported from original repo need info The submitter must provide more info labels Jun 22, 2018
@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Sunday Oct 04, 2015 at 21:27 GMT


BTW, why do you need to do raw translation? Do you use integrating plugin: https://wordpress.org/plugins/woocommerce-qtranslate-x/

@herrvigg
Copy link
Collaborator Author

Comment by ventouris
Sunday Oct 04, 2015 at 21:53 GMT


@johnclause You are right. The problem is the "|" character. The vertical line that used for the select values. I am not sure how I can escape it. As for the woocommerce-qtranslate-x:

When I first installed it, I had the two flags about the section, but changing the language kept the same content for the attributes. Didn't use it for the translation. I tried to update the qtranslate-x from the Github directly from the source code, by uploading the new files from the FTP and since then, the woocommerce-qtranslate-x doesn't work. I cannot see the flags any more.

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Sunday Oct 04, 2015 at 22:14 GMT


I am not sure how I can escape it

Find the HTML code like &#xxxx; for | and try it. Otherwise ask Woo how they designed it.

changing the language kept the same content for the attributes

You probably need to resave all attributes after installing integrating plugin on a developed site, I recall something like this.

I cannot see the flags any more

Just install everything nicely, properly and freshly. People report that it all actually works well enough. It does a few things that unachievable with simple raw translations, sending emails in the language of order, for example.

I am closing this issue for now, we can still write into a closed issue, or we can re-open it, if needed.

@herrvigg
Copy link
Collaborator Author

Comment by ventouris
Monday Oct 05, 2015 at 07:22 GMT


I removed them all and installed from the start. Now, the flags are back there, but even if I save the attributes and update the page, the content changed for both the languages. :(

Edit: Plus, when I use the escaped code, after the update, they turned to "|" again.

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Thursday Oct 08, 2015 at 05:24 GMT


Cannot you use different characters instead of '|'? Or then you have to dig out the place in the code and see how easy it would be to adjust it. Ask Woo what do they suggest? This problem is unrelated to qtx.

@herrvigg
Copy link
Collaborator Author

Comment by ventouris
Thursday Oct 08, 2015 at 07:53 GMT


I think that that problem of the character "|" is a side issue and not the main one. The main issue that it is related with qtx is that the flags on Product Data table don't work. You change flags, make changes on product data, save both attributes and page and it changes it for both languages. There was also another issue about it, so I am not alone on this.

And just show that the same happened on the Yoast SEO table. Even if I have enabled the Yoast & qtranslate X plugin. I can move between the two flags, but the content doesn't change at all.

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Thursday Oct 08, 2015 at 15:58 GMT


Maybe those fields are not multilingual and need integration? Do they have a color bar on the left side like other multilingual fields do?

Please provide step-by-step instructions how to reproduce the problem, preferably under a publicly available theme like "Storefront" and the minimum number of active plugins. For example, you mentioned "value of attributes", but I do not know which admin or front page do you refer to, etc.

If there is a similar issue, please, cite it here with a link.

Do you have any errors in Java Console, which can be opened with Ctrl+Shift+J? Errors in error_log? Have you done the initial troubleshooting: https://qtranslatexteam.wordpress.com/troubleshooting/? What did you find out?

@herrvigg
Copy link
Collaborator Author

Comment by ventouris
Friday Oct 09, 2015 at 09:10 GMT


Install the qTranslate-X either from Wordpress directly or from Github. Download Yoast and Woocommerce support from Github is the Wordpress has an older version. Install them on admin.

Here is a screenshot:
screenshot

The latest version of Yoast SEO & qTranslate add the colors on the inputs and makes them translatable. The one from Wordpress admin, doesn't. But as you can see on the product data table, there isn't a flag and the inputs that I am referring as attributes with labels and values don't have a translatable color.

Nothing weird on the Dev Console.

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Saturday Oct 10, 2015 at 06:34 GMT


Indeed, there is a bug in the latest qtx, otherwise front end should work well. Custom Variable products were never integrated yet, but raw values like yours should work. Maybe it is more logical to have it like "[:en]Renting[:de]Anmietung[:] | [:en]Return[:de]Ruckgabe[:]", or it may not be important, I am not sure. The latter should work by design, the original version might work by accident.

Anyway, I will update plugin "Woo&qtx" shortly to fix the problems.

@herrvigg
Copy link
Collaborator Author

Comment by ventouris
Saturday Oct 10, 2015 at 09:33 GMT


That's great! Please, let me know so I can test any side effects and possible fixes or bugs. Thank you :)

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Sunday Oct 11, 2015 at 04:07 GMT


I updated plugin https://github.com/qTranslate-Team/woocommerce-qtranslate-x at GitHub. Could you please test it? Update qTranslate-X to the latest 3.4.6.1 too.

Please, read section "Known Issues" before testing, in order not to report what is already known.

"Custom Product Variations", which was your original trouble, has never been finished. Woocommerce has done it in an unexpected way, so it is unclear how to integrate that piece, but raw format should work. Although, most people use "Product Attributes" instead, which work more stable.

@herrvigg
Copy link
Collaborator Author

Comment by ventouris
Monday Oct 12, 2015 at 13:34 GMT


It seems that it works like a charm. I did almost a few general tests. I will do more in the week. If you want, we can close the issue and in case I find a related bug, I can open it again :)

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Monday Oct 12, 2015 at 18:30 GMT


I will probably release it now shortly for everyone. Thank you, @ventouris, very much for all your help.

@herrvigg
Copy link
Collaborator Author

Comment by AleCss81
Thursday Apr 21, 2016 at 11:45 GMT


@johnclause Hi John, I've implemented the solution you've explained here some months ago, but it doesn't work for me

I've put this on custom product value filed:

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Tuesday Apr 26, 2016 at 23:09 GMT


@AleCss81: I think your message is not finished, is it?

@herrvigg
Copy link
Collaborator Author

Comment by AleCss81
Wednesday Apr 27, 2016 at 10:21 GMT


@johnclause hi John, the message were been truncated, I don't know why. Maybe, my code was deleted automatically by editor bacause I haven't used the correct tool to insert code.

Now, I was saying that I've put this code on custom product value: [:en]White [:it]Bianco[:] | [:en]Vanilla [:it]Vaniglia[:] | [:en]Natural [:it]Naturale{:} | [:en]Pink [:it]Rosa[:] | [:en]Grey [:it]Grigio[:]

but it doesn't work. The selection element not show any variations. You can see the result here: http://hugsfactory.com/product/nursery-sack/

Can you help me?

Thank you very much

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Wednesday Apr 27, 2016 at 16:43 GMT


@AleCss81: I cannot reproduce what you describe. It works for me. Try to delete the attributes and re-create them? Contact us if you wish to give us admin access.

@herrvigg
Copy link
Collaborator Author

Comment by AleCss81
Thursday Apr 28, 2016 at 07:26 GMT


@johnclause Hi John, is it working on this page http://hugsfactory.com/product/nursery-sack/?

As you can see in the screenshot, it doesn't work! At least for me, in all browsers.

image

Apart from that, I have used the "contact us" form providing the admin access as you have suggested.

Thank you very much, I wait for a response.

@herrvigg
Copy link
Collaborator Author

Comment by dieSuse
Thursday Apr 28, 2016 at 11:35 GMT


Hi,

I had the same problem as AleCss81. It took me crazy for days and the solution above didn't work for me neither.

I found out that some translations __() were not correct in class WC_Product_Variable method get_variation_attributes(), so that the result variation array was always empty. I derived an own class My_WC_Product_Variable and changed the code in get_variation_attributes().

Maybe it was not the cleanest way but it worked for me.

Regards,
Suse.

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Thursday Apr 28, 2016 at 18:36 GMT


@dieSuse: could you display your changes, so that @AleCss81 could use the same solution until we come up with a better one?

@herrvigg
Copy link
Collaborator Author

Comment by AleCss81
Friday Apr 29, 2016 at 08:56 GMT


@johnclause yes, it could be useful! @dieSuse effectively, I don't understand what you have implemented, can you explain what to do? Many thanks

@herrvigg
Copy link
Collaborator Author

Comment by dieSuse
Friday Apr 29, 2016 at 12:15 GMT


Hi all,

I confess I do not remember in detail but here is my class:

has_child() ) { return $variation_attributes; } $attributes = $this->get_attributes(); foreach ( $attributes as $attribute ) { if ( ! $attribute['is_variation'] ) { continue; } $values = array(); $attribute_field_name = 'attribute_' . sanitize_title( $attribute['name'] ); // Get used values from children variations foreach ( $this->get_children() as $child_id ) { $variation = $this->get_child( $child_id ); if ( ! empty( $variation->variation_id ) ) { if ( ! $variation->variation_is_visible() ) { continue; // Disabled or hidden } $child_variation_attributes = $variation->get_variation_attributes(); if ( isset( $child_variation_attributes[ $attribute_field_name ] ) ) { $values[] = __($child_variation_attributes[ $attribute_field_name ]); } } } // empty value indicates that all options for given attribute are available if ( in_array( '', $values ) ) { $values = $attribute['is_taxonomy'] ? wp_get_post_terms( $this->id, $attribute['name'], array( 'fields' => 'slugs' ) ) : wc_get_text_attributes( $attribute['value'] ); // Get custom attributes (non taxonomy) as defined } elseif ( ! $attribute['is_taxonomy'] ) { $text_attributes = wc_get_text_attributes( $attribute['value'] ); $assigned_text_attributes = $values; $values = array(); // translation $i=0; foreach ($text_attributes as $attr) { $text_attributes[$i] = __($attr); $i++; } // Pre 2.4 handling where 'slugs' were saved instead of the full text attribute if ( version_compare( get_post_meta( $this->id, '_product_version', true ), '2.4.0', '<' ) ) { $assigned_text_attributes = array_map( 'sanitize_title', $assigned_text_attributes ); foreach ( $text_attributes as $text_attribute ) { if ( in_array( sanitize_title( $text_attribute ), $assigned_text_attributes ) ) { $values[] = $text_attribute; } } } else { foreach ( $text_attributes as $text_attribute ) { if ( in_array( $text_attribute, $assigned_text_attributes ) ) { $values[] = $text_attribute; } } } } $variation_attributes[ $attribute['name'] ] = array_unique( $values ); } return $variation_attributes; } ``` } If I remember correctly I found out, that the comparison in line 73/74 has no compliances, so I started at this point. I'm not sure if there was one element translated and the other not or if it was just a thing of upper and lower case... In line 39 I added the translation for the attributes of array $values. And I inserted lines 56-60 and did the translation for each element of array $text_attributes. I think that were the 2 places, where I changed the code. I'm using WooCommerce 2.5.5 and WooCommerce & qTranslate-X 1.3. Regards, Suse

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Saturday Apr 30, 2016 at 04:31 GMT


So, to be precise, one can modify file /wp-content/plugins/woocommerce/includes/class-wc-product-variable.php to achieve the same result.

Line 406

      $values[] = $child_variation_attributes[ $attribute_field_name ];

should be replaced with

      $values[] = __($child_variation_attributes[ $attribute_field_name ]);

which adds translation of the $values[].

Then, at line 419, after lines

} elseif ( ! $attribute['is_taxonomy'] ) {
$text_attributes = wc_get_text_attributes( $attribute['value'] );
$assigned_text_attributes = $values;
$values = array();

inserted a translation of $text_attributes:

// translation
$i=0;
foreach ($text_attributes as $attr)
{
$text_attributes[$i] = __($attr);
$i++;
}

@AleCss81, could you try that and see if your problem goes away?

This would give your temporary fix until we find a permanent solution.

@herrvigg
Copy link
Collaborator Author

Comment by dieSuse
Saturday Apr 30, 2016 at 06:27 GMT


Exactly.
But if you use class-wc-product-variable.php directly, it is not update safe, is it?

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Saturday Apr 30, 2016 at 18:39 GMT


As a temporary change, it is ok, it will be overwritten on next Woo update, but otherwise it is perfectly ok. Let us see if it helps first.

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Saturday Apr 30, 2016 at 19:39 GMT


@AleCss81: I simply followed my own instructions and it worked. I am not sure what step did you miss. I removed an attribute, saved product, added attribute with only two languages enabled, saved product, then re-save variations (do not need to delete them), and the drop down appeared.

The problem is that you cannot edit attribute name after it is created once. You may edit values and variations as you pleased, but not the attribute name.

If you need to change attribute name, then do as above, delete attribute, save product, add attribute again, save product, re-save variations.

Also, do not forget to put [:] at the end, and use [:] consistently, do not mix it with {:}, as you had it.

I hope you will be fine from now on.

@herrvigg
Copy link
Collaborator Author

Comment by AleCss81
Monday May 02, 2016 at 07:31 GMT


Hi @johnclause it works, but if I change the variations to achieve the result expected (i.e White - Grey roses) the dropdown no works anymore. I can't leave "Any" - "Any". Now, it doesn't work anymore also if I leave Any - Any. Don't know why.

Do I have to implement the customization on file /class-wc-product-variable.php you have exlpained above?

Thanks

@herrvigg
Copy link
Collaborator Author

Comment by johnclause
Monday May 02, 2016 at 07:35 GMT


Wow, I did not try that. I did not try @dieSuse 's fix either. Yes, please, try their fix, and I meanwhile will try to work on the issue with complex variations.

@herrvigg
Copy link
Collaborator Author

Comment by AleCss81
Monday May 02, 2016 at 08:31 GMT


Yeah, it works like a charm. Thanks @dieSuse and @johnclause for this excellent support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working, reproducible legacy issue Legacy issue imported from original repo need info The submitter must provide more info
Projects
None yet
Development

No branches or pull requests

1 participant