26

Re: Multi Language How to

@David
I try your solution but I have a problem with displaying the translated content. Changing names in the sidebar works fine. But the content of the page not. I have enabled multilanguage plugin as tab and language source as uri.

Thumbs up

27

Re: Multi Language How to

@xkapr - The system I used/documented was devised before Martijn produced the multi-language plugin, and the two approaches are indepdent.

I recommend using the plugin, because it is integral to Wolf and as a "core" plugin, will be maintained and developed.

The system I described (and demo'ed) is there as an alternative, and illustrates a technique that can be used for different "switching" situations. But it does not use the multi-language plugin. You need to follow the instructions in the wiki to get the content to "change".

If I haven't understood your problem, please ask again!

28

Re: Multi Language How to

@David
I want to use this solutions because of translated titles. I followed the wiki and se no mistake. I also disable the multilanguage plugin, and still no different content. Titles and menu are translated with no problem.
If I understand well the source in the wiki there is no code to overwrite the content. There is a snippet that replaces title but no content. Or am I blind?

Thumbs up

Re: Multi Language How to

@xkapr - if you set the multiple languages plugin to "translation as page" instead of "translation as tab", you can also translate the page title as long as the slug remains the same.

(the slug needs to remain the same as the original because the system needs to be able to know its the same page as the original)

Wolf CMS founder and lead developer
Please always check the Support forums and Wiki before asking. (My Ohloh account.)
Like Wolf CMS? Consider making a financial contribution.

30

Re: Multi Language How to

Hi,
havin problems using the multilanguage plugin.

Plugin set to:
Style: Translations as page copy
Language: URI

My first level navi set as:

<ul>
            <? foreach ($this->find("/")->children() as $child) { ?>
              <li class='<? echo $child->slug ?>'><? echo $child->link('<span>'.$child->title.'</span>', (url_start_with($child->url) ? ' class="current"': null)) ?></li>
            <? } ?>
            </ul>

My tree is build like:
HOME PAGE (slug can not be changed)
- level 1
- level 2
....
- en
  - copy of level 1 (slug the same as level 1)
  - copy of level 2 (slug the same as level 2)
...

Problem is, that i get EN in the upper navigation.

I thought, that wolf recognizes the language pack automaticly?

Thumbs up

Re: Multi Language How to

It's working perfectly. You selected the "URI" option. That means the language to use is embedded in the URL. Also, you've selected "Translations as page copy" which means a page (and its children) should be created for each language you support.

When you write your menu code, you are responsible for skipping the pages intended for translations.

An easy way to do this is by setting (for example) the "nl" page (for dutch) to status "hidden". That will prevent it from showing up in the results of the children() function in normal use.

Wolf CMS founder and lead developer
Please always check the Support forums and Wiki before asking. (My Ohloh account.)
Like Wolf CMS? Consider making a financial contribution.

32

Re: Multi Language How to

Hello, thanks for the interesting discussion on multilingual sites. I am trying to use the core plugin and facing some difficulties. My ambition is to develop the site in english, french, and hindi. for the moment, I am trying english and french, but not successful.
Style: translation as page copy
Language source: URI

Page tree:
Home page
- Computing
- fr (hidden)
  - Computing (copy)
I try to modify the content of the copy under fr (i keep the same slug, computing) but when i save it deletes the content and gives errors
Illegal value for created_on_time and published_on_time fields
any insight would be helpful.
thanks in advance.

Thumbs up

33

Re: Multi Language How to

I think that I have found the cause of this error. If I create a copy of a page and move it using the reorder function in the tree I get this error. However, if i create a fresh page under fr, and paste the content in it, this works fine. perhaps a bug which links it to the slug of the english page and consider a duplicate?
i have another question. how do i create the equivalent home page in french. i think this will have to be done with the top level page "fr" which is hidden for the moment, but haven't yet figured out how so that all the links make reference to the french pages. also, are there any snippets for putting the languages on the home page from which the visitors can choose?
the skeleton of the site is at http://shail.free.fr it doesn't contain anything but some content from a very old site.
thanks in advance for your help.

Thumbs up

34

Re: Multi Language How to

hello again, i have another issue with the display of UTF-8 characters in the title. if you go to http://shail.free.fr/cms/?articles/2004 … ticle.html the title appears for a few seconds and then disappears. do i need to set UTF encoding somewhere, i didn't find it yet.

Thumbs up

35

Re: Multi Language How to

mvdkleijn wrote:

4) The multiple languages plugin does not affect the menu in any way.

