Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2020-09-06 15:24:45

Myusername
Member
Registered: 2019-12-12
Posts: 61

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)

Offline

#2 2020-09-06 15:34:02

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,269
Website

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/>'/>

and

<txp::msg pt="Sua mensagem" en="Your message" es="Su mensaje"/>

Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#3 2020-09-07 10:44:40

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,360
Website

Re: Create your theme in multiple languages

Probably worth mentioning as an aside, but any text strings listed in the [common] and [public] groups in Textpacks are available to use in <txp:text /> tags – so that might cut down the amount of special code you need in your examples above.

Offline

Board footer

Powered by FluxBB