Jump to content

Some questions (Plus tutorials on how to support multiple languages)


Snakehit
 Share

Recommended Posts

First of all I want to congratulate you with the wonderfull work you did for this CMS system. I've been trying out the demo multiple times and it looks very good, but like always there's a but :-)

Some questions:

1) Can we make a multilangual site with ProcessWire? I can't find the place for adding languages.

2) The tree at the first page of ProcessWire doens't have the 'looks' for a real pagination tree. Maybe by adding some indent lines it would look better.

3) Is there any way for creating some easy contact form or gallery module?

Thanks in advance.

Link to comment
Share on other sites

Hi Snakehite,

welcome to forums.

1. Currently there is no option of multiple languages (i.e. one tree with pages with multiple languages). However, there is an option how to do it (How am I currently doing it):

  • you'll create your languages as subpages of root – e.g. '/es/' for spanish tree and '/en/' for english tree and continue as if you administrated two separated sites (one for spanish and one for english)
  • Unfortunately, this system needs a bit of more of your attention to keep the trees mirrored (so every /es/ URL has its opposite in /en/ branch)
  • for common parts of templates, e.g. footer and header and site title, I created one custom template with few textareas, called it 'various-parts' and have it hidden in each language branch, then in template you do something like $partials = $pages->get($language.'/various-parts/');

For starters, it is a bit awkard, but it'll work. We're trying to come up with a better solution with Ryan, but if you have any ideas hwo to make it work, let Ryan know.

2. Noted (and I already told Ryan a while ago :), but there is other stuff to do right now :( – you could even use your own admin theme if you wish :)

3. as for contact form, I'll let Ryan answer that part (I haven't set up contact so far, so I'm no sure), but as for gallery – just have 'images' field, which gives you an array of images. Just let it output in your template, where you can use whatever client-sdie code you wish. (I'm currently setting up custom jQuery Cycle gallery – http://malsup.com/jquery/cycle/ for example.

Adam

Link to comment
Share on other sites

1) Can we make a multilangual site with ProcessWire? I can't find the place for adding languages.

The admin and error messages use language, and we will be getting more language packs for those in the future.  For everything else, ProcessWire is language agnostic and doesn't use language. It doesn't currently provide any specific tools for handling multiple languages (though we are looking at that). But for now, I think there are a lot of approaches you could take, and Adam's approach looks like a good one. Here's another one below. One of the main differences from Adam's example is that this one keeps separate fields for each language on one page, rather than separate pages for each language. Which approach is better will depend on your needs.

Using field names and URL segments to display different languages

Use the $input->urlSegment API variable to check if the last segment of the URL is "es" or "fr" or "en", and have your template output the corresponding field. For example, lets say you had a page called /about/ and these are the language versions you supported (and their corresponding URL):

  • /about/ - The default language page, we'll assume English
  • /about/es/ - The Spanish About Page
  • /about/fr/ - The French Language Page

The /about/ page is used as an example, but this could be for any and/or all pages in your site. You could set it up for one template and use it site-wide.

You would create fields corresponding to the languages that you want to support, and add them to your template. For instance, you might have a field called "body_en" for English, and then one called "body_es" for Spanish, and "body_fr" for French. If you are dealing with lots of fields, you may want to separate them with ProcessWire's FieldsetTab field type, which will place each language version on a separate tab, compartmentalizing each language on it's own screen.

Then you would enable URL segments for your template(s) in the admin (Setup > Templates > Advanced). That ensures that your /about/ page won't show up as a 404 page when someone accesses /about/es/ (because the es/ doesn't actually exist).

The API code in your template might look like this:

<?php

// other languages that we support in addition to English
$languages = array('es', 'fr'); 

// check if the current page's URL ends with a language
if(in_array($input->urlSegment1, $languages)) {
   // A known language was specified in the URL, so save it in our session. 
   // Now that language will be the default even if URL doesn't have a language specified.
   $session->language = $input->urlSegment1; 
}

if($session->language) {
   // Get the body field for our custom language
   $body = $page->get("body_" . $session->language); 
} else {
   // get the body field for our default language (English)
   $body = $page->body_en;
}

// Output the body text
echo "<div id='bodycopy'>$body</div>";

That will ensure that the correct language is always displayed. They would only have to hit the /about/es/ page once (or any /es/ page), and the rest of the site would then assume it's displaying Spanish regardless of the URL. Likewise, if they hit /about/fr/ next, the site is now in French. If you preferred it, you could relegate this functionality to some gateway page where they had to select a language. But I prefer it this way because they can make language changes on the fly (not that people do that, hehe).

Optional: Locking a language to a URL

It may be that you want to lock your language setting to a URL so that English always displays at /about/ and never Spanish or French. Likewise, the only time you'd see Spanish is if you were at the /es/ version of a given page. The advantage of this approach is that you may get 3 different language versions of your site indexed in Google, and it will be possible for you to use template caching. (You wouldn't be able to use template caching in the previous example because it's session-dependent rather than URL-dependent).

To do this, you would just need to pay attention to the language setting when you create your navigation, and you would update the example above to show the "body" field according to the validated $input->urlSegment1 and not $session->language. Here's how you might create language-aware navigation:

