[Resolved] Translating words embedded in a custom template
This thread is resolved. Here is a description of the problem and solution.
Problem: You are trying to translate words embedded in HTML tags within a .php template for a custom post type, which are not editable from the WordPress dashboard. Solution: If you're experiencing this issue, we recommend you try the following steps: 1. Wrap the strings in the gettext
Apply this procedure for all hardcoded strings you wish to make translatable. 2. Scan the theme or plugin from the WPML > Theme and plugins localization page where you updated the code. 3. Go to the WPML > String Translation page, search for the string, and add the translation. For more detailed instructions, please visit our documentation on translating texts wrapped in gettext calls.
If this solution does not apply to your case, or if it seems outdated, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If you still need assistance, please open a new support ticket at WPML support forum.
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.
Background of the issue:
I am trying to translate a page that has words in HTML tags which are not editable from the WordPress dashboard. They are only editable in a .php template that controls the appearance of the page. The page is a custom post type.
Symptoms:
I am unable to translate words embedded in a custom template because they are not editable from the WordPress dashboard.
Questions:
How do I translate words embedded in HTML tags in a .php template for a custom post type?
I have also tried the e() function and tried using a different text domain with both the get text and e() function.
I make changes in the WordPress file editor.
After doing this, I click to save the file.
I get a message that the file was edited sucessfully.
I then go to Theme and plugins localization.
I select "Genesis" and "Monochrome Pro" and then I click on "Scan selected themes for strings"
I get a success message such as "Scan successful! WPML found 681 strings. They were added to the string translation table.
The following files were processed:"
I then click on WPML > String Translation
I scroll to the bottom of the page and click on "Translate texts in admin screens »"
I search for "Region"
The h3 tag does not come up.
I have attached screenshots of the steps described above so you can see the screens.
I looked at the documentation link you provided. However it seems to be about creating a new plugin and a lot more steps that we're not used to.
Are you able to help us find a solution to be able to translate these HTML tags?
Thank you very much. I had tried the e() function just in case it would work, when I couldn't get the original code to work.
Your solution does work, thank you.
I have another instance of the word "Roles:" which seems to come from the Genesis theme somewhere. It is not visible in a string search, even after I have scanned the theme and child theme to search for strings. I am not sure if this requires a new ticket, or if it can be resolved in this ticket, being that it is a similar issue.
Can you confirm?
I have attached screenshots to show what I mean.
Visible on this page: hidden link
New threads created by Noman and linked to this one are listed below:
Glad to hear the hardcoded string translation issue is solved. For searching the string for translation, it’s a different issue and will be handled separately as per our support policy. I've created a new ticket for this at: https://wpml.org/forums/topic/unable-to-find-string-for-translation/
If the hardcoded string translation issue is solved, please mark this ticket as resolved and we will continue working on the above ticket for it.