Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2025-03-27 08:39:33

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

add lang attribute globally

To allow for multi-lingual sites it would be good if we could have a lang attribute both in textile and tags.

ie. <txp:permlink id="22" lang="hr" />

and

p{lang="hr"}(my_class).

etc.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#2 2025-03-27 08:44:48

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,850
Website GitHub

Re: add lang attribute globally

Hi Yiannis,

For the second case, there is already a language setting:

p[hr]. Croatian text here…

For the first case, what would the lang attribute do? Add that to the url? Or include lang="hr" as an attribute of the a tag?


TXP Builders – finely-crafted code, design and txp

Offline

#3 2025-03-27 09:00:10

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

Re: add lang attribute globally

Thanks Julian,

I missed the textile attribute.

For the second case I was admittedly lazy. <txp:permlink id="22" lang="hr">moja poveznica</txp:permlink> which could parse something like <a rel="bookmark" lang="hr" href="https://www.site.tld/title">moja poveznica</a>, where the default, non signified in the tag, language would be the one initially stipulated by the admin.

A similar use could be in other tags.

Edited to add that we can of course create a shortcode for such links, but if it was in the core, it would be a small baby-step towards multi-lingual sites.

Last edited by colak (2025-03-27 09:02:32)


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#4 2025-03-27 13:05:49

etc
Developer
Registered: 2010-11-11
Posts: 5,342
Website GitHub

Re: add lang attribute globally

For the record, some tags (like <txp:date />) already accept lang attribute, but not as HTML attribute, which might be confusing.

Offline

#5 2025-03-28 04:46:28

phiw13
Plugin Author
From: South-Western Japan
Registered: 2004-02-27
Posts: 3,355
Website

Re: add lang attribute globally

colak wrote #339378:

To allow for multi-lingual sites it would be good if we could have a lang attribute both in textile and tags.

ie. <txp:permlink id="22" lang="hr" />

What would the expected HTML output of that be ? <a lang="fr" href="/fr/article-title">en Français</a> or <a hreflang="fr" href="/fr/article-title">article title</a>. Those are different things: the first one says “the enclosed string is in French” while the second: “This link points to a French language article titled …”

Textile only generates lang="xxx", It would be nice if it added the hreflang attribute

p[fr]. Un belle goélette décrite ici: "[fr]xxx":/fr/belle-goelette

Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

#6 2025-03-28 15:14:18

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

Re: add lang attribute globally

phiw13 wrote #339394:

…the first one says “the enclosed string is in French” while the second: “This link points to a French language article titled …”

I had no idea of the hreflang attribute. How would you also see it in the permlink tag?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#7 2025-03-28 16:28:23

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,677
Website GitHub

Re: add lang attribute globally

hreflang is an absolute swine to set up because every article must have the entire set of articles referenced, including itself. That gets very messy, very quickly for all but the most basic bilingual site, because every time you add a new translation you need to revisit all the others and update them.

When I was implementing it recently for a site, I ended up using the sitemap to list the translations – as recommended way, way down this ahrefs article because then I didn’t have the above headache, nor did I have to faff with headers.


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

#8 2025-03-29 01:04:28

phiw13
Plugin Author
From: South-Western Japan
Registered: 2004-02-27
Posts: 3,355
Website

Re: add lang attribute globally

colak wrote #339396:

I had no idea of the hreflang attribute. How would you also see it in the permlink tag?

I have currently no idea and to be honest, the way I use the <txp:permlink /> tag in content is trough a shortcode as Textile really does not like it when inserted it directly. And the shortcode does all the heavy job.

In templates I am not sure if a HTML lang attribute would be useful for the output of <txp:permlink /> as it most certainly would sit inside a block with the same language. Your <txp:permlink lang="xxx"/> could then output the HTML hreflang attribute. That is assuming a way can be found to pass along the values (from some flag, CF maybe? in the DB).


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

#9 2025-03-29 08:25:20

phiw13
Plugin Author
From: South-Western Japan
Registered: 2004-02-27
Posts: 3,355
Website

Re: add lang attribute globally

phiw13 wrote #339399:

[…]
Your <txp:permlink lang="xxx"/> could then output the HTML hreflang attribute. That is assuming a way can be found to pass along the values (from some flag, CF maybe? in the DB).

Actually it could have both the lang and hreflang.

And here is what i’ve been doing for a site that has some articles translated in this or that language (all file in section “translations”). I use a customfield named lang, I then use it to specify firstly the lang for the individual article. For my article list, the code looks like this:

<article <txp:evaluate>lang="<txp:custom_field name='lang' />"</txp:evaluate>>
  <h2 id="al-<txp:article_id />"><a <txp:evaluate>hreflang="<txp:custom_field name='lang' />"</txp:evaluate> href="<txp:permlink />"><txp:title /></a></h2>
<txp:excerpt />
<footer><p class="article-meta">Posted: <time datetime="<txp:posted format="%Y-%m-%d" />"> <txp:posted /></time></p>
</footer></article>

works fine for my purposes. One could imagine having a dedicated field under the “Meta” block where the article language is specified.


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

#10 2025-03-29 09:17:46

etc
Developer
Registered: 2010-11-11
Posts: 5,342
Website GitHub

Re: add lang attribute globally

OT, but you can spare a tag here:

<article <txp:custom_field name='lang' wraptag='lang="<+>"' /> />

Offline

#11 2025-03-29 09:30:30

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,850
Website GitHub

Re: add lang attribute globally

Aside: there’s a case to be made for being able to add any user-definable attribute to certain txp:tags. I think you raised that before in the past.


TXP Builders – finely-crafted code, design and txp

Offline

#12 2025-03-29 09:47:53

etc
Developer
Registered: 2010-11-11
Posts: 5,342
Website GitHub

Re: add lang attribute globally

jakob wrote #339407:

Aside: there’s a case to be made for being able to add any user-definable attribute to certain txp:tags. I think you raised that before in the past.

Yes, e.g. <txp:image /> accepts any html attribute, and this should be the case of any txp tag outputting an html tag. But it looks tricky to do this globally, most tags need to be tweaked. Also, this would probably require removing ‘unknown attribute’ warning, so mind typos.

Offline

Board footer

Powered by FluxBB