Textpattern CMS support forum

You are not logged in. Register | Login | Help

#11 2015-07-15 20:06:04

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

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

etc wrote #293254:

Stef has some plans re multilingualism, he would do it better and faster;

Plans are just plans until someone makes them happen. I have a doc, sure. It has some logical and functional holes in it, I’m sure. I’ll rejig it in light of recent multi-lingual conversations on the forum and publish it if someone thinks they might be interested in improving it and/or putting some code towards it. Like Themes, I don’t think it’s that big a job if it’s broken down and the goals are simplified, with plugins being allowed to add supporting functionality as the end game.

Loading language strings is the longest (by far) db query on a typical page

Yes, and it’s going to get worse as more strings are added and sites are delivered in multiple languages.

But we have a unique opportunity here with the next batch of 4.x upgrades. Since we intend to phase out reliance on the RPC server for both language strings and help, and find a better way to manage languages (e.g. by bundling all language packs and help content with Txp in the download or making it a one-click job to grab a pack and install it from a central location for that version of Txp) then we potentially have a few wins at our disposal:

  • We could strip out all legacy strings that are no longer used in the next release. That’s not easy but a simple support utility to grep through the distro and find gTxt() calls and compare them to any given language might get us 90% of the way there. I do this in ied_plugin_composer to scan for potential Textpack strings in plugin code, but it misses some that are programmatically generated (e.g. gTxt($event . '_something')). The language packs keep getting bigger, even though there’s a lot of cruft to support older versions back to the gamma days. There’s no real need to keep doing that if we maintain some kind of version info against strings so packs can be built for the strings only in that version of Txp.
  • We could find a better way to load lang strings on the site. Examples (not necessarily all feasible or desirable) are:
    • Scanning for strings and only loading the ones in use on a page.
    • Loading strings on-demand and caching them.
    • Using the disk more by loading them all on first page request and caching them so that future requests on subsequent pages are disk bound if those strings exist. Plugins could also play here too with the same built-in mechanism.
    • Bypassing the DB entirely and using the distributed packs for all content, only deferring to the database if a string is not found (e.g. a plugin string request, which could then be cached too).

There are other ways we could improve things here for both optimisation and workflow improvements. If anyone can chime in, float ideas, run with this, put some code to it, anything, it would really benefit everyone.


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

#12 2015-07-16 04:58:26

makss
Plugin Author
From: Ukraine
Registered: 2008-10-21
Posts: 355
Website

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

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

I also encountered this problem when you run a multilingual website

My first thought was to use the tags Texpattern (via a plugin), as described by you. But the code of forms becomes difficult to read and very difficult to edit them later. Therefore, a simple wrapper was written which makes replacing {{some_words}} to the desired language. That is, the page template and the forms used simple {{older}}.

For explicit language, I would suggest {{older:es}} or {{older:es-ca}}

Upd: This approach proved to be convenient for me. I have used TxP tags:
{{sec_short_<txp:section />}}
{{sec_long_<txp:section />}}
{{sec_description_<txp:section />}}
{{sec_keywords_<txp:section />}}

Last edited by makss (2015-07-16 09:34:24)


aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)

Offline

#13 2015-07-16 12:14:10

etc
Developer
Registered: 2010-11-11
Posts: 2,729
Website

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

Bloke wrote #293277:

But we have a unique opportunity here with the next batch of 4.x upgrades.

Quite agree, multilingualism is a major change, it needs some thoughts. And since you are I am well behind me you (pardon my English!) in this area, there is no point that I make changes now that couldn’t fit later the general framework. We can share jelly beans, though. :)

Last edited by etc (2015-07-16 12:27:45)


etc_[ query | search | pagination | date | tree | cache ]

Offline

#14 2015-07-16 12:50:31

etc
Developer
Registered: 2010-11-11
Posts: 2,729
Website

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

FWIW, on my db server, loading ~20 strings takes roughly the same time that the whole public-side package (~350 strings). There is a unique index on lang, name, which is used, but doesn’t help much. So, reducing the overall number of strings could be more efficient than selecting only the used ones.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#15 2015-07-16 13:01:54

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

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

etc wrote #293332:

reducing the overall number of strings could be more efficient than selecting only the used ones.

I agree. So how to do that then, for the best? Some kind of versioning / tag system so we know which belong to which releases of Txp? Any ideas?


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

#16 2015-07-16 13:15:11

etc
Developer
Registered: 2010-11-11
Posts: 2,729
Website

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

Probably separate public and admin tables? The ratio is about 1:5, and only few strings of the common part seem to be useful on the public side.


etc_[ query | search | pagination | date | tree | cache ]

Offline

#17 2018-02-11 14:10:09

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 2,970
Website

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

I’m out of touch here: did this progress further since these last promising-sounding discussions?

If not, firstly: is there a potential alternative one could use now? Perhaps even with txp 4.6?

And secondly: I recently had the “pleasure” of shifting a WP site over to a new theme and made a child theme for it. The language strings for a plugin or theme have their own ‘text-domain’ (link). Might that approach in combination with the new themes facility work as a way of limiting the number of public strings? One could then supply a textpack folder with a theme with custom strings in different languages.

FWIW: I liked Pete’s original suggestion with the lang attribute for txp:text. Far more compact for inline-stuff than wrapping every tag. The other txp:lang / if_lang tags also sound good.

makss wrote #293306:

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

… a simple wrapper was written which makes replacing {{some_words}} to the desired language. That is, the page template and the forms used simple {{older}}. For explicit language, I would suggest {{older:es}} or {{older:es-ca}}

@makss, is this something you could show or share?


TXP Builders – finely-crafted code, design and txp

Offline

#18 2018-02-11 23:18:33

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

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

I’d forgotten all about this discussion. Thanks for finding it again. That probably answers your first question about progress in this area :-]

Multi-linguality on the public side is on the hit list for (probably) next version-or-two-ish, seeing as we’ve made a start with language improvements in 4.7.x. The good news is that all strings now have an “owner” (equivalent to ‘text-domain’ in a way). Core strings have no owner set (owner=""). So if you insert a custom Textpack you can nominate an owner, which allows it to easily be attributed to a plugin, author, whatever you want. It’s just a freeform column in the txp_lang table.

Should be a cinch to pull out strings of a certain owner via a tag in a plugin. Since we’ve also separated the admin language from the public language, this is even more achievable now as a halfway house – in a sort of DIY-lang-strings capacity, as long as you don’t mind grabbing strings by hand based on the currently set public language. You could make your own simple <txp:text> tag that could take an owner and lang attributes, with lang defaulting to the current public language.

What it won’t do, however, is permit you to tie the language to the URL and translate content types – articles, links, image captions, etc. That’d have to be a whole new arena that we’ll need to figure out somehow.


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

#19 2018-02-12 13:19:01

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 2,970
Website

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

Thanks for the update. That definitely sounds promising!


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB