Jump to content

How to set up a multilanguage site using a single page tree


choppingblock
 Share

Recommended Posts

Hi all,

I just switched to processwire from MODx and I am really impressed of how clean, fast and intuitive this system is.

My first project with processwire happens to be a multi language site, and I am really happy that it can be done with a single page tree.

However, I had to dig the forums a lot to find all information i needed to get everything working, so I thought I share my newly gained knowledge... :)

The order of the steps is important, especially if you are working on IIS (which can inflict database damage if you add languages before you change the field types!)

1. Install the Language support modules:
    - Languages Support
    - Languages Support - Fields
    - Languages Support - Page Names

2. Change any existing Fields of types Textfield/Textarea/PageTitle to TextLanguage/TextareaLanguage/PageTitleLanguage
You now will have an input field for each language you add.

3. Set up your languages under Setup->Languages (define a name and title for each language. For each new language, you will have to add a title to all the other languages in that new language)

4. Edit your homepage, set it to hidden and unpublished.

UPDATE: don't set the homepage to unpublished, the first-child-redirect won't work! (I realized just now, because if you are logged in as admin, it does work)


For each language, you have to define a unique name (e.g. "de" and "en")

5. Edit your "home" template to redirect to its first child:

<?php
$session->redirect($page->children->first()->url);

UPDATE: this is not essential... as ryan pointed out, it might even be better not to do it (for SEO-optimization)


6. If you have something like   

$children->prepend($homepage); 

in the menu part of your head.inc, remove it (you don't want the home page to show up in your menu)

UPDATE: if you left out the redirect option, you'll want to leave this out as well.


7. To switch languages, add this snippet to your head.inc:

<ul>
<?php
    $user_lang = $user->language;
    foreach($languages as $language) {
        $user->language = $language;
        if($language->name != $user_lang->name) {
            echo '<li><a href="'.$page->url.'">'.$language->title.'</a></li>
                 ';
        }
    }
    $user->language = $user_lang;
?>
</ul>

Each language except the currently active one will be displayed in a list (of course, this can also be done with a select field).

UPDATE: Ryan pointed me to a better solution for the langugae switch: http://processwire.c...s-urls/?p=33537

8. Done. Now your page urls should look something like path/to/root/en/my-page, or path/to/root/de/meine-seite

It took me less than a day to set up processwire, install my html template and configure the site to be multi-language... this is so great, considering the pain multilanguage sites usually cause with all the other CMSs...

Keep it up! ^-^

UPDATE: I was a bit quick to post a tutorial just after one day working with PW... should have made some more research beforehand. Just got a little too excited there... ;)

I'm still impressed by the system and plan on digging deeper into it.

  • Like 11
Link to comment
Share on other sites

The order of the steps is important, especially if you are working on IIS (which can inflict database damage if you add languages before you change the field types!)

I wonder why this is the case? Sounds like bug to me, I will have to try and duplicate. Has anyone else run into this?

4. Edit your homepage, set it to hidden and unpublished.

I'm unclear about why the homepage should be hidden and unpublished?

5. Edit your "home" template to redirect to its first child:

From an SEO standpoint, I think it's a little better to let your homepage (root, no language segment) serve as the homepage for your default language. The thinking here is that people often link to your domain rather than a specific page in the domain. It's technically stronger to have those links resolve to an actual page rather than to a redirect. 

7. To switch languages, add this snippet to your head.inc:

Here's another good example of a language switcher that uses the multi-language page names module:

http://processwire.com/talk/topic/2979-multi-language-page-names-urls/?p=33537

  • Like 2
Link to comment
Share on other sites

The order of the steps is important, especially if you are working on IIS (which can inflict database damage if you add languages before you change the field types!)

I wonder why this is the case? Sounds like bug to me, I will have to try and duplicate. Has anyone else run into this?

Unfortunately, I have no idea why this happens... it seems the creation of the additional fields in the pages table does not work.

 
4. Edit your homepage, set it to hidden and unpublished.
I'm unclear about why the homepage should be hidden and unpublished?

The intention was to have the home page as kind of a switch for all the content pages... and redirect to the respective pages in the currently active language if needed. Thinking about this again, this is not necessary because there is a default language...

 
5. Edit your "home" template to redirect to its first child:

From an SEO standpoint, I think it's a little better to let your homepage (root, no language segment) serve as the homepage for your default language. The thinking here is that people often link to your domain rather than a specific page in the domain. It's technically stronger to have those links resolve to an actual page rather than to a redirect.

Absolutely right... this relates to the idea of having a language switch in the homepage (s. above)

Here's another good example of a language switcher that uses the multi-language page names module:

http://processwire.c...s-urls/?p=33537

It's not another "good one", it's definitely a "much better one"! Thanks.

I'll try to do some more research before posting in the tutorials section again... ;)

Link to comment
Share on other sites

I think it's great that you wrote the tutorial. It shows how easy it is to create a multilanguage site with PW. Maybe you could update the original post with Ryan's suggestions.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...