• We have a Spanish language site that we recently redesigned using full site editing, including using woocommerce blocks to build the product pages. We noticed several strings that aren’t being translated into Spanish, for instance in the product page, the review count next to the product name (see screenshot) and in the store page, once you add a product the button text changed to “1 in cart” (see screenshot).

    We figured out these were comming from Woocommerce because we turned off all other plugins and also switched to the WP default theme. So we did a search in the files themselves and found this:

    
    	const reviewsCount = sprintf(
    		/* translators: %s is referring to the total of reviews for a product */
    		_n(
    			'(%s customer review)',
    			'(%s customer reviews)',
    			reviews,
    			'woo-gutenberg-products-block'
    		),
    		reviews
    	);

    This comes from woocommerce/packages/woocommerce-blocks/assets/js/atomic/blocks/product-elements/rating/block.tsx

    So here is the issue: we have a translation in place for woocommerce text domain, but this is a different text domain ‘woo-gutenberg-products-block’ and we can’t figure out how to use it. We know there is a separate plugin that includes all the same blocks that uses that text domain, we’ve downloaded the language files and placed them both in wp-content/languages/plugins and wp-content/languages/woocommerce, but it’s doing nothing. We can’t access these strings from Locotranslate.

    Any help would be greatly appreciated!

    (If you go to the linked product page, you will see it says “ver valoraciones” instead of “# customer reviews”, it’s not translated, I just changed it with CSS)

    • This topic was modified 2 years, 4 months ago by Yui.
    • This topic was modified 2 years, 4 months ago by Mat.

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Tim W

    (@timwhitlock)

    JavaScript translation in WordPress is a complicated topic. Before this thread get’s messy, a quick question:

    Did you install only the language files for the “woo-gutenberg-products-block” text domain? Or did you also install the plugin that provides that text domain? If so, did you enable it?

    Thread Starter Mat

    (@mrosero)

    The plugin is installed but not active!

    • This reply was modified 2 years, 4 months ago by Mat.
    Plugin Author Tim W

    (@timwhitlock)

    Assuming the plugin in question is responsible for loading the string you need into the same page that you need it, then it will have to be enabled.

    The code you’ve posted cannot load additional text domains, it can only attempt to access what’s been made available in the page. That requires the correct JSON files have been loaded based on the registered scripts. This is the responsibility of the plugin that owns the domain. My plugin cannot force this to happen.

    Next question, is the string you need already translated in the files you installed? If so, can you find it in a JSON translation file? If so, is that file being loaded into the page?

    Thread Starter Mat

    (@mrosero)

    Sorry about the late reply! We ran into other, unrelated issues and were busy with those.

    The string is already translated in the po and mo files (generated from PoEdit), and they are in wp-content/languages/plugins/

    Plugin Author Tim W

    (@timwhitlock)

    Re my follow up question —

    can you find it in a JSON translation file? If so, is that file being loaded into the page?

    I don’t know if POEdit generates JSON files for script translation. Can you verify the above?

    I suggest you open up the PO file in the Loco Translate editor, and make any edit in order to press Save and recompile the translation files. This operation will save JSON files providing the PO has the correct file references. See the many caveats.

    As mentioned already, my plugin cannot force the above code to load the correct JSON file from another plugin. In order for the translations to be available, the original script to which this string belongs must have been registered on the same page as your code, and the related JSON must be on disk.

    Thread Starter Mat

    (@mrosero)

    Before we go on to the JSON issue, and sorry I didn’t lead with this:

    The WooCommerce Blocks plugin can’t be activated, when I try I get this message: “The WooCommerce Blocks plugin has been deactivated as the latest improvements are now included with the WooCommerce plugin.” (https://paste.pics/b4aa3eed44a5ae10a2eafbc8fe448c0c)

    Does this mean there is no way to translate the strings that have the ‘woo-gutenberg-products-block’ textdomain? Like I said, this is coming from inside Woocommerce, but doesn’t use the woocommerce textdomain, so it isn’t showing up there.

    I’m stumped, and really hoping there is a fix for this issue. Thank you again for your help and patience.

    • This reply was modified 2 years, 3 months ago by Mat.
    Plugin Author Tim W

    (@timwhitlock)

    I don’t see that I’m in a position to “fix” any issue here, as this all falls outside the remit of my plugin. I can help you identify whether certain JSON files are generated when a PO file is saved, but this is rather pointless if the plugin can’t be activated and seems redundant.

    I think your questions are better directed at whoever is responsible for the code you originally posted. If the text domain being referenced belongs to a deprecated plugin, then it seems like a mistake and should be changed to use the main woocommerce plugin text domain.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Problem translating Woocommerce blocks’ is closed to new replies.