-
Notifications
You must be signed in to change notification settings - Fork 110
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
Comments
Comment by johnclause 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. |
Comment by johnclause BTW, why do you need to do raw translation? Do you use integrating plugin: https://wordpress.org/plugins/woocommerce-qtranslate-x/ |
Comment by ventouris @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. |
Comment by johnclause
Find the HTML code like &#xxxx; for | and try it. Otherwise ask Woo how they designed it.
You probably need to resave all attributes after installing integrating plugin on a developed site, I recall something like this.
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. |
Comment by ventouris 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. |
Comment by johnclause 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. |
Comment by ventouris 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. |
Comment by johnclause 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? |
Comment by ventouris 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. 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. |
Comment by johnclause 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. |
Comment by ventouris That's great! Please, let me know so I can test any side effects and possible fixes or bugs. Thank you :) |
Comment by johnclause 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. |
Comment by ventouris 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 :) |
Comment by johnclause I will probably release it now shortly for everyone. Thank you, @ventouris, very much for all your help. |
Comment by AleCss81 @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: |
Comment by johnclause @AleCss81: I think your message is not finished, is it? |
Comment by AleCss81 @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: 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 |
Comment by johnclause @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. |
Comment by AleCss81 @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. 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. |
Comment by dieSuse 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, |
Comment by johnclause @dieSuse: could you display your changes, so that @AleCss81 could use the same solution until we come up with a better one? |
Comment by AleCss81 @johnclause yes, it could be useful! @dieSuse effectively, I don't understand what you have implemented, can you explain what to do? Many thanks |
Comment by dieSuse 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 |
Comment by johnclause 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
should be replaced with
which adds translation of the Then, at line 419, after lines
inserted a translation of
@AleCss81, could you try that and see if your problem goes away? This would give your temporary fix until we find a permanent solution. |
Comment by dieSuse Exactly. |
Comment by johnclause 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. |
Comment by johnclause @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. |
Comment by AleCss81 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 |
Comment by johnclause 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. |
Comment by AleCss81 Yeah, it works like a charm. Thanks @dieSuse and @johnclause for this excellent support. |
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>
The text was updated successfully, but these errors were encountered: