Welcome, Guest. Please login or register.
Did you miss your activation email?
15 Mar 2010, 01:17

Login with username, password and session length
Home Chat Help Search Calendar Login Register
Pages: [1] 2 3
Print
Author Topic: My trick for multilingual pages with regular CMS v1.0.6  (Read 29021 times)
0 Members and 1 Guest are viewing this topic.
jsmonzani
Forum Members
**

Karma: 4
Offline Offline

Posts: 43


« on: 26 Apr 2007, 13:37 »

Since the multilingual version of CMS is a branch and is not up to date, I've thought about doing an adaptation of the regular templates to support multiple languages.

The idea is to create content blocks for each language within the template. I'm going to use "fr" as another language here

My template looks like this


Code:
{getlang}    (you'll see below)

{if $weblang == "fr"}
  {content block="content_fr"}
{else}
  {content}
{/if}
...

{if $weblang == "fr"}
  {content block="title_fr" oneline="true" wysiwyg="false"}
{else}
  {title}
{/if}

... and something like this to ensure that the template has blocks for menu entries in various languages, although they are not displayed on the template directly...

{if 0}
  {content block="menu_fr" oneline="true" wysiwyg="false"}
{/if}

Languages will be put in the URL like this: index.php?page=id&lang=fr
If you set it once in the URL and don't use it anymore afterwards, the system will default to this language using a cookie.
Here is my tag (getlang)

Tag: getlang

Code:
/* assigns the variable {$weblang} */
global $gCms;
if (isset($_GET["lang"])) { /* Passed in the url: lang= ... */
  $gCms->smarty->assign('weblang', $_GET["lang"]);
  setcookie("MYlang", $_GET["lang"]);
} elseif (isset($_COOKIE["MYlang"])) {
  $gCms->smarty->assign('weblang', $_COOKIE["MYlang"]);
} else {
  setcookie("MYlang", "en");
  $gCms->smarty->assign('weblang', "en");
}

Now, the problem is to have the menus in various languages. I'm going to define this tag, that takes a pageID and returns the proper menu text, depending on the language.

Tag: general_menu_title

Code:
/* param: pageid, assigns {$current_menu_text} */

global $gCms;
$manager =& $gCms->GetHierarchyManager();
/* $thisPage = $gCms->variables['content_id']; */

$thisPage = intval($params['pageid']);
$currentNode = &$manager->sureGetNodeById($thisPage);
$currentContent =& $currentNode->getContent();

if ($smarty->get_template_vars('weblang') == "en") {
$t_ =$currentContent->MenuText();
} else {
$t_ =$currentContent->GetPropertyValue('menu_' . $smarty->get_template_vars('weblang'));
}

$gCms->smarty->assign('current_menu_text', $t_);


Now, in your menu template, replace $node->menutext by this. In order to get the current pageID, I'm gonna use the capture trick.

the code snippet looks like that

Code:
{capture name=MENUNODE}
{$node->id}
{/capture}
{general_menu_title pageid=$smarty.capture.MENUNODE}

and here is a complete basic menu with it... note how I use {$current_menu_text} instead of $node->menutext. All the rest is standard

Code:
{if $count > 0}
<ul>
{foreach from=$nodelist item=node}



{capture name=MENUNODE}
{$node->id}
{/capture}
{general_menu_title pageid=$smarty.capture.MENUNODE}



{if $node->depth > $node->prevdepth}
{repeat string="<ul>" times=$node->depth-$node->prevdepth}
{elseif $node->depth < $node->prevdepth}
{repeat string="</li></ul>" times=$node->prevdepth-$node->depth}
</li>
{elseif $node->index > 0}</li>
{/if}

{if $node->current == true}
<li><a href="{$node->url}" class="currentpage"{if $node->target ne ""} target="{$node->target}"{/if}> {$current_menu_text} </a>

{elseif $node->parent == true && $node->depth == 1}
<li class="activeparent"> <a href="{$node->url}" class="activeparent"{if $node->target ne ""} target="{$node->target}"{/if}> {$current_menu_text} </a>

{elseif $node->type == 'sectionheader'}
<li class="sectionheader">{$current_menu_text}

{elseif $node->type == 'separator'}
<li style="list-style-type: none;"> <hr class="separator" />

{else}
<li><a href="{$node->url}"{if $node->target ne ""} target="{$node->target}"{/if}> {$current_menu_text} </a>

{/if}

{/foreach}

{repeat string="</li></ul>" times=$node->depth-1}</li>
</ul>
{/if}

Hope this will help someone Wink
Logged

An approach to mutli-lingual CMSMS using only content blocks:
http://forum.cmsmadesimple.org/index.php/topic,11756.0.html
cyberman
Support Team
Power Poster
***

Karma: 147
Offline Offline

Posts: 8497

Location: Dohna / Saxony / Germany


Reality.sys is corrupt. Reboot universe (Y/N)?


WWW
« Reply #1 on: 27 Apr 2007, 01:15 »

Many thanks for that.
Logged

"2 hours of try and error can save 10 minutes of manual reading"
(2 Stunden Ausprobieren knnen Ihnen 10 Minuten Handbuchlesen ersparen)
------------------------------------------------------------------------------------
Fr deutschsprachige Anwender / for german speaking users only
http://www.cmsmadesimple.de/ - deutschsprachige Support-Seite fr CMS made simple
http://demo.cmsmadesimple.de/ - Informationen der CMSms-Musterinstallation in deutsch
http://wiki.cmsmadesimple.org/index.php/Main_Page/de - deutschsprachiges Wiki fr CMS made simple
http://dev.cmsmadesimple.org/projects/german/ - deutsche Sprachdateien fr CMS made simple
-----
http://themes.cmsmadesimple.org/Full_Themes.html - Templates fr CMS made simple (engl.)
http://www.cmsmadesimple.org/apidoc/ - API fr CMSms 1.x (engl.)
jsmonzani
Forum Members
**

Karma: 4
Offline Offline

Posts: 43


« Reply #2 on: 27 Apr 2007, 02:00 »

No problem. It can't be compared to how many help you've provided us  Wink
Logged

An approach to mutli-lingual CMSMS using only content blocks:
http://forum.cmsmadesimple.org/index.php/topic,11756.0.html
jsmonzani
Forum Members
**

Karma: 4
Offline Offline

Posts: 43


« Reply #3 on: 02 May 2007, 07:30 »

Also, if you have problems with the search module, have a look there:
http://forum.cmsmadesimple.org/index.php/topic,11845.0.html

Cheers
Logged

An approach to mutli-lingual CMSMS using only content blocks:
http://forum.cmsmadesimple.org/index.php/topic,11756.0.html
moorezilla
Power Poster
***

Karma: 12
Offline Offline

Posts: 299


« Reply #4 on: 02 May 2007, 08:02 »

First of all, thanks very much for your work on this, and for sharing it! I have a few questions about taking this approach to multi-lingual sites, and about some ideas it raises.

1. Since the language chosen is contained by the url, do you know if "pretty" urls using Apache's rewrite engine will still work properly?
2. Is the change made to the search module a change that should be added to svn, or is there a potential disadvantage for people not using multiple content blocks?
3. I know that multi-language capabilities are not listed as part of the next release, but does anyone involved with coding the base package have an opinion on the best method for ultimately adding this capability to the core? In other words, does anyone have an opinion on whether the earlier multi-lingual project (a fork using a separate install package), or this new method represent a good logical base for adding this functionality to the core, or should these be seen more as stop-gap measures that will ultimately be replaced by something significantly different?

I do not in any way want to detract from the efforts of these two projects, and I'm using the term "stop-gap" only because my vocabulary fails to provide me with a better term; I'm just curious if either of these methods for multi-lingual support can/should/might be adopted by the cmsms team as a platform for adding this functionality to the core.

Thanks,
am
Logged
jsmonzani
Forum Members
**

Karma: 4
Offline Offline

Posts: 43


« Reply #5 on: 04 May 2007, 09:27 »


> 1. Since the language chosen is contained by the url, do you know if "pretty" urls using Apache's rewrite engine will still work properly?

Probably not, but don't forget that you only need to use the language parameter on one page, it is then stored in a cookie so that all other links don't need to specify it. So you can easily make a version that works with the pretty urls, by setting the cookie yourself.

The code works this way:

1. index.php?page=1&lang=fr  -> display the French block and stores French as the default language in a cookie
2. index.php?page=1 -> no language is specified. Either
    - pick up English if no cooky was set
or - use the latest language stored in a cookie


> 2. Is the change made to the search module a change that should be added to svn, or is there a potential disadvantage for people not using multiple content blocks?

I have submitted it and it will be fixed in the next version

> 3. I know that multi-language capabilities are not listed as part of the next release [...]

Actually, it's in the roadmap, I think

Cheers

JS
Logged

An approach to mutli-lingual CMSMS using only content blocks:
http://forum.cmsmadesimple.org/index.php/topic,11756.0.html
moorezilla
Power Poster
***

Karma: 12
Offline Offline

Posts: 299


« Reply #6 on: 04 May 2007, 10:31 »

Sounds good. Thanks!
am
Logged
Pierre M.
Support Team member
Support Guru
Power Poster
****

Karma: 32
Offline Offline

Posts: 3736

Location: Paris

Please keep it simple


« Reply #7 on: 04 May 2007, 12:03 »

Hi folks !

Very interesting !-)

