The wpml-string shortcode assists in building multilingual sites with the help of the Toolset and WPML plugins. It allows you to register strings for translation in WPML’s String translation and displays the translations.
Using [wpml-string], you can create Toolset templates that work for different languages. Instead of creating a different template per language, you can create one template and wrap translatable texts in .
Let us look at an example:
You can see that the text ‘read more’ is wrapped in wpml-string.
Doing so, registers the text for translation by WPML’s String Translation. When Toolset displays this piece of HTML, it replaces the original text (‘read more’) with its translation, provided that the user translated the text.
The format for the shortcode is:
[wpml-string context='Context of the string' name='Name of the string']Value of the string[/wpml-string]
- Context (optional): This controls the domain under which the string will be registered and appears in the WPML String translation screen. The domain is used to helps group related strings, so that it is easier to find and translate them.If not provided, the context will be created automatically
- Name (optional): This controls the name under which the string will be registered and appears in the WPML String translation. A custom name helps a WPML user identify the relevant string in the WPML String translation screen, especially if you register a few strings with the same context attribute and with the same value, but with different translations (e.g., “comment” can be used both as a verb or a noun).If not provided, the name will be created automatically and will start with the wpml-shortcode prefix followed by a unique identifier based on the value passed in the shortcode content.
Each context can have only one string with the same name.
[wpml-string context='wpv-views']Read more[/wpml-string]
- Registers the ‘Read more’ string in the WPML String translation admin screen under the wpv-views domain, provided the “Read more” string did not exist within that domain yet.
- Displays “Lire la suite” in the French version of the page and “Leer más” in the Spanish version, provided that “Lire la suite” and “Leer más” are French and Spanish translations, respectively, of the “Read more” string, for the wpv-views domain and both translations are marked as completed in the WPML String translation admin screen.
[wpml-string context='cred-form-add-new-item' name='price label']Price[/wpml-string]
- Registers the “Price” string in the WPML String translation admin screen under the cred-form-add-new-item domain and with the price name, provided the “Price” string did not exist within the
- Displays “Prix” in the French version of the page and “Precio” in the Spanish version, provided that “Prix” and “Precio” are French and Spanish translations, respectively, of the “Price” string entered in the cred-form-add-new-item (domain) and price (name) row in the WPML String translation admin screen and both translations are marked as completed.
You can use in any text/HTML input in Toolset. This includes:
- View (Loop field, Filter field, embedded Content Templates)
- Content Template
- WordPress Archive (Loop field, Filter field, embedded Content Templates)
- Toolset form (form body)
- Layouts Visual Editor cells
Instead of wrapping your strings manually with wpml-string shortcodes, you can use the Views GUI and its Translatable string feature. Consider using this feature as a time-saving and bug saving option.
- In your Toolset editor click the Fields and Views button.
- Choose Translatable string. A dialog box will open.
- Type in the context and the string to translate.
- Click Insert shortcode.
Ask us about using the wpml-string shortcode and we’ll do our best to help.
For more elaborate questions, please use our Toolset Professional Support forum.