This thread is resolved. Here is a description of the problem and solution.
There was an error: { "keywords": "WPML, string translation, gettext, custom theme, hardcoded strings", "summary": "Problem:
The client needed to translate hardcoded English strings in a custom theme to Spanish, such as a search box placeholder and button text, and was unsure how to replace these values efficiently.
Solution:
1. We suggested enabling the \"Look for strings while pages are rendered\" option in WPML > String Translation, visiting the page with the string, and then searching for the string in WPML > String Translation.
3. We explained that for WPML to recognize strings, they need to be wrapped in a gettext call. We provided an example of how to wrap strings and a link to find the theme's text domain:
Please note that the solution provided might be outdated or not applicable to your case. If the issue persists, 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 with us." }
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.
I'm trying to understand string translation, for example in the header I have a search box with the default text "What are you looking for?" And a default button that says "Search" - How do I change my custom them to replace these English values for their Spanish alternative.
Search button should read 'Buscar' and the input field default should say "¿Qué estás buscando?"
Please let me know as I have other areas in my template where I have English text hardcoded that needs to be updated to Spanish when the user Toggles between the languages.
Before this ticket gets assigned to my colleagues, I will try to help.
The proper way to translate strings depends a lot on how they have been implemented inside the theme/plugin.
Sometimes, there are even duplicates of the same string and only one of them is the correct one that needs to be translated.
Also, sometimes, simply removing the string (checking the box and removing it) and then re-registering it again by scanning for it (one of the methods below) and re-translating it resolves the issue.
1. Please try this:
Go to WPML > String Translation and at the bottom of the page you will find a checkbox called "Look for strings while pages are rendered". You can enable (check) that and then go in the front end to a page where you have that string showing up and then go back to WPML > String Translation and search for that string and see if it now shows up.
2. If you can't find them inside the WPML > String Translation, they might be added as admin text.
I read your response. I watched the videos provided but I am still having issues. For example the search results page. In string translation when I search for 'Search Results" or 'Sorry, nothing was found.' I do not see either listed in the String Translation section.
Thank you for providing the details. It's noteworthy that you're using a custom theme.
Did you develop this theme yourself? I must mention that our support scope for custom developments is somewhat limited. Nonetheless, I believe the following guide on String Translation could be useful for making your strings translatable.
I didn't quite follow the content in that link. I think it was a bit beyond what I am doing as this is a custom template for a client, not a custom template for sale.
Right now I am doing this to address the hardcoded english language in the template so it can also display in spanish. Can you tell me if there is a more efficient way to accomplish the same thing?
This is an example from search.php. This page lives outside of the database content so this is how I am addressing the conversion. Please tell me if there is a better/smarter way.
<h1 class="entry-title">Search Results</h1>
<h1 class="entry-title">
<?php if ( defined( 'ICL_LANGUAGE_CODE' ) && 'en' == ICL_LANGUAGE_CODE ) {
echo 'Search Results';
} else if ( defined( 'ICL_LANGUAGE_CODE' ) && 'es' == ICL_LANGUAGE_CODE ) {
echo 'Resultados de la búsqueda';
} ?>
</h1>
I think for your specific case use it is important to review the part for Gettext and Wrapping Basic Strings. In order for a string to be picked up by WPML String Translation your hardcoded string needs to be wrapped in a gettext call.
For example:
Not Wrapped --> <h1 class="entry-title">Search Results</h1>
This was very helpful. I've made changes to my custom theme. Scanned the theme and made the translations in the string editor. Thank You.
Is there a way to do this taxonomy names? I have a taxonomy that I don't want to translate because it seems like I will need to tag all the posts and the content in the posts does not need to be translated but the taxonomy terms that filter the post content should be translated.
If that is the case I must add that the filters for the posts will not work as expected as the posts do not actually exist in the database.
Manage Cookie Consent
We use cookies to optimize our website and services. Your consent allows us to process data such as browsing behavior. Not consenting may affect some features.
Functional
Always active
Required for our website to operate and communicate correctly.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
We use these to analyze the statistics of our site. Collected information is completely anonymous.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
These cookies track your browsing to provide ads relevant to you.