...In other words, does anyone have an opinion...

I'm following moorezilla warning that my own wording may not be appropriate to avoid hurting the nice people who make efforts to improve CMSms. I have an opinion, a strong one, indeed. Disclaimer : I'm not a CMSms dev, I'm not improving the code, but I'm a happy user aiming at simplicity and web standards. So please don't be hurt by my words.

My "best-idea-to-design-a-multilingual-CMS" is the "single tree of content". Hopefully, katon has written is this forum that his MLE fork is "single tree of content" designed. It means that the site content is organized as usual (a hierarchy deep as you want, may be flat) but that each leaf may be available in multiple "flavours", the languages. I think it is The Right Way(TM;) because it is how the web is supposed to work. The feature of the HTTP protocol implementing this is named "transparent content negociation" (TCN). Here is an outdated (2000) page about it : http://gewis.win.tue.nl/~koen/conneg/ Here is a demo : http://www.debian.org/intro/cn Here is my previous post about it : http://forum.cmsmadesimple.org/index.php/topic,11214.0.html

I would like CMSms to be multilingual (you can search for my commitment to this in these forums). This is why I like what katon and jsmonzani have made so far. I'd like to stress the "single negociated tree" design pattern because I think it is best of all worlds :
-Pretty URLs aren't touched. You still make the rewriting you want and have the URL you want.
-TCN is automatic and user friendly (and your browser is allready configured for it - all browsers, in fact).
-Universality : no need for cookie hacking, just actual HTTP headers.
-It keeps CMSms simplicity : the templates are not modified. CMSms just serves the requested flavour of the same content bloc. In the admin, we can add as many flavours as we like, just tagging them with "en", "fr", "es", "it", "de", "ru"...
-As it is HTTP implemented, it is webserver cache friendly.

