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:

Content Template with the wpml-string shortcode
Content Template with the wpml-string shortcode

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.

Arguments for wpml-string

The format for the shortcode is:

wpml-string syntax
[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.

Examples and how to use wpml-string

wpml-string without a ‘name’ argument

wpml-string without a ‘name’ argumen
[wpml-string context='wpv-views']Read more[/wpml-string]
  1. 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.
  2. 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.

How the “Read more” string appears in the WPML String translation screen
How the “Read more” string appears in the WPML String translation screen

wpml-string with a name attribute

wpml-string with a name attribute
[wpml-string context='cred-form-add-new-item' name='price label']Price[/wpml-string]
  1. 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
  2. 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.

How the “Price” string will appear in the WPML String translation screen
How the “Price” string will appear in the WPML String translation screen

Where you can use the wpml-string shortcodes

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

Inserting the wpml-string shortcodes from Toolset GUI

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.

  1. In your Toolset editor click the Fields and Views button.
  2. Choose Translatable string. A dialog box will open.
  3. Type in the context and the string to translate.
  4. Click Insert shortcode.

Inserting the wpml-string shortcodes from Toolset GUI
Inserting the wpml-string shortcodes from Toolset GUI

Need help?

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.