Textpattern CMS support forum
- Registered: 2019-12-12
- Posts: 73
Create your theme in multiple languages
Basically, in all the templates we create there are messages like “You haven’t published anything yet”, or “search” buttons, or inputs with a placeholder written “your name”. They are just examples.
With this small and simple shortcode you will be able to display the message you want according to the language that was defined in the language panel in Textpattern. This way, you guarantee that whoever uses the theme you created, will have a theme according to your language.
Give the name of the form “msg” or as you wish, and use the following code:
<txp:variable name='current_language' value='<txp:lang/>'/> <txp:if_variable name='current_language' match='any' value='pt-br, pt'> <txp:yield name='pt' default=''/> </txp:if_variable> <txp:if_variable name='current_language' match='any' value='en, en-us, en-gb'> <txp:yield name='en' default=''/> </txp:if_variable> <txp:if_variable name='current_language' value='es'> <txp:yield name='es' default=''/> </txp:if_variable>
Use the message like this:
<txp:output_form form='msg' pt='Sua mensagem' en='Your message' es='Su mensaje'/>
Or with short tag:
<txp::msg pt='Sua mensagem' en='Your message' es='Su mensaje'/>
Note: Obviously, it can be expanded (or changed) to as many languages as you want, just add another
if_variable tag, give it one or more conditions, and that’s it. Easy. If you have an easier way to do this, tell me, it would be helpful. At least for me, I’m just an amateur trying.
Last edited by Myusername (2020-09-06 15:49:16)
Re: Create your theme in multiple languages
That is indeed very handy but I think that double quotes are needed for the tags, unless they reside in another tag. ie
<txp:variable name="current_language" value='<txp:lang/>'/>
<txp::msg pt="Sua mensagem" en="Your message" es="Su mensaje"/>
- Core designer
- From: Haslemere, Surrey, UK
- Registered: 2009-06-11
- Posts: 3,420