I'd like it be done the web way, the simple way, the CMSms way.

katon once began the work. Now jsmonzani has made steps to resurect it. I'm respectfully suggesting to work with the devs at the core level rather than at the templating hack level. I wish fun coding days to all people involved.

Hope this helps, hope this doesn't hurt.

Pierre M.
Logged

-- Pierre, support team member. comodrateur du forum francophone.
Please read "how to submit installation/support requests" before posting. Don't send private messages to ask for support.
Want to contribute to CMSms ? Improve the wiki with your forum account.
jsmonzani
Forum Members
**

Karma: 4
Offline Offline

Posts: 43


« Reply #8 on: 07 May 2007, 05:24 »

Thanks Pierre,

Sure, the multiple tree is a simple way to solve the problem. Since some of  my clients asked me to have a single page, this template works better for them.

I would love to contribute to developing the core but I really don't have time to put efforts on that: I'm working as a designer, not a developer (even though it wouldn't be a problem) so I try to avoid debugging code as much as possible Wink Wink

Cheers

JS
Logged

An approach to mutli-lingual CMSMS using only content blocks:
http://forum.cmsmadesimple.org/index.php/topic,11756.0.html
Pierre M.
Support Team member
Support Guru
Power Poster
****

Karma: 32
Offline Offline

Posts: 3736

Location: Paris

Please keep it simple


« Reply #9 on: 07 May 2007, 07:44 »

Hello all,

I agree this is a nice tip for a single page.

Let's hope the devs will find some time to implement TCN with multiflavour same bloc in unchanged templates. I'm sure there is already some GPL code about this on the web.

Pierre M.
Logged

-- Pierre, support team member. comodrateur du forum francophone.
Please read "how to submit installation/support requests" before posting. Don't send private messages to ask for support.
Want to contribute to CMSms ? Improve the wiki with your forum account.
OlafNoehring
Forum Members
**

Karma: 3
Offline Offline

Posts: 78


« Reply #10 on: 23 May 2007, 08:57 »

Hi

quick question:
how can I write the page id of the current page into the HTML (using php). I want to be able to let the user return to the page where he changed the language.

Example: You are on page (ID=7) "Products" and change the language. You should not return to the main page but to the page "Products" - with the chosen language.

Say I am stupid, but I was not able to figure it out, so I decided to ask you.

Thanks already
Olaf
Logged
OlafNoehring
Forum Members
**

Karma: 3
Offline Offline

Posts: 78


« Reply #11 on: 23 May 2007, 14:07 »

Hi

ok

I got the page id now ... try - and much errors -:

I add this to my page (of course you need to enable the {php} in your config.php:

Code:
{php}
global $gCms;
$tpl_vars = $gCms->smarty->get_template_vars();
echo $tpl_vars["page_id"];
{/php}

Olaf
« Last Edit: 23 May 2007, 14:19 by OlafNoehring » Logged
alby
Member Support Team
Support Guru
Power Poster
****

Karma: 139
Offline Offline

Posts: 4687

Location: Ferrara, Italy


My kids


« Reply #12 on: 23 May 2007, 15:36 »

I add this to my page (of course you need to enable the {php} in your config.php:

Try with UDT (better and secure):

Code:
global $gCms;
$smarty =& $gCms->GetSmarty();
echo $smarty->get_template_vars('page_id');


Alby
Logged

Blue_Guru
Peanut Gallery


Karma: 0
Offline Offline

Posts: 5


« Reply #13 on: 13 Jun 2007, 09:20 »

Hey all

first let me thank you for this wonderful multilanguage instructions, worked perfectly for the content and the menu  Smiley

But unfortunately I have problems with some of the modules I used:

1) breadcrumbs
the breadcrumbs are always shown with the menutext of the default language. I looked into the function.breadcrumbs.php but I don't have a clue how and where to change it to use the added second language menutext.
Would be great if somebody could have a look at that, my php-skills are way too bad Roll Eyes

2) print
with the print module there is a similar problem. It it will always print the original default content, but not the content of the added second language. Any ideas how to make it use the other content ?

3) news
guess adapting of the news module for two languages would pretty complex ?

Any help will be greatly appreciated !

Thanks!
« Last Edit: 13 Jun 2007, 09:23 by Blue_Guru » Logged
theredspecial
Forum Members
**

Karma: 0
Offline Offline

Posts: 31


« Reply #14 on: 13 Jun 2007, 11:05 »

Before posting my question let me sincerely apologize for the possible stupidity of the question.
I'm new to CMSMS and working out its capabilities for the site(s) I want to design. I only designed 1 Joomla-site before, but feel CMSMS is better for my 'client' and easier to design.

But, let's get down to business:
I like the idea of this smooth and easy tweak, but have no idea where to put the code (or at least the first part)
Thus: where do I put the code?
Logged
Pages: [1] 2 3
Print
Jump to: