Skip Navigation

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 topic contains 9 replies, has 2 voices.

Last updated by Marcos Vinicios Barreto 1 week, 6 days ago.

Assigned support staff: Marcos Vinicios Barreto.

Author Posts
January 17, 2021 at 10:28 am #7862075

calvinY-3

I asked how to do a label translation using the same value of all languages, so that they are all "sync" and only need to select once on the default language, I was given two thread suggest using

https://wpml.org/wpml-hook/wpml_register_single_string/
https://wpml.org/wpml-hook/wpml_translate_single_string/

those threads are
https://wpml.org/forums/topic/translate-labels-only-for-acf-checkbox/#post-7091327
https://wpml.org/forums/topic/acf-labels-are-not-translating-in-the-front-end/

i have trouble how to implement to my twig template, do I add do_action in function.php or at my .twig file

i hope to receive a step by step instruction.

What I have done:
- Delete all the translations of the field groups you did
- Go to WPML > Settings > Post type Translation > Set "Field Group" as "Not Translatable"
- I use a Field Group called Education as test, added a field called Pre-School, field type as checkbox, translation preferences to copy. Choices as
school 1
school 2
school 3

Now I am stuck at how to register the label as string and apply filter to my post? e.g. hidden link

At the moment i use the following code to display the result

{% if fn('get_field', 'pre-school') is not empty %}
<td class="field_title">{{ __('Pre-School', 'realtyspace') }}</td>
<td class="field_value">{{ fn('get_field', 'pre-school')|join('\n')| nl2br }}</td>
{% endif %}

January 19, 2021 at 6:12 pm #7880741

Marcos Vinicios Barreto
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Bahia (GMT-03:00)

Hello,

Thank you for contacting our support service. Although we do our best to provide you with the best reply ever, not always we are able to help when the request involves some custom code. In any case I will do my best to point you on the right direction. So, please, consider:

1 - Do you need to translate only the labels or the values entered? It seems the approach using our hooks is better suitable when you need to translated the entered values (dynamic texts). If you what you need is to translate the fields interface elements (labels, placeholders, etc) then the best approach should be the following: https://wpml.org/documentation/related-projects/translate-sites-built-with-acf/#translating-acf-user-interface

2 - I can't garantee using the hooks it would work in .twig template files, however as the hook docs describes it should follow the same pattern bellow:

do_action( 'wpml_register_single_string', string $context, string $name, string $value );

Where:

$context: is the text domain you would need to search in String Translation to translate the desired strings.
$name: is the string name you would need to translate its value.
$value: is what you need to translate actually.

So, in your case, you could have something like:

$acf_field_labels = get_field_object('pre-school');
if ($acf_field_labels) {
    foreach( $acf_field_labels['label'] as $label ) {
          do_action( 'wpml_register_single_string', 'my-acf-labels', $label, $label );
    }
}

Then, you would need to visit the page in the frontend where such strings appear and reload the page, with this step the mentioned strings are acutally registered for translation. Once done, you would need to search for these strings at WordPress Dashboard > WPML > String Translation and translate them.

Once, translated you should retrieve the information, something like inside the loop where you ned to display that information:

$acf_field_labels = apply_filters( 'wpml_translate_single_string', $label, 'my-acf-labels', $label);

As said, there's no garantee it would work inside .twig templates as it uses a bit of different architecture than the standard WordPress way. Also, I didn't test this code it is just general guidelines on how to proceed as code customizations is not our support scope. For those cases, I recommend you to check this request with one of our WPML contractors at: https://wpml.org/contractors/

Please, check the following resources for reference:

hidden link
https://wpml.org/forums/topic/acf-labels-are-not-translating-in-the-front-end/
https://wpml.org/documentation/getting-started-guide/string-translation/finding-strings-that-dont-appear-on-the-string-translation-page/#auto-register-strings-for-translation

Hope it brings some bit of clarifications on how to proceed, have a nice day.

January 25, 2021 at 3:02 pm #7922879

calvinY-3

According to this thread: https://wpml.org/forums/topic/translate-labels-only-for-acf-checkbox/#post-7091327 i use the
value: label approach
meaning i want to translate label, but by inputting
value: EN label
value: CN label
in the translated groups, trying output the same value with different translation labels didn't work for me

does this approach: https://wpml.org/documentation/related-projects/translate-sites-built-with-acf/#translating-acf-user-interface

meaning i have to translate the value?

January 25, 2021 at 3:06 pm #7922907

calvinY-3

it doesn't matter to me whether to translate value or label, since the select/checkbox options are fixed and cannot add new custom value.

all i want is to display a value(s) inside a translated group at front-end, i believe the only difference if the values are changed, value translation will not pick up the changes require new translation, however for label translation, even with the same value, the labels can be changed and re-translated.

however for me, the value is the school names, the only reason i used label is for translation with the approach mentioned above.

correct me if i got these concepts incorrectly

January 26, 2021 at 1:42 am #7926411

Marcos Vinicios Barreto
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Bahia (GMT-03:00)

Hello,

