Textpattern CMS support forum
- Registered: 2019-12-12
- Posts: 153
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"/> </txp:if_variable> <txp:if_variable name="current_language" match="any" value="en, en-gb, en-us"> <txp:yield name="en"/> </txp:if_variable>
Use the message like this:
<txp::msg pt="Parece que não há nada por aqui :(" en="Looks like there's nothing around here :("/>
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 (2021-07-06 12:59:35)
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"/>