Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2015-07-14 09:06:44

gaekwad
Admin
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 2,575

Add lang attribute to <txp:text />

txp:text doesn’t appear to have any option to specify an alternate language. If >1 languages are installed, for example on multi-lingual sites, I would love to have the option to fine-grain control output of button text, messages etc. Something like this:

<txp:text item="older" lang="es-ca" />

Last edited by gaekwad (2015-07-14 09:23:12)

Offline

#2 2015-07-14 17:33:30

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,760
Website

Re: Add lang attribute to <txp:text />

Fine idea. If only more than one language was downloaded to the public site :-(

But there’s nothing to stop the lang attribute firing off a database request for either:

  1. individual strings on an as-needed basis (caching them in textarray for future requests on the page), or
  2. (probably better, if more network traffic) fetching the entire array for that language — and caching as above — thereby cutting down on future requests. The rationale being that the fact you’ve called the thing with lang means you’re quite likely to want other strings in the same language. Future requests for the same language would then just use the downloaded array directly.

On the surface, seems like a worthy addition and another stepping stone towards multi-linguality. If you fancy flexing your PHP muscles, be my guest. Failing that, raise an issue and I or some other benevolent contributor can look into it.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2015-07-14 18:24:46

etc
Developer
Registered: 2010-11-11
Posts: 3,298
Website

Re: Add lang attribute to <txp:text />

I’d say 2, because how many users are well acquainted with item attribute values of <txp:text /> tag? Probably, some <txp:lang /> switcher would be easier to use.

Offline

#4 2015-07-14 18:39:52

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,760
Website

Re: Add lang attribute to <txp:text />

etc wrote #293182:

I’d say 2, because how many users are well acquainted with item attribute values of <txp:text /> tag? Probably, some <txp:lang /> switcher would be easier to use.

Interesting. Are you proposing to use that tag instead of the lang attribute to load the languages from the DB to the public side?

I was intending to hijack <txp:lang /> at some point for use in a container. Maybe, I dunno, inside <txp:lang_list> or something, which would return a list of installed languages for you. So you could display information about the current language inside the container / make a select list lang switcher, stuff like that.

Right now, it just returns the 2-letter code of the “current language” (monoglot) but I’d intended to add an attribute — like type or item or something — so you could get more info from it when used as a single tag. But it would return info about the “current language” (polyglot) from the list inside the <txp:lang_list> container. Is this compatible with your vision for its use in Pete’s proposal?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2015-07-14 19:36:27

etc
Developer
Registered: 2010-11-11
Posts: 3,298
Website

Re: Add lang attribute to <txp:text />

Bloke wrote #293185:

Are you proposing to use that tag instead of the lang attribute to load the languages from the DB to the public side?

Oups.. I’ve forgotten that <txp:lang /> already exists. Yes, it could accept some lang attribute to load (and cache) language strings, either inside its $thing (if turned into container), or globally (in single tag mode).

I was intending to hijack <txp:lang /> at some point for use in a container. Maybe, I dunno, inside <txp:lang_list> or something, which would return a list of installed languages for you. So you could display information about the current language inside the container / make a select list lang switcher, stuff like that.

Right now, it just returns the 2-letter code of the “current language” (monoglot) but I’d intended to add an attribute — like type or item or something — so you could get more info from it when used as a single tag. But it would return info about the “current language” (polyglot) from the list inside the <txp:lang_list> container. Is this compatible with your vision for its use in Pete’s proposal?

I think yes, if lang attribute is unset, it could just return some info, without changing the language. Setting lang could allow for things like

<txp:lang_list>
	<txp:lang lang='<txp:lang />' />
	In <txp:lang type="full_name" /> "older" is "<txp:text item='older' />"
</txp:lang_list>

And Pete’s proposal (e.g. <txp:text item="older" lang="fr-fr" />) would be equivalent to

<txp:lang lang="fr-fr"><txp:text item="older" /></txp:lang>

I don’t know how many people use individual <txp:text /> tags. It seems more logical to change all language strings at once, but I have no clear idea yet.

Offline

#6 2015-07-15 01:48:43

maverick
Member
From: Southeastern Michigan, USA
Registered: 2005-01-14
Posts: 960
Website

Re: Add lang attribute to <txp:text />

With fear and trepidation, can I muddy the waters? (I know – groans abound)

With the move to multilingual capabilities, I am wondering if, in theory (I don’t have a real life use case at this point), a <txp:if_lang> tag would become valuable.

Something like

<txp:if_lang isocode="es" >
<txp:text />
*or alternately*
<other special content />
<txp:if_lang />

(Quietly returns to the woodwork)

Last edited by maverick (2015-07-15 01:50:16)

Offline

#7 2015-07-15 09:10:34

etc
Developer
Registered: 2010-11-11
Posts: 3,298
Website

Re: Add lang attribute to <txp:text />

maverick wrote #293208:

With the move to multilingual capabilities, I am wondering if, in theory (I don’t have a real life use case at this point), a <txp:if_lang> tag would become valuable.

Stef is your man, but if <txp:lang /> could be used as container, rather than a new tag I would suggest

<txp:lang lang="es" >
	<txp:text />
<txp:else />
	<other special content />
</txp:lang>

Offline

#8 2015-07-15 11:30:53

gaekwad
Admin
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 2,575

Re: Add lang attribute to <txp:text />

I am absolutely not married to the OP idea/route of a new attribute.

…and – frankly – etc’s far better at this kind of thing than I, so I’ll defer to his idea above this reply.

etc: are your skills suitable for switching lang to a container rather than just a single tag? I’ll pay you in jelly beans.

Offline

#9 2015-07-15 13:58:52

maverick
Member
From: Southeastern Michigan, USA
Registered: 2005-01-14
Posts: 960
Website

Re: Add lang attribute to <txp:text />

etc wrote #293225:

if <txp:lang /> could be used as container, rather than a new tag I would suggest

<txp:lang lang="es" >...

etc – a much better suggestion!

Offline

#10 2015-07-15 15:12:42

etc
Developer
Registered: 2010-11-11
Posts: 3,298
Website

Re: Add lang attribute to <txp:text />

My dear Lords, it’s not that I wouldn’t, but:

  • Stef has some plans re multilingualism, he would do it better and faster;
  • Loading language strings is the longest (by far) db query on a typical page, this tag shouldn’t be taken <txp:lang lang="fr-fr">à la légère</txp:lang>.

Offline

Board footer

Powered by FluxBB