How to make shortcodes translatable in WordPress

What is a shortcode?

From wordpress.com

A shortcode is a WordPress-specific code that lets you do nifty things with very little effort. Shortcodes can embed files or create objects that would normally require lots of complicated, ugly code in just one line. Shortcode = shortcut.

Examples:
[gallery id="402"]
[display-postss tag=”advanced” posts_per_page=”20″]
[code language=”php”]
some php code…
[/code]

 

A shortcode consist of a name (e.g. code), can contain attributes (e.g. language=”php”) and can have an enclosed content (e.g. some php code…).

How does our plugin deal with shortcodes?

Per default our translation plugin hides shortcodes from the translator. They bloat up the content which makes it hard for the translator to find the text to translate. Also,  shortcodes are easily broken. Changing the quote character can already result in the shortcode not being rendered by WordPress.

But what if there is some text in a shortcodes attribute that needs to be translated? In this case you can configure the plugin to recognize the attribute and make its content visible to the translator.

How to configure our plugin to recognize translatable attributes?

1. Identify the shortcodes having attributes which contain texts in the editor. Example: 

 

2. Go to Settings->Supertext->Shortcodes

 

3. Click on Add setting and enter the shortcode name in the Shortcode field

 

4. Click on Add Attribute and enter the attributes name (repeat this for each attribute)

 

5. Click on Save settings

 

The Functions fields are used to define functions used to encode the enclosed content or attribute value. Most of the time no encryption is applied which means the attribute values and enclosed content is saved as plain text and these fields can be left empty. In some cases though the shortcode implementation requires that the content is being encrypted. Then you will need to list the functions used to encode the content.




Ähnliche Beiträge


Leave a Reply

Your email address will not be published. Required fields are marked *



*