Facebook-for-woocommerce: Facebook for Woocommerce + qTranslate = same problem again

Created on 29 Jan 2018  Â·  33Comments  Â·  Source: facebookincubator/facebook-for-woocommerce

Hello,

I had an issue with qTranslate multilanguage plugin before (https://github.com/facebookincubator/facebook-for-woocommerce/issues/30) but it was fixed and closed. I had no problems till the last Facebook for Woocommerce plugin release, but now I see that the code looks a little bit different and I don't know how to change it again.

Could someone take a look at the closed issue and help me with the same problem?

Thank you.

question

Most helpful comment

Hello! Help me please. I need to solve the same problem to desciption.
This method does not work :(

add_filter( 'facebook_for_woocommerce_integration_prepare_product', 'wc_facebook_qtranslate_fix' );
function wc_facebook_qtranslate_fix($product){
  $product['name'] = preg_replace('/..ru\]([^\[]*)\[.*/i', '$1', $product['name']);
  $product['description'] = preg_replace('/..ru\]([^\[]*)\[.*/i', '$1', $product['description']);
  return $product;
}

All 33 comments

Hi @cesneris ,

Yeah, we are working on performance now by uploading feed (one time http call) instead of products one by one (only for the first time 'get started' to set up all products). That's why the code changed a lot.

You can change this line to :
'name' => preg_replace('/.:lt]([^[])[.*/i', '$1', $woo_product->get_title());
another post_content you want is here

Let me know if you need more help.

Thanks.

Hello again,

Thanks, but I think I'm doing something wrong. Or maybe the code you wrote me might be incorrect.

Do you mean 418-419 lines?

Now code line looks like this:

'name' => WC_Facebookcommerce_Utils::clean_string( $this->get_title()),

How exactly should it look? Thanks!

Hi @cesneris ,

Can you try:
'name' => preg_replace('/.:lt]([^[])[.*/i', '$1', $this->get_title())

Let me know if you need more helps.

Thanks.

I'm sorry, but I guess it doesn't work.

I try many variations to edit fbproduct.php file but either I get error and my sites crashes, or facebook for woocommerce extension page becomes blank.

Hope you can still help me.

Hello again,

It sucks that we broke this. I wonder if we can make a more permanent fix for qTranslate, but I think there is a fix you can do that will require no maintenance as we update the plugin in the future.

This fix involves using a filter on the product data itself, https://github.com/facebookincubator/facebook-for-woocommerce/blob/master/includes/fbproduct.php#L467

Let me try out my idea this week and make sure it works then reply back. In the meantime I recommend using the older version of the extension which works with the fix.

Hi @cesneris

I have a solution for you to try. Try inserting this code:

add_filter( 'facebook_for_woocommerce_integration_prepare_product', 'wc_facebook_qtranslate_fix' );
function wc_facebook_qtranslate_fix($product){
  $product['name'] = preg_replace('/..lt\]([^\[]*)\[.*/i', '$1', $product['name']);
  return $product;
}

In this location of this file (or near the top of any other file, it should work anywhere) :
https://github.com/facebookincubator/facebook-for-woocommerce/blob/master/facebook-for-woocommerce.php#L27

I have tested this on my test server. Assuming the product title still looks like [:lt] Lithuanian Title [:en] English Title it works. This solution should also work forever with no breaking changes caused by our updates, since it uses a filter.

Finally! Great, thanks, it looks like it's working fine right now.

So as I understood I can just update to the newer versions in the future and code won't change?

Glad I could help! I hope we can support qTranslate more officially in the future, but that would mean having some advanced options and a language selector.

If you update, you will have to insert the code again, unfortunately. However you shouldn't have this same problem as before where we changed something and the fix no longer works, that's what I meant to say.

Hi,

We're experiencing the same issue with a danish shop: [:en]English Title[:da]Dansk titel[:].
Is it sufficient to simply add the filter to the file "facebook-for.woocommerce.php" changing "lt" to "da", or should we modify any other files in order to remove the english title and the qTranslate tags?

Thanks in advance.
Michael

Well, try it. I think it should work as well if you just change it to "da" instead of "lt".
I just simply add this code to facebook-for-woocommerce.php file and it works perfectly.

You can add it, try to add new product and see what happens. If it doesn't work, just remove the code.

Thank you, I'll test it right away :)

Hi @dmitridr,

Unfortunately this doesn't solve our problem where we would like to exclude both the english text and the language tags and only display the danish subject: [:en]English Title[:da]Danish Title[:] should become Danish Title.

Would you be so kind to provide us with a solution? Simply changing lt to da doesn't do the job. I guess it's because the tags are reversed compared to @cesneris's setup.

Best regards,
Michael

Hi @jerndorff

You're right, it's because the tags are reversed. Try changing,

$product['name'] = preg_replace('/..lt\]([^\[]*)\[.*/i', '$1', $product['name']);

to

$product['name'] = preg_replace('/.*da\]([^\[]*)\[.*/i', '$1', $product['name']);

does it work? The key is the extra .* at the beginning which will match everything, whereas before it was . which would only match one character.

Hi @dmitridr

It does, at least in my test environment! Thank you! I'll have a go at it :)

I made this version yesterday, which allow you to choose between both languages via either group 1 ($1: English) or group 2 ($2: Danish):
$product['name'] = preg_replace('/..en\]([^\[]*)..da\]([^\[]*)\[.*/i', '$2', $product['name']);

That'll work too! Thanks for posting it, it might help someone else out as well.

How can I solve same issue for desciption?

Hello! Help me please. I need to solve the same problem to desciption.
This method does not work :(

add_filter( 'facebook_for_woocommerce_integration_prepare_product', 'wc_facebook_qtranslate_fix' );
function wc_facebook_qtranslate_fix($product){
  $product['name'] = preg_replace('/..ru\]([^\[]*)\[.*/i', '$1', $product['name']);
  $product['description'] = preg_replace('/..ru\]([^\[]*)\[.*/i', '$1', $product['description']);
  return $product;
}

Hi storn92!

This work for me. :) Add "this code" after "add_filter( 'facebook_for_woocommerce_integration_prepare_product', 'wc_facebook_qtranslate_fix' );................."

---this:
add_filter( 'facebook_for_woocommerce_integration_prepare_product', 'wc_facebook_qtranslate_fix_description' );
function wc_facebook_qtranslate_fix_description($product_data){
$product_data['description'] = preg_replace('/.hu]([^[])[.*/i', '$1', $product_data['description']);
return $product_data;
}

It'll be better using qTranslate-X functions:

add_filter( 'facebook_for_woocommerce_integration_prepare_product', 'wc_facebook_qtranslate_fix' );
function wc_facebook_qtranslate_fix($product){
global $q_config;
$product['name'] = qtranxf_use($q_config['language'], $product['name'], true, false);
return $product;
}

Or, if you want to choose manually a language, e.g. Spanish:

add_filter( 'facebook_for_woocommerce_integration_prepare_product', 'wc_facebook_qtranslate_fix' );
function wc_facebook_qtranslate_fix($product){
$product['name'] = qtranxf_use('es', $product['name'], true, false);
return $product;
}

Hi asedano!

This code work for description too?

Thx

It's what qtranslate uses to translate every encoded string so I think that
it should work

Enviado desde mi Android

El jue., 11 oct. 2018 20:52, koikaam notifications@github.com escribió:

Hi asedano!

This code work for description also?

Thx

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/facebookincubator/facebook-for-woocommerce/issues/241#issuecomment-429077046,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AC-dF1qtOJE_n8_2JysUzu-OZTOvOr9Sks5uj5N4gaJpZM4RwHj-
.

Thank you! I try it. :)

It'll be better using qTranslate-X functions:

add_filter( 'facebook_for_woocommerce_integration_prepare_product', 'wc_facebook_qtranslate_fix' );
function wc_facebook_qtranslate_fix($product){
global $q_config;
$product['name'] = qtranxf_use($q_config['language'], $product['name'], true, false);
return $product;
}

Or, if you want to choose manually a language, e.g. Spanish:

add_filter( 'facebook_for_woocommerce_integration_prepare_product', 'wc_facebook_qtranslate_fix' );
function wc_facebook_qtranslate_fix($product){
$product['name'] = qtranxf_use('es', $product['name'], true, false);
return $product;
}

Amazing! Its work, thank you!

For description must be one more line.
$product['description'] = qtranxf_use('ru', $product['description'], true, false);

But I have another problem.
Сase insensitive description

For example
on the site description: Lorem Ipsum
on facebook description: lorem ipsum

Does anyone know how to fix this?

can you help me also for the short descripion
i use this line but nothing happent
$product['short_description'] = qtranxf_use('el', $product['short_description'], true, false);

can you help me also for the short descripion
i use this line but nothing happent
$product['short_description'] = qtranxf_use('el', $product['short_description'], true, false);

Hello, what exactly problem you are facing with the short description? I see that the newest version of Facebook for Woocommerce plugin (1.10.2) has the option in settings page to choose what description to use for facebook's description. Also, it does not cause me any problems. It shows only one language. If it shows you both languages, you can add a description in product's page which will be used only for Facebook.

its about 500 products to shop so its a little bit difficult to move all short descriptions to descriptions
i just want to show only one language to facebook and not get the [:el]title[:en]title[:]

its about 500 products to shop so its a little bit difficult to move all short descriptions to descriptions
i just want to show only one language to facebook and not get the [:el]title[:en]title[:]

I see some changes in the code so I experience the same issues as well. Once I figure out I let you know.

Hi, I have the same problem, still continue to show [:it]__[:] tag on facebook shop page!
Any solutions?
FireShot Screen Capture #138 - 'Forevhair Extensions I Facebook' - www_facebook_com_700010936794039_shop_all_products__ref_code=mini_shop_page_card_ct
I'm trying all previous solutions, but still don't working for me, please help me asap!

Hi, I have the same problem, still continue to show [:it]__[:] tag on facebook shop page!
Any solutions?
FireShot Screen Capture #138 - 'Forevhair Extensions I Facebook' - www_facebook_com_700010936794039_shop_all_products__ref_code=mini_shop_page_card_ct
I'm trying all previous solutions, but still don't working for me, please help me asap!

Hi, I actually just moved from qtranslate to WPML. It's much more complexed but at the same more useful, and because of SEO issues and other problems with qtranslate, I decided to move it to WPML. But the moving process also took lots of preparation. If you need any tips how to move, I could help.

yes, please help me to move to WPML please @cesneris

@cesneris I read that it is better to uninstall FfW and use Pixel Caffeine, how do you feel about that?

Hi, I have the same problem, still continue to show [:it]__[:] tag on facebook shop page!
Any solutions?
FireShot Screen Capture #138 - 'Forevhair Extensions I Facebook' - www_facebook_com_700010936794039_shop_all_products__ref_code=mini_shop_page_card_ct
I'm trying all previous solutions, but still don't working for me, please help me asap!

@cesneris Did you solve this?

Was this page helpful?
0 / 5 - 0 ratings