Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2019-05-06 08:32:40

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

Re: Multi-Lingual Site

jakob wrote #317863:

By way of example, this is what you’d do for the minimum theme … [to update to texpattern 4.7+‘s theme facility.]

FWIW, I gave this a whirl, and you can find the converted theme here. It really is a very basic theme, so I’m not sure how useful it is, but there you go…


TXP Builders – finely-crafted code, design and txp

Offline

#14 2019-05-06 22:26:28

agovella
Member
From: Houston, TX
Registered: 2005-05-01
Posts: 66
Website Twitter

Re: Multi-Lingual Site

jakob wrote #317900:

BTW: I have your book in my shelf here!

POINTS! :-)

Offline

#15 2019-05-07 01:45:19

mori
New Member
Registered: 2019-05-01
Posts: 9

Re: Multi-Lingual Site

By way of example, this is what you’d do for the minimum theme:

  • Download the repository from GitHub
  • Make a folder called minimum
  • Copy the forms, pages and styles folders into it.
  • In the pages folder, rename the file extensions from .page to .txp.
  • in the forms folder, make some folders article, comment, file, link and misc and move the ___.misc.form files into the misc folder, and ___.article.form files into the article folder, and so on. Then rename all the file endings from ___.misc/article/image/link/file.form to .txp.
  • Now make a text file called manifest.json in the minimum folder and put this in it:

{...

And save that. Take a look at the default theme to see an example of how it should look in the end.

Now move the entire folder to the /themes folder of your textpattern installation. When you visit Presentation › Themes, you should now be able to import Minimum from disk.

The last bits you’ll need to do is add the section names that don’t already exist as shown here.

And install the plugins the theme recommends. Of the plugins that the minimum theme suggests, cxc_templates is not necessary. The others should all work but all can be replaced by txp’s own built-in tags. To install them, visit that page in Github, e.g. here, click on the Raw button and copy the long string of letters and numbers to the clipboard. Visit Admin › Plugins and paste that string of letters and numbers into the install plugin textbox and click install and then activate (switch to “on”).

Thank you for the tutorial! I followed your guide and uploaded the theme onto my Textpattern installation. Then I created a new section which uses Minimum and its “default_minimum page”, and made an article (with a test string) for that Test section. As it turns out, nothing came out on screen. I didn’t investigate further. I inserted plain HTML into a blank page template under Minimum theme to test things out, and it worked, so it probably wasn’t an installation issue. All in all, I have a better Idea of how themes work – thank you! I’ll probably customize themes when I have the time.

To link different language menu sections to each other, you can set up a list of variables that indicate which is the section name in the parallel language. By naming the variables according to a pattern, you can make your language switcher switch between the correct sections at the section landing page level.

For the navigation you can likewise use a variable to hold the list of sections that should appear in each language. While you can use a cookie to keep track of which language you are on, it’s not strictly necessary here as this method essentially uses several sets of article trees and you restrict the menu sections to those that you need for each language.

Sorry..I don’t have the knowledge to know the exact steps. By “variable” do you mean inserting variables into the URL and using .htaccess to rewrite the URL before passing it to Textpattern and then use adi_gps or rah_gps plugin to extract the variable for use – like what you mentioned in another post?

The plugin rah_pathway allows you to give an article a completely user-defined url including forward slashes. While it doesn’t add any actual depth structure to Textpattern, it would enable you to fake the last line of the above table to look like this:

That looks really nice. I too would really like to have urls with multiple sub-directories, which would involve constructing my own permlinks and section category links. Does that mean making use of URL variables and txp tags or would I have to touch the core code files?

The rah_pathway github page says to install it using composer. Unfortunately, I think my hosting provider doesn’t have Composer, nor can I ssh into the server. A quick search on my host provider’s forum gave the following:

Our general recommendation for composer stuff is to install it and run all the commands on your own PC, then upload the resulting files. It works just fine and doesn’t require we install it or run anything on our servers that way.

It looks as if I have to do a local installation, install the plugin with composer, search for the newly generated files and upload them…if that works at all… Might there be another way of installing rah_pahthway?

Update I installed Textpattern with the rah_pathyway plugin on my local machine, zipped it up and unzipped on hosting server. The “Free-form article URL” field didn’t show up on Admin > Site panel. Might there be another way of installing the plugin?

Last edited by mori (2019-05-07 05:07:44)

Offline

#16 2019-05-07 05:20:50

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

Re: Multi-Lingual Site

mori wrote #317912:

Thank you for the tutorial! I followed your guide and uploaded the theme onto my Textpattern installation. Then I created a new section which uses Minimum and its “default_minimum page”, and made an article (with a test string) for that Test section. As it turns out, nothing came out on screen. I didn’t investigate further.

Have a look here for an example of the converted minimum theme.


TXP Builders – finely-crafted code, design and txp

Offline

#17 2019-05-07 05:30:00

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

Re: Multi-Lingual Site

mori wrote #317912:

By “variable” do you mean inserting variables into the URL and using .htaccess to rewrite the URL before passing it to Textpattern and then use adi_gps or rah_gps plugin to extract the variable for use – like what you mentioned in another post?

This thread has got a bit complicated with the different methods, so there’s a risk of mixing them up.

Going back to Variant 1 with parallel sections in different languages, I meant using textpattern’s own variables which you set and use with the txp:variable tag. With this variant, you have a host of sections with articles in their respective languages but you need to control which sections show in the menu in each language and a make a switcher that allows you to switch between the corresponding sections in each language. The following is an example showing the principle with sections only and assumes:

  • You have set up sections for each area of your site in each language (using distinct names).
  • For the homepage view in another language, make an extra section and name it with the language code, e.g. “de”. If “en” is your standard language, it’s not strictly necessary to make that section unless you really want it.

To begin with, you need to set up some helper variables for the site as a whole. Typically I put these in a form of their own such as page_vars and call that form with txp:output_form at the top of the page template (the plugin adi_variables provides a UI for making that more user-friendly but it’s not essential).

1) For the navigation, set a variable for each language with a list of the sections that should appear in the menu in that language, e.g.:

