• Resolved helena377

    (@helena377)


    Hello,

    Is it possible to translate html attributes, like data-title or data-label? For ex., I would like to translate Order ID in: <td data-title=”Order ID”>. But apparently, TranslatePress doesn’t display this element.

    Thank you,
    Regards

    • This topic was modified 4 years ago by helena377.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Anghel Emanuel

    (@anghelemanuel99)

    Hello there,

    Thank you for reaching us!

    Unfortunately, TranslatePress works only on the front-end part.

    You are not able to translate the HTML attributes with our plugin.

    If there`s anything else, please let us know!

    Kind Regards,

    Thread Starter helena377

    (@helena377)

    Hello,

    Thank you for your reply. Actually, the text in HTML attribute is displayed on front-end part. In my example, the text related to data-title is used in order to change the layout of a table on small screens. In other words, the text Order ID would be visible only on small screens, like this: https://ibb.co/qJk5p21

    So, it is on front-end part, just it appears only on small screen.

    Kind regards

    Plugin Support Anghel Emanuel

    (@anghelemanuel99)

    Hello there,

    If the text is display,this should work to be translated.

    If you want to translate the text inside of an HTML attribute,this won`t work.

    You can also translate your strings directly from the backend using the WP Data Access plugin https://wordpress.org/plugins/wp-data-access/
    Let’s say for example that your default site’s language is English (United States) and that you want to translate a string to Spanish.
    Using WP Data Access, you will have to search for that string either in the wp_trp_dictionary_en_us_es_es table or in the wp_trp_gettext_es_es table.
    The gettext table contains all the strings related to plugins or themes, while the dictionary table contains the strings related to your site’s content.

    Here is an image of how WP Data Access looks when you search for the trp tables: https://www.cozmoslabs.com/wp-content/uploads/2021/05/wp_data_access_search_for_table.jpg

    You can never be too sure in which table a string will be, so the best practice is to search for it in both tables. Start with one table and if you are not able to find it there, search for it in the other table.
    Here is an image of how I was able to search for all strings that contain “cart” in the wp_trp_dictionary_en_us_es_es table: https://www.cozmoslabs.com/wp-content/uploads/2021/05/wp_data_access_search_for_string.jpg

    After you find the string that you want to edit, all you have to do is to edit the row and to add the translation in the Translated column. It is also important to add 2 in the Status column (0 – not translated; 1 – automatic translated; 2 – manually translated).
    Here is an image of how to do the translation: https://www.cozmoslabs.com/wp-content/uploads/2021/05/wp_data_access_translate_string.jpg
    After you have filled the Translation and Status columns, press the Submit button and the translation is going to be saved.

    In the example I gave above, I used English and Spanish, you can do the same for all languages, just make sure to replace the en_us and es_es language codes with the ones that you are using. You can find the codes for your languages by going to: Settings –> TranslatePress –> General tab https://www.cozmoslabs.com/wp-content/uploads/2021/05/general_langauge_code.jpg

    Try this and let me know!

    Kind Regards,

    Thread Starter helena377

    (@helena377)

    Hi,

    Thank you for your reply. Actually, I have been able to fix the issue by simply injecting some PHP in the HTML attribute. So, for example, instead of: <td data-title=”Order ID”>
    I would use: <td data-title="<?php echo __('Order ID', 'plugin-name'); ?>">
    Sorry, I should have posted my solution when I had the answer but I just forgot to.
    Anyway, thank you for your update. I will definitely take a look at WP Data Access, it looks interesting.

    Kind regards

    Plugin Support Alex

    (@alexcozmoslabs)

    Hi,

    It’s not a problem. Thank you for your feedback.

    • This reply was modified 3 years, 9 months ago by Alex.
Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Translation of HTML attributes’ is closed to new replies.