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 4 replies, has 4 voices.

Last updated by Andrey 1 year, 9 months ago.

Assisted by: Andrey.

Author Posts
August 23, 2023 at 6:58 pm #14280419

mb-magu-spaceE

Tell us what you are trying to do?
I want to translate 3 strings that are hard coded
Is there any documentation that you are following?
I tried to read other issues, but unfortunately got lost
Is there a similar example that we can see?
jQuery(document).ready(function ($) {
$('.term-description').addClass('desc-reveal-closed');

$(document).on('click', '.description-visibility-modifier .visibility-modifier.text-hidden', function () {
$(this).removeClass('text-hidden').addClass('text-visible');
$('.term-description').removeClass('desc-reveal-closed').addClass('desc-reveal-open');
$('.gradient-transparent').addClass('hide-gradient');
$('.description-visibility-modifier .visibility-modifier').html('Rodyti mažiau');
});

$(document).on('click', '.description-visibility-modifier .visibility-modifier.text-visible', function () {
$(this).removeClass('text-visible').addClass('text-hidden');
$('.term-description').removeClass('desc-reveal-open').addClass('desc-reveal-closed');
$('.gradient-transparent').removeClass('hide-gradient');
$('.description-visibility-modifier .visibility-modifier').html('Rodyti daugiau');
});
});

I need to translate 2 strings that are added through .html(' ')

They are added here

function category_description_modifier() {
if ( is_product_category()) {
echo '<div class="description-visibility-modifier">';

echo '<div class="gradient-transparent"></div>';
echo '<button class="visibility-modifier text-hidden">Rodyti daugiau</button>';

echo '</div>';
}
}
What is the link to your site?

August 23, 2023 at 9:29 pm #14280615

Bobby
WPML Supporter since 04/2015

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hi there,

While waiting for one of my colleagues to help you, please review the following documentation on how to wrap hard-coded strings in a gettext call() which will allow the string to be located by String Translation.

https://wpml.org/documentation/support/enabling-text-translation-for-themes-not-compatible-with-wpml/

Let us know your results, please.

August 24, 2023 at 11:10 am #14284323

mb-magu-spaceE

i can't do that through jquery i think

August 24, 2023 at 12:29 pm #14285571

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

You can localize these strings by using the "wp_localize_script" function: https://developer.wordpress.org/reference/functions/wp_localize_script/

This is necessary because WordPress currently only offers a localization API in PHP, not directly in JavaScript.

In the 'Example' section of the link above, you can check that it'll create a JavaScript code having an object "object_name" with some values, among these values the "some_string".

This code must be within PHP (usually, the recommended file is the functions.php of your theme). To access the JavaScript object, you will only use values that have already been defined within your PHP file.

That is, they are two pieces of code that are going to be defined in two different places. One is PHP (functions.php of your theme), so you can define the translatable string. The second part will be the JavaScript object inside the JavaScript file that you want to use it.

Relevant Documentation:
Please, check the following link with a tutorial, that can help you understand better this: hidden link

Hope this helps.

Regards,
Drazen

August 24, 2023 at 9:17 pm #14288281

Andrey
WPML Supporter since 06/2013

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kyiv (GMT+03:00)

Please follow the links provided by my colleagues. They should help you to localize your hardcoded strings, whether they are added through PHP or jQuery.