Hi Martijn,
is there an easy way to have the menu also translated?

Thumbs up

Re: Multi Language How to

kirk wrote:
mvdkleijn wrote:

4) The multiple languages plugin does not affect the menu in any way.

Hi Martijn,
is there an easy way to have the menu also translated?

Through the plugin? Currently no... since the menu systems on sites are built by the designer themselves and not by Wolf CMS, I've not provided for any functionality for that.

Why? Got an idea on how to do it?

Wolf CMS founder and lead developer
Please always check the Support forums and Wiki before asking. (My Ohloh account.)
Like Wolf CMS? Consider making a financial contribution.

37

Re: Multi Language How to

My way is (using tabs):
step 1: add to MultiLangController.php file

    public static function translateTitle($page)
    {
        if ($page->hasContent('titles')):
            $titles2 = $page->content('titles');
            $res = preg_match('/'.I18n::getLocale().':\s*(.*)/i', $titles2, $results2);
            if($res == 1):
                $title2 = trim($results2[1]);
            else: 
                $title2 = $page->title();
            endif;
        else:
            $title2 = $page->title();
        endif;
        return $title2;
    }

step 2: add tab titles to pages and complete
en: english tiltle
pl: polski tytuł
de: deutsch titel
...
step 3: in Your theme

<title><?php echo MultiLangController::translateTitle($this); ?></title>

nav

 <li><?php echo $menu->link(MultiLangController::translateTitle($menu), (in_array($menu->slug, explode('/', $this->url)) ? ' class="current"': null)); ?></li>

Hope it help

Last edited by djgprv (2012-05-13 09:50)

"Everyone knows something cannot be done. Then along comes a man who does not know that it cannot be done and does it."
Albert Einstein

38

Re: Multi Language How to

@djgprv,
Thank you for sharing,
I opted for the page copy option because i intend to use page parts within my pages.

@ Martijn,

At the moment I'm looking for hint on how to tackle the problem.
my set up is:
HTTP
page copy

as a simple hack i was thinking to check the URL just before building the menu and if the code fr, en etc  is found squeeze it in as per below.

$lang = '';
$mylang = array(en, it, fr, de, nl);

explode URL into an array, trim the '?'  if necessary and search array($mylangs) against code in the URL.
if the search produce a result; set the variable $lang otherwise leave it as default to be used as per below.

foreach($this->find('/$lang')->children() as $menu): ?>

I look forward for your thoughts on this.

Last edited by kirk (2012-05-13 04:10)

Thumbs up

Re: Multi Language How to

@kirk,

If you're using the setup where the language is part of the URI ("uri" option in the plugin) , you can do it in a similar way as the Multiple Languages plugin itself does it. The plugin fist calls replaceUri() and then replaceContentByUri() based on events.

The first function determines what the requested language is based on the keys of the SettingController::$iso_639_1 array. It stores that in a GLOBAL variable called $urilang. That variable is used by the second function to actually replace the content.

You could use a similar tactic and reuse the $urilang variable which I believe should be available already by the time your menu code is executed. Translated page names could be stored in page parts called "fr_title", "nl_title" etc... your code can then replace the title by $urilang.'_title'...

If you, for example, want to use the browser preferences ("header" option in the plugin) to determine the language, you can just call:

        use_helper('I18n');
        $found = false;

        foreach (I18n::getPreferredLanguages() as $lang) {
            if ( Setting::get('language') == $lang) { break; }

            if ( your language specific part exists based on $lang ) {
                // do your thing
                $found = true;
            }

            if ($found) break;
        }
Wolf CMS founder and lead developer
Please always check the Support forums and Wiki before asking. (My Ohloh account.)
Like Wolf CMS? Consider making a financial contribution.

40

Re: Multi Language How to

Thank you Martijn,
I will be exploring your idea as it's a better solution than mine :-)

The problem is: the URI solution will work when the user select a language or switch between languages.  How do I handle the automatic "redirect"?
I'm thinking to use cookies to do this, basically when an user access the website check if cookie are set up, in case no cookie is found the user is redirected to the language based on the HTTP of his browser and set the cookie.


What are your thought on this? Would you go down the cookie path or there are better way to achieve this?

On another note, as if this was not complicated enough.
How would you handle different domains ie mysite.com, mysite.nl, mysite.it etc etc
Let's say, ideally situation would be to be able to use all domains from a single installation.

Last edited by kirk (2012-05-14 13:40)

