My trick for multilingual pages with regular CMS v1.0.6

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
jsmonzani
Forum Members
Forum Members
Posts: 54
Joined: Mon Apr 03, 2006 10:58 am

My trick for multilingual pages with regular CMS v1.0.6

Post by jsmonzani »

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: Select all

{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: Select all

/* 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: Select all

/* 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: Select all

{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: Select all

{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 ;)
An approach to mutli-lingual CMSMS using only content blocks:
http://forum.cmsmadesimple.org/index.ph ... 756.0.html
cyberman

Re: My trick for multilingual pages with regular CMS v1.0.6

Post by cyberman »

Many thanks for that.
jsmonzani
Forum Members
Forum Members
Posts: 54
Joined: Mon Apr 03, 2006 10:58 am

Re: My trick for multilingual pages with regular CMS v1.0.6

Post by jsmonzani »

No problem. It can't be compared to how many help you've provided us  ;)
An approach to mutli-lingual CMSMS using only content blocks:
http://forum.cmsmadesimple.org/index.ph ... 756.0.html
jsmonzani
Forum Members
Forum Members
Posts: 54
Joined: Mon Apr 03, 2006 10:58 am

Re: My trick for multilingual pages with regular CMS v1.0.6

Post by jsmonzani »

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

Cheers
An approach to mutli-lingual CMSMS using only content blocks:
http://forum.cmsmadesimple.org/index.ph ... 756.0.html
moorezilla

Re: My trick for multilingual pages with regular CMS v1.0.6

Post by moorezilla »

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
jsmonzani
Forum Members
Forum Members
Posts: 54
Joined: Mon Apr 03, 2006 10:58 am

Re: My trick for multilingual pages with regular CMS v1.0.6

Post by jsmonzani »

> 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
An approach to mutli-lingual CMSMS using only content blocks:
http://forum.cmsmadesimple.org/index.ph ... 756.0.html
moorezilla

Re: My trick for multilingual pages with regular CMS v1.0.6

Post by moorezilla »

Sounds good. Thanks!
am
Pierre M.

Re: My trick for multilingual pages with regular CMS v1.0.6

Post by Pierre M. »

Hi folks !

Very interesting !-)
moorezilla wrote: ...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.ph ... 214.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.
jsmonzani
Forum Members
Forum Members
Posts: 54
Joined: Mon Apr 03, 2006 10:58 am

Re: My trick for multilingual pages with regular CMS v1.0.6

Post by jsmonzani »

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 ;) ;)

Cheers

JS
An approach to mutli-lingual CMSMS using only content blocks:
http://forum.cmsmadesimple.org/index.ph ... 756.0.html
Pierre M.

Re: My trick for multilingual pages with regular CMS v1.0.6

Post by Pierre M. »

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.
OlafNoehring
Forum Members
Forum Members
Posts: 78
Joined: Mon Oct 23, 2006 4:43 pm

Re: My trick for multilingual pages with regular CMS v1.0.6

Post by OlafNoehring »

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
OlafNoehring
Forum Members
Forum Members
Posts: 78
Joined: Mon Oct 23, 2006 4:43 pm

Re: My trick for multilingual pages with regular CMS v1.0.6

Post by OlafNoehring »

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: Select all

{php}
global $gCms;
$tpl_vars = $gCms->smarty->get_template_vars(); 
echo $tpl_vars["page_id"];
{/php}
Olaf
Last edited by OlafNoehring on Wed May 23, 2007 6:19 pm, edited 1 time in total.
alby

Re: My trick for multilingual pages with regular CMS v1.0.6

Post by alby »

OlafNoehring wrote: 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: Select all

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

Alby
Blue_Guru

Re: My trick for multilingual pages with regular CMS v1.0.6

Post by Blue_Guru »

Hey all

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

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 ::)

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 edited by Blue_Guru on Wed Jun 13, 2007 1:23 pm, edited 1 time in total.
theredspecial
Forum Members
Forum Members
Posts: 31
Joined: Tue Jun 05, 2007 5:36 pm

Re: My trick for multilingual pages with regular CMS v1.0.6

Post by theredspecial »

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?
Locked

Return to “Tips and Tricks”