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: 165

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)

Offline

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

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,090
Website GitHub Mastodon Twitter

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 | hblack.art | EMAP | A Sea change | Toolkit of Care
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,564
Website GitHub Mastodon

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