<?php

// determine our language (or reuse the other example)
if(in_array($input->urlSegment1, array('es', 'fr'))) $language = $input->urlSegment1; 
   else $language = 'en';

$topnav = $pages->find("parent=/"); 

foreach($topnav as $item) {
   $url = $item->url;
   // if language isn't English, add a language segment to the end of the URL
   if($language != 'en') $url .= $language; 
   echo "<li><a href='$url'>{$item->title}</a></li>";
}

Optional: Redirecting to the selected language

If you didn't want to always consider language when drawing navigation, you could also just set your pages to redirect to the proper language version if they access the generic /about/ page when the language is Spanish. You'd want to store your language in $session->language again, like in the first example, and perhaps use that instead of the $language variable in the second example.

<?php
if($session->language && !$input->urlSegment1) {
   $session->redirect($page->url . $session->language); 
}

2) The tree at the first page of ProcessWire doens't have the 'looks' for a real pagination tree. Maybe by adding some indent lines it would look better.

I'm not exactly sure what you mean by indent lines. Can you attach a screenshot example or rough mockup of what you mean?

3) Is there any way for creating some easy contact form or gallery module?

While ProcessWire doesn't yet have a public-site form collection feature, making a contact form is a pretty easy thing to do. See this post for an example:

http://processwire.com/talk/index.php/topic,22.0.html

Though I think in most cases, you would probably want to email the submitted form rather than saving it to a page, i.e.

mail("you@company.com", "Contact Form Submitted", $message); 

For an image gallery, Adam is right on. Also see this:

http://processwire.com/talk/index.php/topic,16.0.html

Link to comment
Share on other sites

Not yet, but we'll be making language packs for the admin, and it'll be pretty easy to do (well, the code side of it). The language part I'll need help with. :) I wasn't sure how many would be interested, so that wasn't high on the list before, but there does seem to be interest so it will probably be implemented sooner rather than later.

Link to comment
Share on other sites

  • 4 months later...

I am using this code from Ryan

<?php

// other languages that we support in addition to English
$languages = array('es', 'fr'); 

// check if the current page's URL ends with a language
if(in_array($input->urlSegment1, $languages)) {
    // A known language was specified in the URL, so save it in our session. 
    // Now that language will be the default even if URL doesn't have a language specified.
    $session->language = $input->urlSegment1; 
}

if($session->language) {
    // Get the body field for our custom language
    $body = $page->get("body_" . $session->language); 
} else {
    // get the body field for our default language (English)
    $body = $page->body_en;
}

// Output the body text
echo "<div id='bodycopy'>$body</div>";

this work perfect only the problem is to make change in title field in menu, others fields work nice and translate nice :)

Link to comment
Share on other sites

You'd want to setup your title fields in the same way as your alternate language body fields. But are you talking about the display of the title field in the admin Page List? We don't currently have a way to select a field dynamically according to language in the admin Page List (though we will in 2.2). As a result, separate trees are currently a better solution for multi language if you need the language to be reflected in the admin Page List.

Link to comment
Share on other sites

  • 2 months later...

1. Currently there is no option of multiple languages (i.e. one tree with pages with multiple languages). However, there is an option how to do it (How am I currently doing it):

  • you'll create your languages as subpages of root – e.g. '/es/' for spanish tree and '/en/' for english tree and continue as if you administrated two separated sites (one for spanish and one for english)
  • Unfortunately, this system needs a bit of more of your attention to keep the trees mirrored (so every /es/ URL has its opposite in /en/ branch)
  • for common parts of templates, e.g. footer and header and site title, I created one custom template with few textareas, called it 'various-parts' and have it hidden in each language branch, then in template you do something like $partials = $pages->get($language.'/various-parts/');

For starters, it is a bit awkard, but it'll work. We're trying to come up with a better solution with Ryan, but if you have any ideas hwo to make it work, let Ryan know.

Adam, could you please elaborate on how you're implementing this method ? I know about http://codeordie.posterous.com/multi-lingual-sites-with-the-processwire-cms but some details seem to be missing !? I'm not talking about the YAML part allowing to translate PW messages - I'm not there yet - only about the structure, pages and their content to be made available in different languages.

How did *you* do it ? By any chance, do you have a blank multilingual "demo" website that you'd use as a basis when you're starting a new multilingual project (and would be willing to share  :-* ) ?

Link to comment
Share on other sites

Hey J,

  • I don't have demo how I set up my system
  • that code or die tutorial wasn't made by me :)
  • I'm preparing my own tutorial, but I'm not there yet – I do different tutorial right now, mine should be published somewhere around here in two weeks

If that's okay with you, you can wait. However, if you need faster response, I may create some draft of future tutorial and post it for you somewhere.

Link to comment
Share on other sites

I knew that that codeordie page was not from you (well, I assumed), I just mentioned it in case you wanted to redirect me to it.

I'm not in a hurry, if you think it will be published in two weeks, I can wait...

Meanwhile I will try to figure some things by myself, maybe asking a few questions here and there ;-)

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...