Thumbs up

Re: Multi Language How to

kirk wrote:

Thank you Martijn,
I will be exploring your idea as it's a better solution than mine :-)

You're welcome. There are probably better ways too. smile

kirk wrote:

The problem is: the URI solution will work when the user select a language or switch between languages.  How do I handle the automatic "redirect"?
I'm thinking to use cookies to do this, basically when an user access the website check if cookie are set up, in case no cookie is found the user is redirected to the language based on the HTTP of his browser and set the cookie.

What are your thought on this? Would you go down the cookie path or there are better way to achieve this?

If you want users to be able to dynamically select their language based on the flag they click for example (which sounds like your plan), then the cookie way is just about the only way.

When no cookie is set, you'll have to either assume the default language of the site or determine the desired language some other way like you said.

Once the user makes a selection (or you did it for them), a cookie should be set that's checked and acted upon every time the user wants to view a page. This last part can be achieves by using the Observer system and watching for the page_found event.

kirk wrote:

On another note, as if this was not complicated enough.
How would you handle different domains ie mysite.com, mysite.nl, mysite.it etc etc
Let's say, ideally situation would be to be able to use all domains from a single installation.

I would probably change config.php to dynamically determine the URL_PUBLIC:

// The full URL of your Wolf CMS install
define('URL_PUBLIC', 'http://'.substr(dirname($_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']), 0, strrpos(dirname($_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']), '/wolf')).'/');

HOWEVER, its important that only domain names belonging to your site resolve to that site. In this sort of setup Wolf CMS would accept just about any domain name for its site.

Wolf CMS founder and lead developer
Please always check the Support forums and Wiki before asking. (My Ohloh account.)
Like Wolf CMS? Consider making a financial contribution.

42

Re: Multi Language How to

if I make a suggestion
@kirk - i use session.
Index.php

'type'=>    'both'
...
Dispatcher::addRoute(array(
    '/multi_lang_switchLanguage/:any' => '/plugin/multi_lang/switchLanguage/$1'
));
..
    elseif ($source == 'session') {
        Observer::observe('page_found', 'replaceContent');
        Observer::observe('page_requested', 'replaceUri2');
    }
...
/* replaceContent */
    else if ($source == 'session' && $style == 'tab') {
        use_helper('I18n');
        $found = false;
        if ( isset($_SESSION['lang']) ) $lang = $_SESSION['lang']; else $lang = I18n::getLocale();
        I18n::setLocale($lang);

        if ( isset($page->part->$lang) && !empty($page->part->$lang->content_html) && $page->part->$lang->content_html != '' ) {
            $page->part->body->content_html = $page->part->$lang->content_html;
            $found = true;
        }
        //redirect(BASE_URL.I18n::getLocale().'/'.CURRENT_URI); !!!!!!!!!!!!!!!!!!!!!!!!!!
    }
..
/* 
function replaceUri2($uri) {
    if (startsWith($uri, '/')) {
        $uri = substr($uri, 1);
    }

    global $urilang;
    $tmp = explode('/', $uri, 2);

    if (array_key_exists($tmp[0], SettingController::$iso_639_1)) {
        $urilang = $tmp[0];
        $uri = substr($uri, 2);
    }
    else $urilang = false;

    return $uri;
}

MultiLangController.php

    public static function switchLanguage($lang)
    {
        if(!isset($_SESSION['lang'])) {
            $_SESSION['lang'] = I18n::getLocale();
        } elseif (isset($lang)) {
            $_SESSION['lang'] = $lang;
        }
        if($_SERVER['HTTP_REFERER'] != '') { 
          header('Location: '.$_SERVER['HTTP_REFERER']); // Forward back
        } else {
          header('Location: '.BASE_URL); // Forward home
        }
    }

example fronted link to change language
http://website.com/multi_lang_switchLanguage/en

@mvdkleijn
when i use

redirect(BASE_URL.I18n::getLocale().'/'.CURRENT_URI);

in replaceContent my link loks like: www.yourweb.com/pl/pl/page.html (duble lang)
can you explain? wink

Last edited by djgprv (2012-05-15 20:26)

"Everyone knows something cannot be done. Then along comes a man who does not know that it cannot be done and does it."
Albert Einstein

43

Re: Multi Language How to

Thank you for sharing Djgprv,
by index.php do you mean the index in the root of the site or the index in the multilang plugin folder?
I'll look at this over the weekend. I'll keep you posted on how i go smile

Thumbs up