This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This thread is resolved. Here is a description of the problem and solution.

Problem:
How can I translate the strings of the custom field labels created with WooCommerce Custom Checkout Field plugin?

Solution:
In includes/ccf.php line 302 we can wrap the 'field_name' with __() to get it auto-registered and translated, like this:

woocommerce_form_field($field['field_id'], array(
                                              'type' => $field['field_type'],
                                              'class' => array($field['field_class']),
                                              'label' => __($field['field_name']),
                                              'required' => $field_required,
                                              'placeholder' => __($field['field_placeholder']),
                                                  ), $checkout->get_value($field['field_id']));

Just remember to make sure that the default text domain is set to automatically register, and then visit the checkout page in the secondary language once to get the string registered and then you can translate it via String Translation.

This topic contains 29 replies, has 2 voices.

Last updated by jannekeW 1 year, 11 months ago.

Assigned support staff: Lauren.

Author Posts
October 10, 2017 at 2:31 pm #1396939

jannekeW

Hi Lauren!
Just got a tip on my website: Translate strings with ST and don't load .mo files: Some themes and plugins have huge .mo files that take a long time to load. WPML already knows the strings in these files and loads only the necessary strings to display each page.

Could the website even more get out of resources???????????????

October 10, 2017 at 4:00 pm #1397061

jannekeW

PS.
If you get the error, just refresh the page and you should get in. That's how I do it..... I won't upload anything to Cloudinary for the next 24 hours.........

October 10, 2017 at 4:08 pm #1397085

Lauren
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

Thanks for sending the file path, that was exactly what I needed 🙂 As for the error, that could make sense if we were both trying to work on the site at the same time.

I made the changes to the inlcudes/ccf.php file. However, when I tried to view the checkout page in the secondary language, I am again seeing the resources error. Please try to load the checkout page in the secondary language, which will register the string for translation. Then you should be able to add the translations via WPML -> String Translation.

That message about .mo files shows up automatically when they are activated. I would suggest trying to load the .mo files and if you find that the performance slows down, you can always switch back to not loading .mo files.

You can also try going to WPML -> Theme and plugin localization and scan the plugins where these strings are contained and then translate via String Translation.

October 10, 2017 at 4:22 pm #1397104

jannekeW

Thanks Lauren!
I will scan it tomorrow or the day after.....I'm on the road tomorrow.... I just saw a notification in my wp-dashboard saying WPML Update isn't complete. Did you do anything and how do I have to configure it? I tried it but I still get the message....... I'm afraid i'm destroying your work when I set it wrong.......

October 10, 2017 at 7:51 pm #1397385

Lauren
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

I haven't done anything to update the plugins, but if that message is not resolved, you can try manually updating the plugins via FTP.

I tried to just refresh the page a couple times after getting the error, but I am unable to load it. Let me know how the scan goes when you get a chance to do it.

October 13, 2017 at 3:16 pm #1400501

jannekeW

Hi Lauren!

After a lot of troubleshooting and stress, I think I solved it now. I don't expect to get any errors anymore....

I've done what you said about the string translation, but there have left a couple of small issues.... All the other one I found and translated successfully.

I've added them attached. I can not find the strings (left all the others) and in some, one of the translations (and string) is missing.
Hope you can fix it!

Bug hug, Janneke

October 13, 2017 at 8:44 pm #1400775

Lauren
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

Thanks for the screenshots.

To translate "Brand", please go to WPML -> Taxonomy Translation. Select Product Brands from the drop down. Scroll all the way down to the bottom where you can see the taxonomy label and click the "+" icons to add the translations.

For "Betaal met iDEAL", this string I found in text admins and have added it to your String Translation table. You need to check the box next to the string, then click " Change language of selected string" and set the correct language. Then you can add the translations.

For the custom checkout field, you will need to follow the previous steps and set the correct string in the default language to translate, and wrap that in the gettext call so it can be translated via the String Translation table.

As for the Checkout button in the mini cart, please open a new ticket, since the original issue of this ticket has been resolved. This will avoid confusion, and the mini cart issue could be related to a number of things so I think it is best that a new ticket be devoted to troubleshooting that issue. Thanks for your understanding!

October 14, 2017 at 10:26 am #1400932

jannekeW

Hi Lauren!

Thanks for your help and explanation!
I found everything and translated it, except one...... the second text in German in the custom checkout (attached). I even deleted it and put a new text in the custom checkout field, hoping the new field would pop up.... Unfortunately .....I also scanned ALL the plugins and found the missing strings, but not the one from the custom checkout field...