<txp:variable name="menu_sections_en">about,music,gallery,reviews,contact</txp:variable> 
<txp:variable name="menu_sections_de">ueber,musik,galerie,pressestimmen,kontakt</txp:variable> 

2) Then set a variable for each section in each language pointing to the corresponding parallel section, e.g.:

<txp:variable name="langswitch_about">ueber</txp:variable>
<txp:variable name="langswitch_ueber">about</txp:variable>
<txp:variable name="langswitch_music">musik</txp:variable>
<txp:variable name="langswitch_musik">music</txp:variable>
<txp:variable name="langswitch_gallery">galerie</txp:variable>
<txp:variable name="langswitch_galerie">gallery</txp:variable>
...
<txp:variable name="langswitch_default">de</txp:variable>
<txp:variable name="langswitch_de"></txp:variable>

Make sure the naming matches your section names. Note: the last two are for the homepage in the respective language (“default” is the standard textpattern name for the homepage).

3) At the top of the page template (or at the end of the page_vars form), set a variable to detect the current language of the section you are on:

<txp:if_section name='<txp:variable name="menu_sections_en" />'>
    <txp:variable name="lang" value="en" />
<txp:else />
    <txp:variable name="lang" value="de" />
</txp:if_section>

(Note the use of ' single quotes for using a txp-tag as a variable of a txp-tag).

If you have more than two languages, you need to do several separate <txp:if_section> … </txp:if_section> one after the other instead of using txp:else. This lang variable will be useful throughout the rest of your page template and forms to control output according the respective language.

To create the site navigation for the respective language, you feed txp:section_list with the respective menu_section_{language} variable, so that only those sections appear in the menu. (Note: here it’s necessary to use ' single quotes as above, and in this case also two single quotes '' when using a txp-tag as a variable of a txp-tag as a variable of a txp-tag!)

<!-- navigation -->
<nav class="c-main-nav">
    <txp:section_list sections='<txp:variable name=''menu_sections_<txp:variable name="lang" />'' />' break="" wraptag="ul">
        <li<txp:if_section name='<txp:section />'> class="active"</txp:if_section>>
            <a href="<txp:site_url /><txp:section />"><txp:section title="1" /></a>
        </li>
    </txp:section_list>
</nav>

For the language switcher, the code looks like this:

<nav class="c-lang-switch">
    <ul>
<txp:if_variable name="lang" value="en">
        <li class="en active">
            <a href="<txp:site_url /><txp:section />">EN</a>
        </li>
        <li class="de">
            <a href="<txp:site_url /><txp:variable name='langswitch_<txp:section />' />">DE</a>
        </li>
</txp:if_variable>
<txp:if_variable name="lang" value="de">
        <li class="en">
            <a href="<txp:site_url /><txp:variable name='langswitch_<txp:section />' />">EN</a>
        </li>
        <li class="de active">
            <a href="<txp:site_url /><txp:section />">DE</a>
        </li>
</txp:if_variable>
    </ul>
</nav>

The principle is that by naming your variables to match the section names, your language switcher will point to the corresponding section in the other language.

The language switcher code also shows how you can use the lang variable created at the top of the page, to show different content, e.g.

<h2><txp:if_variable name="lang" value="en">Welcome<txp:else />Willkommen</txp:variable></h2>

Because that can get a bit cumbersome over time (and increasingly complex if you have more than two languages), you can use smd_babel to define named strings in each language via the admin interface. If you name them something like mysite_welcome_en and mysite_welcome_de, you can use the variable tag-in-tag trick in combination with txp:text to output the respective language string, e.g.:

<h2><txp:text item='mysite_welcome_'<txp:variable name="lang" />' /></h2>

You get the principle by now…

All this is just at the section level. If you need to extend the language switcher to the article level, you can do that by creating one or more custom_fields, e.g. parallel_article_id when you have just one other language or en_article_id, de_article_id, fr_article_id etc. when you have several languages. You place the id number of the corresponding article(s) in the custom field, e.g. if “about” is article id#1 and “ueber” is article id#2, you would put 2 in the parallel_article_id custom field of the “about” article.

With a combination of txp:if_article_list, txp:if_individual_article, and custom_field and if_custom_field as well as <txp:article_custom id='<txp:custom_field name="parallel_article_id" />'><txp:permlink /></txp:article_custom> you can make your switcher switch between corresponding articles in each language.


TXP Builders – finely-crafted code, design and txp

Offline

#18 2019-05-07 05:44:37

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

Re: Multi-Lingual Site

mori wrote #317912:

… which would involve constructing my own permlinks and section category links. Does that mean making use of URL variables and txp tags or would I have to touch the core code files?

No, you don’t need to touch the core files, it just means the standard txp:permlink and txp:section url="1" etc. won’t include your language-specific aspects, and you need to make (i.e. “write out the parts of”) your hrefs using txp:tags, e.g.

<txp:site_url />en/<txp:section/<txp:article_url_title />

or

<txp:site_url /><txp:section/<txp:article_url_title />?lang=<txp:variable name="lang" />

etc.

The rah_pathway github page says to install it using composer. Unfortunately, my hosting provider doesn’t have Composer, nor can I ssh into the server. … Might there be another way of installing rah_pathway?

Ah, it seems the plugin author gocom has gone over to not providing the .txt installer files in the (currently wrong) assumption that everyone can use composer. He also uses a clever but non-standard setup for his plugins, so you need to use his plugin compiler on your local computer to create a compiled txt. Hang on, and I’ll see if I can do that for you. Here you go:

# Name: rah_pathway v0.1.0
# Custom article permlinks
# Author: Jukka Svahn
# URL: https://github.com/gocom/rah_pathway
# Recommended load order: 5
# .....................................................................
# This is a plugin for Textpattern - http://textpattern.com/
# To install: textpattern > admin > plugins
# Paste the following text into the "Install plugin" box:
# .....................................................................

H4sIAAAAAAAAE+1Z6XLbOBL+r6fo1biGksuW5CuHvE7F47ETbTmJV8dMpTxZFURCJMoUoQVA
O5pJ3mbfZF9su0FQoijKcebvjn7YIog+0P31BbHuwXH3D9097tYTNuP1U909OOjWFYvGc2ai
B7agpefd+j1XWsiEnk669U7roNWh78+6dZaaS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IsEoU
gbLJ3iL5DCq2FoegimzlCAulp0i9UYLqvZ/PPNR5rb5s0d6GQrW4KIVWGa+PaPeIr6rsSYZI
l9cEResvJVZlV+q+NXb589R8K/XYamM/V8teb2sSwsnWpxsPuEiVomC22b86RuDt8N01ZCRZ
H1kVMFj2zHq5LE0ODavh3kr4RqMs7T5777Bm8WL6wXIaDj/jcLtaa+4tdxejYVmXcSDPblmt
MrrRzIpzOptgpqfyHLMJ30SF02ZZVTyEB8YfGqrhiJvkVauNY1EJB6alwh2OXXMTAZk9euTj
pY3c7oK19nC8T7mbE2wHnKMGZf11t/zX3fL/5d0yTb+FC4sGBoX78cUs5tnvSt36ifv5SCpE
SWltGrNQu7VD+v8CSW2I+Hd2+Rh5/fDa3gzVNm4jKH0QZPZtg5jfTmPz5vJkLaf84XXMkjDF
WQjf7E9FNatf2JyxWSqNFAlPLL+7O46xC1JLYfgdZmrz3//YIx6g8rZDHUdmFo+zX59Et5Md
gR7Hij3Yn9E6HVw4aBVNXavVb/CEjLr3ejdPAPN8yRo7e0JjI10xFcAXLLla44S/onwsdbSF
3VyruXw03TAYZSi2SlH1Uo5aiSkUfpLVou5OW4Nrmyt8mSBYXSMFOp3sa+67TIqcMXoC0DSd
4hC4v4/9giGAxgtMKgus2knYqtWiw1Z++1arjTQVwPqFnM2lRvCsDsyN7xbJWN1abeJj+wD5
or0DERg+JeNl/C9kMhVhqnit1kvgBqcXjvXS56hmlsp2B6jaLjjt92D3EZTtQlYt7OmVjDU8
RAILXwYrTE2hpEMY6dJPYI1MQbrpCfoFxLbMTGsRJvlFmqctc4Qf9uR4qA2OTBcveqxuTO8L
7ex5gUNhyGMZ4uNRC35xudT+nouFiupIu3Pc7rys1ejqE4cY+yNJzJnmLQv3o259FtigPTrs
1l8eP++cHB4eH7HgiD077Bwenbx47k/5y5PDEz7pHNVPv/4P+Bg9R2MeAAA=

TXP Builders – finely-crafted code, design and txp

Offline

#19 2019-05-07 06:17:23

mori
New Member
Registered: 2019-05-01
Posts: 9

Re: Multi-Lingual Site

Wow! Thank you so so much for the excellent tutorials as always! By far the best I’ve ever experienced, thank you! I can’t express my gratitude enough!

You definitely showed the power of Textpattern! I’ve gone through the basic documentation and will poke around the tags reference a bit more while giving a bit more thought to how I should set things up.

And thank you! for compiling it for me – worked like a charm.

Update After a bit of thought, I’ve decided to go the route of using the same url with language code query parameter at the end, because the site would have east-asian languages which doesn’t use the alphabet. Although the words could be romanized, the url would be a pain to read and not pretty at all. I’ll take the SEO loss.

Thank you for teaching me how to write code for using distinct urls though! It’s a very good reference for how I should implement my permalinks even when I’m using the query parameter method.

Last edited by mori (2019-05-09 05:36:04)

Offline

#20 2021-04-05 13:23:26

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 220
Website

Re: Multi-Lingual Site

I would like to share my multilingual setup, which is quite similar to what jakob described at the beginning and was actually inspired by it.

  • The plugins adi_menu and smd_query are needed. Hopefully when I dive more into it, there will be other solutions or an extra plugin to simplify things and also to have less extra queries.
  • Pages can only be used on a per section (group) base (I´ll come to that in a bit.)
  • You will get “speaking” URLs for sections and articles
  • It is quite an easy setup

Things still to be improve:
Show and create relations in the backend between “sister”-articles in the different languages.
The idea is to have the ID of the current article beeing stored somewhere (custom_field) when I copy an article. Like that articles could be easily copied and relate to each other when cloned for the other languages. (Maybe somebody would be interested in working with me on a plugin for that?)
At the moment this is achieved by putting the “sister”-ID manually in a custom_field. Which works fine but could work nicer.

Imagine you are writing the German article and after that you want to create the english article. There could be an extra Button “clone” which does the same than the “Duplicate”-Button but it writes the ID of the article to be cloned in the custom_1 of the cloned article. That would improve things a lot already.

Ok let´s go:

Install adi_menu (Make sure it is the latest version 1.4 with adi_menu_if_info tags)
Install smd_query Version 0.6.0

Create Sections for all the languages that you have (e.g. “en”,“de” etc.).
Have them as level1 sections. Create as many subsections in adi_menu in those language-sections as you need.
For example section “contact” would go as subsection into “en” and section “kontakt” would go into “de” etc.

Create for all those sister-sections unique page-templates. In this example the page-template could be called “contact”.
Every related sections share the same page-template and will be “linked” through it.

A form called “language” will always give you the current language and it contains this:

<txp:adi_menu_if_info type="parent"><txp:adi_menu_info type="parent" /><txp:else/><txp:section/></txp:adi_menu_if_info>

To use it, make sure every page template has this on top:

<txp:variable name="lang"><txp::language/></txp:variable>
<txp::language_snippets/>

The language_snippets form holds unique translation words or phrases for each language.
It could look like this (to split it for better overview):

<txp:if_variable name="lang" value="de">
<txp::language_de/>
</txp:if_variable>
<txp:if_variable name="lang" value="en">
<txp::language_en/>
</txp:if_variable>

The forms language_de and language_en will hold the actual variables.
Like:

<txp:variable name="more" value="mehr dazu"/>@ or @<txp:variable name="more" value="more"/>

For the language switcher create a form called “langswitcher” with the following content:

<txp:adi_menu_if_info type="parent">
<txp:if_article_list>
<txp:smd_query query='SELECT name,adi_menu_parent FROM txp_section WHERE page IN (SELECT page FROM txp_section WHERE name = "?s")' wraptag="ul" break="li">
<a href="/{name}/">{adi_menu_parent}</a>
</txp:smd_query>
<txp:else/>
<txp:smd_query query='SELECT url_title, Section, adi_menu_parent FROM textpattern
LEFT JOIN txp_section ON Section = name WHERE id = "<txp:article><txp:custom_field name="Clon von"/></txp:article>" OR custom_1 = "<txp:article><txp:article_id/></txp:article>" OR id = "<txp:article><txp:article_id/></txp:article>"' wraptag="ul" break="li">
<a href="/{Section}/{url_title}/">{adi_menu_parent}</a>
</txp:smd_query>
</txp:if_article_list>
<txp:else/>
<ul>
<li><a href="/de/">de</a></li>
<li><a href="/en/">en</a></li>
</ul>
</txp:adi_menu_if_info>

and put <txp::langswitcher/> where you want your language to be switched… footer or header…whatever.
That will handle the language switching on home, sections and articles.

To be able to continously use “if_section” on your pages, create another form called “sectiongroup”.
It should contain:

<txp:smd_query query='SELECT name FROM txp_section WHERE page = "<txp:yield name="n"/>" AND adi_menu_parent = "<txp::language/>"'>{name}</txp:smd_query>

Let´s say you want to put <txp:if_section> and it should respect the current language it would be now enough to know the name of the page beeing used and it will work in both languages like that:

<txp:if_section name='<txp::sectiongroup n="contact"/>' />

<txp::sectiongroup n="xxx"/> will always give you the correct section for your current language.

That is basically it.

Put this in your htacces to make it always start with /de/

RedirectMatch 301 ^/?$ /de/

Enjoy. Comment. Improve.

Last edited by demoncleaner (2021-04-05 13:37:37)

Offline

#21 2021-04-05 19:38:05

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,094
Website Mastodon

Re: Multi-Lingual Site

demoncleaner wrote #329670:

I would like to share my multilingual setup, which is quite similar to what jakob described at the beginning and was actually inspired by it.

cool. thanks for the tutorial


…. texted postive

Offline

#22 2021-04-05 20:03:57

demoncleaner
Plugin Author
From: Germany
Registered: 2008-06-29
Posts: 220
Website

Re: Multi-Lingual Site

You are welcome. I am curious if it works for you.
I just realized that I forgot one thing.
To make it work you would need a custom field on custom_1 called “Clon von”.
If you change the name, make sure you change it in the langswitcher form, too.
Or better choose a more general syntax if possible.

When I tried

WHERE id = "?custom1"

instead of

WHERE id = "<txp:article><txp:custom_field name="Clon von"/></txp:article>"

it was not working. I don´t really know why.

Offline

#23 2021-04-06 09:44:12

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

Re: Multi-Lingual Site

demoncleaner wrote #329670:

Enjoy. Comment. Improve.

Very intriguing. I’m not sure if I’ve understood it all, but am I right in assuming this is the basic setup:

  • txp sections with each language prefix (e.g. de and en)
  • further txp sections for each language’s named section (e.g. ueber-uns, kontakt, … and about, contact,…)
  • assign language sections to language prefix section (the “parent”) using adi_menu
  • language lookup for a section by checking its adi_menu parent
  • coupling of de+en sections via the same page template (e.g. a different page template for each section pair)
  • coupling of de+en articles via a custom field holding the reciprocal article id
  • language snippets as a set of txp variables loaded at page begin, then used throughout the page.
  • use htaccess to set default language

I like the idea, and an advantage might also be that it can accommodate multiple languages better than other methods. Having not really used adi_menu, I’d not thought of that way, so it’s certainly interesting. It does involve observing a set of dependencies, like the same page templates.

I’ve done a similar structure that probably involves fewer queries but then also more manual definitions of correspondences between sections (using section custom fields via jcr_section_custom) and articles (using a custom field like you have). I have a small unpublished plugin (that Stef may have passed on to you) for inserting the language prefix at the beginning of the url. That can be retrieved from each url and if you name your snippets and custom fields with language prefix, you can use the language_prefix as a tag-in-tag for outputting corresponding links, text snippets etc. There’s perhaps fewer queries to construct but more manual definition involved. Swings and roundabouts. It also gets exponentially more complex/laborious the more languages you have.

One more thing: how have you dealt with things like image captions?

Saving queries

One way to save the number of queries is to place some of those as page variables at the top of your page, and then use the variables in the rest of your page template.

“Duplicate page” function to show and create relations in the backend between “sister”-articles in the different languages.

Yes, I agree: something that could hook into the “Duplicate” function and do the following:

  • Store the “current article id”.
  • Identify “next article id” for new duplicate article.
  • Place “next article id” in designated custom field in the current article and save.
  • Create new duplicate article and place “current article id” in the designated custom field of the new article.

That would make the process a bit more automatic than the current manual assignment.


TXP Builders – finely-crafted code, design and txp

Offline

#24 2021-04-06 09:59:34

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

Re: Multi-Lingual Site

jakob wrote #329682:

I have a small unpublished plugin (that Stef may have passed on to you) for inserting the language prefix at the beginning of the url.

I haven’t passed it on. Was waiting until you’d had a chance to play with the prefs tweaks I made and whether using Oleg’s suggestion for URL wrangling would cut down on plugin code needed (and hence development effort in future as our permlink schemes change).


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

Board footer

Powered by FluxBB