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.
Tagged: Documentation request
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? $(document).on('click', '.description-visibility-modifier .visibility-modifier.text-hidden', function () { $(document).on('click', '.description-visibility-modifier .visibility-modifier.text-visible', function () { I need to translate 2 strings that are added through .html(' ') They are added here function category_description_modifier() { echo '<div class="gradient-transparent"></div>'; echo '</div>'; |
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. 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: Hope this helps. Regards, |
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. |