Could you please help me with that one? Then I will leave you alone...;-) The German text is a bit different because in Germany they have different shipping/post ways (no Kiala).

Have a nice weekend!
Janneke

October 16, 2017 at 2:46 pm #1402166

Lauren
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

I'm happy to help you find this last string. I am able to log on to your FTP, however, I can't see the site files there. I can see the site files when I login via Direct Admin, but I can't edit the files.

Previously, I had access to the plugin editor, but that access is no longer available. I also installed a plugin called String Locator to try and see if perhaps this string is stored somewhere different, but I also don't have access to this plugin and where it normally shows up under the Tools menu, it is not available for me there. So it seems like there are some access restrictions on your site. Can you perhaps check with your hosting provider and allow me access?

October 16, 2017 at 4:50 pm #1402394

jannekeW

Hi Lauren!
A setting in iThemes caused to deny acces to the plugin editor. I deactivated that option and now you have access to the plugin editor. If you need anything else, just holler!
Thanks again, Janneke

October 16, 2017 at 8:07 pm #1402637

Lauren
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

Wonderful, thanks so much for allowing me access to that again. I checked the file and it looks like I did already add the gettext call to the other field types, so once again I'm consulting with our 2nd Tier team to figure out why this particular string is not in the String Translation table. I will report back as soon as I have something more, and I really appreciate your patience with this.

October 19, 2017 at 5:50 pm #1406325

jannekeW

Hi Lauren!
Did you hear anything from your 2nd Tier team about that missing string dutch/German?

And... I've noticed that some words/strings were in english again, and I couldn't find their strings to translate. But then I checked the box "Translate themes and plugins using WPML's String Translation and always load .mo files as backup" and there they were again!! But when I de-check that box again, the words (city. phone etc. in checkout) turn into english again. How can I get these words in the string so I can de-check that box so I don't use so much memory with the backups?

Thanks, Janneke

October 19, 2017 at 6:10 pm #1406350

Lauren
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

Hi Janneke, there is some additional code you can add to translate the drop down options. However, we are starting to go into heavy modification and have not heard back from the author. In order to make these changes permanent, we need the authors cooperation. Otherwise, each time you have an update, all of these changes will be undone.

In order to translate the checkout field drop down, you will need to add this code to the plugin file mentioned earlier, in the /includes/ccf.php file:

//for select field
                                          $field_options = array_combine(explode(',', $field['field_options']), explode(',', $field['field_options']));
                                          $field_options_first_option[''] = __($field['field_placeholder']);
                                          $field_options = array_merge($field_options_first_option, $field_options);
                                          $field_options = array_map( '__', $field_options );

                                          woocommerce_form_field($field['field_id'], array(
                                              'type' => $field['field_type'],
                                              'class' => array($field['field_class']),
                                              'label' => __($field['field_name']),
                                              'required' => $field_required,
                                              'options' => $field_options,
                                                  ), $checkout->get_value($field['field_id']));

I would suggest reaching out to the Custom Checkout Field author from your end, perhaps that will encourage him to respond to us. And if not, it may be better to choose a different custom checkout plugin that is more compatible with WPML. Here is a list of some that are currently compatible: https://wpml.org/documentation/woocommerce-extensions-compatibility/?wpv_view_count=627943&wpv_post_search=checkout&wpv_filter_submit=Search

As for the translations coming from the .po file, you can create the .po file from the WPML -> Theme and plugin localization page. Then import that file into String Translation at the bottom of the string translation table and you should be able to use String Translation to translate the strings. If you need further assistance with importing/exporting strings, please open a new ticket so that we can focus on that issue, so this one does not get confusing with too many issues 🙂

Thanks for understanding.

October 19, 2017 at 6:48 pm #1406413

Lauren
Supporter

Languages: English (English )

Timezone: America/New_York (GMT-04:00)

One other thing - I realized that I missed telling you this in my previous reply. The label for the second field is now available for translation at WPML -> String Translation. The reason it did not show up before is because the Default domain was excluded from auto registration. I enabled default and now the string appears.

Please let me know if you need any further assistance and I will be happy to help.

October 19, 2017 at 9:14 pm #1406543

jannekeW

Hi Lauren!
Then thats sorted out then! It's working fine now. I will send you another ticket for the .po file.
Thanks again!!
Janneke