Thank you for the updates. Your request is still a bit confusing for me, in your initial request you mention the following:

I asked how to do a label translation using the same value of all languages, so that they are all "sync" and only need to select once on the default language, I was given two thread suggest using

It makes me to conclude you need to keep the same checkbox field name, but to show a different label according the language, if it is the case, then what you need is to translate the interface elements of the fields groups as https://wpml.org/documentation/related-projects/translate-sites-built-with-acf/#translating-acf-user-interface explains.

Please, let me know if it attends your needs, if not, please, elaborate youy request better, maybe adding some screenshots and a concrete sample of what you need to achieve, it will help me to understand your request into details. Have a nice day.

January 26, 2021 at 4:10 pm #7933787

calvinY-3

this is my real initial request thread in 2019: https://wpml.org/forums/topic/field-groups-and-field-choice-translation/

the reason why i stated "I asked how to do a label translation using the same value of all languages" because this is the method being suggested by WPML

what i want is to have my value (or label) to be translated automatically at front end without have to do them separately of each language, back to my example, i was told to use the following method

create an ACF field (translatable) name called "school", field type as checkbox
for ENG
school 1: ABC school
school 2: BBC school
school 3: CCC school

for CN
school 1: ABC學校
school 2: BBC學校
school 3: CCC學校

by outputting value school 1 in my post, FRONT-END should be like
ENG post
ABC school

CN post
ABC學校

my original post stated that this doesn't work even being told this should work, later i came across another thread that has similar problem i encountered: https://wpml.org/forums/topic/translate-labels-only-for-acf-checkbox/#post-7091327

your colleagues suggest another method, using hooks which i am not sure how to use

the bottom line is i want auto translation where i only need to select the field values of the default language once, instead of translate them every time

January 28, 2021 at 1:59 am #7946551

Marcos Vinicios Barreto
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Bahia (GMT-03:00)

Hello,

Thank you for the updates. I read all the mentioned threads and noticed there are bunch of ping and pong discussion due the confusing nature of the request.

I do understand you need to show different labels in the frontend according the language, exactly as you have in your backend, I suspect the the call to the ACF get_field() function in .twig templates should be the cause of such issue as it couldn't take into consideration the right field ID according the language viewed.

However, in order to confirm it, I would appreciate to inspect a duplicator package of your website, where the issue can be reproduced and some experiments can be made, so, I would need the following:

1 - A duplicator package of your website with some test field group.
2 - The exact page/post where the field group content is output.
3 - The exact file name and patch where you retrieve the fields values.

As regarding the Duplicator package, please, consider:

To best troubleshoot the issue, please make a snapshot of your site using the Duplicator plugin: https://wordpress.org/plugins/duplicator/. This will allow me to try and duplicate the error so that I can run further tests without interrupting your live site.

Once the snapshot is complete, either upload the snapshot ZIP file and the installer.php file to a file sharing service such as Dropbox (and share the link in your reply) or right click the Duplicator links in your wp-admin and paste in your reply.
Please note: It is important to reduce the size of the package so please exclude some paths like /cache or /uploads and also exclude archives and media files.I will also need the username and password of an account that was created BEFORE creating the duplicator package.I will enable the next reply to be private so only you and I have access to it!

Thank you for your collaboration. Have a nice day.

January 30, 2021 at 7:26 pm #7968755

Marcos Vinicios Barreto
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Bahia (GMT-03:00)

Hello,

Thank you for the provided details. I am updating here to let you know I would need some more extra hours in order to review your issue into details, I will be back as soon as I am done. Thank you for your understanding and continued patience, have a nice day.

February 4, 2021 at 7:49 pm #8010705

Marcos Vinicios Barreto
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Bahia (GMT-03:00)

Hello,

Thank you for your continued patience. During my troubleshooting process a fatal error (most likely caused by some third party code dependency in your custom code) happened, so, I would need the FTP access details to the test/stating environment in order to keep debugging it properly and restore access to the WordPress Dashboard.

By the way, the issue is really hard to debug, the interface and values in chinese make it hard for me to understand which values should be output and where. Also, in the provided sample post, I don't see any checkbox, only the 'university' label from the 'Education Facilities' fields group which makes me to conclude your custom code is the root cause of your issue as you only output labels and don't take into consideration the right language ID. In any case, as said the FTP details will help to keep debugging the issue when something breaks and I loose the WordPress Dashboard access.

The next reply is marked as private, so, you can safely provide the required details. Thank you for your continued patience and understanding, have a nice day.

February 11, 2021 at 10:08 pm #8065651

Marcos Vinicios Barreto
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Bahia (GMT-03:00)

Hello,

Thank you for the details and sorry for the waiting here. I took a detailed look at this issue and did a detailed troubleshooting testing several scenarions, I couldn't make it to work.

However I consulted our development logs and noticed it is something reported and confirmed as bug, our developers are working on a fix to be releated in the next version of the 'Avanced Custom Fields Multilingual' so, stay tunned and test it as soon as the update is available.

Thank you for your patience and understanding, have a nice day.