• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 131 posts ]  Go to page 1, 2, 3, 4, 5 ... 9  Next
Author Message
 Post subject: One more approach to build a multilingual site with the regular CMSMS
PostPosted: Fri Feb 01, 2008 8:39 pm 
Offline
Forum Members
Forum Members
User avatar

Joined: Thu Jan 25, 2007 2:54 pm
Posts: 124
Location: España / Hispanujo / Spain
[Update 1: If you start reading this thread here, note that the code has been improved several times since I posted this first message. You can read the messages in chronological order to follow the improvements or jump to the Final step by step implementation guide I posted at the end of the thread with the last version of the code.]

[Update 2/Actualización 2: He publicado una versión en español de la guía final de implementación. I've posted a Spanish version of the final implementation guide.]

[Update 3: You can see a working example of this method in a bilingual personal site of mine:  http://alien.alinome.net.]

[Update 4 (2009-08-26): Pierre-Luc has written a module called Babel, based on this method, easier to use and with more features.]

[Update 5 (2009-09-12): After almost three years, I have decided not to use CMSMS any more. It has become too complex for my needs, version after version, and latest upgrades have broken many things in my code. I ported the site I mentioned in "Update 3" (and others) to a custom Website Revision System of my own, much simpler and productive (wiki-like, no database, straight PHP programming...). The website look is exactly the same than with CMSMS, though.]




Hi all,

Until now I have built only one site with CMSMS, monolingual; but some of my new projects will be in several languages. I could use other tools I used before, but I like CMSMS so much that I decided to give it a chance. I don't reject the idea to test the CMSMS MLE fork, but firstly I wanted to try to squeeze what I need out of the regular version.

I searched the forum for tips on this question and collected some interesting ideas, mainly about the same solution I already had in my mind at first: separated menu branches for the different languages. (By the way, it is really hard to find useful information with the provided search tool, so finally I googled with the "site:cmsmadesimple.org" option). All the approachs I found were (at first sight) too complex and hard to adapt one way or another. I wanted to find a solution as much simple and configurable as possible.

My goals were these:

  • Only one page template for all pages in all languages (though of course you can use more if you like).
  • The language bar buttons should link to the current page translation, not to the home page.
  • Easily configurable for any number of languages.
  • Easily configurable buttons in the language bar.

Here you are what I did step by step:

Menu organization

I created two root section headers for the two languages needed. Their names are the language codes. All pages in every language are created in the corresponding branch:

  • es (Section Header)
      [li]page1
    • page2
    [/li]
  • eo (Section Header)
      [li]page1
    • page2
    [/li]

To make things easier later, the language section headers have the mark "Show in menu" turned off.

Get the language of the current page

To have only one template for all pages I needed a Smarty variable to keep the current language and use it to select the corresponding parts of the template (the other way would be to use a different template for every language, what is worse to maintain).

My first provisional approach, just to be able to start programming the language bar, was a bit fooly: The user had to choose the language of every page by filling a content block. I put this at the top of the template:

\$1:
{content block="Language code" oneline="true" assign="page_lang"}
{if $page_lang == ""} {assign var="page_lang" value="es"}{/if}


Well, some minutes later  :) the second approach was born and it was a bit -- smarty: As I told, the root parent of every page is a section header whose name is the language code itself. I just needed to get the name of the root parent of the page... But I didn't how to get it! I thought I could learn from the menu module code and program a kind of loop to navigate to the upper parent and so on. I found a possible solution too late in
the message Re: Using the Global variables from CMS. Too late, I said, because I had already thought a simpler solution:
The left char of the template var friendly_position was all I need! The new code at the top of the template was:

\$1:
{if $friendly_position|truncate:1:"":true == "1"}
{assign var='page_lang' value='es'}
{else}
{assign var='page_lang' value='eo'}
{/if}


Of course the if structure is not very elegant. If more languages were needed, it would be better
to use an array with the languages codes, indexed by the menu root positions. Si I decided to write an User Defined Tag called {assign_page_lang}:

\$1:
/*
Assign the Smarty variable page_lang depending on the menu branch the current page belongs to.
*/

global $gCms;

$language_codes = array(
  "1" => "es",
  "2" => "eo")
  ;

$menu_branch = substr($gCms->variables['friendly_position'],0,1);
$smarty = &$gCms->GetSmarty();
$smarty->assign('page_lang', $language_codes[$menu_branch]);


So finally this is the only code needed at the start of the template:

\$1:
{assign_page_lang}


The template

The Smarty var $page_lang can now be used in the template and its blocks to select the content depending on the current language, e.g.:

\$1:
<__html xmlns='http://www.w3.org/1999/xhtml' xml:lang='{$page_lang}'>


Or:

\$1:
{if $page_lang == "es"}
<h1>Título en castellano</h1>
{else}
<h1>Esperanto-titolo</h1>
{/if}
   

Or the main menu itself, to show only the corresponding language branch:

\$1:
<div id='menu'>
{if $page_lang == "es"}{menu template='menu_1' start_element='1' number_of_levels='3'}
{else}{menu template='menu_1' start_element='2' number_of_levels='3'}
{/if}
</div>


Very simple.

The language menu

Now the language menu. I wrote a second UDT called... {language_menu}. In its code you'll see the simple trick to get every page related with its translation. Nevertheless I will explain that later.

The tag has two optional parameters:

  • show_current = Show an inactive link to the current page in the menu? (true/false)
  • show_title = Use the page titles instead of the defined buttons? (true/false)

I needed to execute Smarty tags from a user defined tag (UDT), but happily I found the solution in the CMSMS documentation.

\$1:
/*
Create a language menu.
2008-01-31 Por/Far/By Marcos Cruz (alinome.net)
*/

global $gCms;

/* Parameters
*/
$show_current = $params['show_current']; /* Show an inactive link to the current page in the menu? true/false */
$show_title = $params['show_title']; /* Use the page titles instead of the defined buttons? true/false */

/* Buttons to be used (if $show_title !== true). They could be images too.
I think the text "in language" in the language itself is the most accessible button.
(In my opinion flags are not a good option because they represent countries or regions, not languages).
*/
$language_buttons = array(
  "es" => "<span xml:lang='es'>en castellano</span>",
  "eo" => "<span xml:lang='eo'>en esperanto</span>")
  ;

$current_page = $gCms->variables['page_name'];
/* I explored how to get the page title and found this:
http://forum.cmsmadesimple.org/index.php/topic,1258.msg6831.html#msg6831 (too old)
http://forum.cmsmadesimple.org/index.php/topic,3778.msg93098.html#msg93098
But I haven't explored much yet because I don't use the show_title parameter now...
*/
$page_title = $gCms->variables['page_title']; /* ...so meanwhile this doesn't work :-) Someone can help? */
$page_lang = $gCms->smarty->get_template_vars('page_lang');
$base_page_name = ereg_replace("..$", "", $current_page ); /* take off the language code */


function smarty_cms_selflink($page,$text) {

  /* Call Smarty {cms_selflink}
  Doc found in:
  http://wiki.cmsmadesimple.org/index.php/User_Handbook/Admin_Panel/Extensions/User_Defined_Tags#How_to_Execute_Smarty_Tags_from_A_User_Defined_Tag_.28UDT.29
  */

  global $gCms;

  if ( $text == "" ) { $smarty_data = "{cms_selflink page=" . $page . "}"; }
  else { $smarty_data = '{cms_selflink page=' . $page . ' text="' . $text . '"}'; }

/*
echo "<p><strong>Debug info:</strong></p>";
echo "<p>page=$page</p>";
echo "<p>text=$text</p>";
echo "<p>smarty_data=$smarty_data</p>";
*/

  $smarty = &$gCms->GetSmarty();
  $smarty->_compile_source('temporary template', $smarty_data, $_compiled );
  @ob_start();
  $smarty->_eval('?>' . $_compiled);
  $_contents = @ob_get_contents();
  @ob_end_clean();
  echo $_contents;

}


/* Create the menu
*/

/*
echo "<p><strong>Debug info:</strong><br/>";
echo "page_lang=$page_lang<br/>";
echo "show_title=$show_title<br/>";
echo "show_current=$show_current<br/>";
echo "base_page_name=$base_page_name<br/>";
echo "page_title=$page_title</p>";
*/

echo "<ul>";

foreach ($language_buttons as $language => $button ) {
  if ($language != $page_lang) {
    echo "<li>";
    if ($show_title == true ) { smarty_cms_selflink($base_page_name.$language,""); }
    else { smarty_cms_selflink($base_page_name.$language,$button); }
    echo "</li>";
  }
  elseif ( $show_current == true ) {
    echo "<li class='currentpage'>";
    if ($show_title == true) { echo $page_title; } /* this doesn't work yet */
    else { echo $button; }
    echo "</li>";
  }
}

echo "</ul>";


Yes, it's very simple: just use the same page name (alias) for the language versions but add the language code to it, e.g.:

  • es (Section Header)
      [li]contact_es
    • products_es
    [/li]
  • eo (Section Header)
      [li]contact_eo
    • products_eo
    [/li]

I prefer the format "page.es.html" but the dot cann't be used here. You can use "page-es.html" if you like. The code will change only the last to chars. Of couse you can change the code to name the pages other way (e.g. to put the language code at the start of the name).

You create the language menu in your template like this:

\$1:
<div id='langmenu'>
{language_menu}
</div>


Or with parameters:

\$1:
<div id='langmenu'>
{language_menu show_current=true}
</div>


CSS do the rest.

The code is working fine in a new personal site of mine I'm building these days. I'll post the URL later because the site has no content yet and looks really weird :) .

Future migration to CMSMS 2.0 or whatever

I use Mod Rewrite to get pretty URLs in the format "/contact_es.html" redirected to "/index.php?page=contact_es".

Maybe useful for someone, the lines I use for this in the file .htaccess are:

\$1:
Options +FollowSymLinks
RewriteEngine on

RewriteRule  ^([a-z]+[_]{1}[a-z]{2})\.html$ index.php?page=$1 [NC,L]


(Of course, you have to configure config.php too).

That way, if in the future I migrate to other multilingual system whith a different URL format I will easily create those fake HTML files with PHP code to redirect them (that would be easier for me than messing about Mod Rewrite). E.g. the file products_es.html would be:

\$1:
<?php
header( 'HTTP/1.1 301 Moved Permanently' );
header( 'Status: 301 Moved Permanently' );
header('Location: http://whateveritis.com/futuresystem/es/products/');
exit(0);
?>


Improvements

I'm not very used to PHP (the language I use the most is Forth, what is a extremely different thing!). If you find something that should be corrected or could be improved, please post. I suspect some if structures and conditions could be simpler (when I come back to PHP after a long time, I always forget about && and similar things :) ). The same about the relation beetwen PHP and Smarty, and the inner workings of CMSMS: all that is a new thing for me.

As the code comments explain, the page title option still does not work, but I will ask for help in the corresponding forum board.

Hope all this helps.

Cheers,

Marcos

PS: After implementing my solution I found this interesting message in the forum:
Starting homepage based on users browser language. I think I will add that feature in my site.

_________________
Marcos Cruz


Last edited by alinome.net on Tue Jul 27, 2010 10:35 pm, edited 1 time in total.

Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: One more approach to build a multilingual site with the regular CMSMS
PostPosted: Sat Feb 02, 2008 10:56 am 
Offline
Forum Members
Forum Members
User avatar

Joined: Thu Jan 25, 2007 2:54 pm
Posts: 124
Location: España / Hispanujo / Spain
Karolis \Karolis:
1. It's quite a lot of code;


I don't think so, but I have not compared it with other solutions. Only two UDT are needed: the first has three lines plus the array, and the second has many comments and debug info that make it seem much longer.

Karolis \Karolis:
2. You have to have page titles in other language (so that they are the same). So instead of having About | Apie | O nac, I have to have about-en, about-lt, about-ru. That was single reason I didn't try MLE version.


You are right, it is not a good thing in some cases. It's the simplest solution I found. (I didn't know MLE works this way too). But I think there's an alternative... What about content blocks to keep the name of the other pages?:

\$1:
{content block="Name of the EN version of this page" oneline="true" assign="page_en"}
{content block="Name of the LT version of this page" oneline="true" assign="page_lt"}
{content block="Name of the RU version of this page" oneline="true" assign="page_ru"}


The version in the current language will be left blank (or omitted in the template). The variables can be accessed in the UDT. I am going to explore that.


Thanks, it's nice this code can be useful.

_________________
Marcos Cruz


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: One more approach to build a multilingual site with the regular CMSMS
PostPosted: Sat Feb 02, 2008 11:38 am 
Offline
Forum Members
Forum Members
User avatar

Joined: Thu Jan 25, 2007 2:54 pm
Posts: 124
Location: España / Hispanujo / Spain
Karolis \Karolis:
2. You have to have page titles in other language (so that they are the same). So instead of having About | Apie | O nac, I have to have about-en, about-lt, about-ru. That was single reason I didn't try MLE version.


As promised 30 minutes ago  :) I have explored the question. Here you are a solution:

Add this to your template:

\$1:
{content block="en version" oneline="true" assign="page_en"}
{content block="lt version" oneline="true" assign="page_lt"}
{content block="ru version" oneline="true" assign="page_ru"}


In every page, write the name of the other language versions (the current one is useless).

Then in your template use this modified version of {language_menu}:

\$1:
/*
Create a language menu.
Modified version for different page names in every language.
2008-02-01 Por/Far/By Marcos Cruz (alinome.net)
*/

global $gCms;

/* Parameters
*/
$show_current = $params['show_current']; /* Show an inactive link to the current page in the menu? true/false */
$show_title = $params['show_title']; /* Use the page titles instead of the defined buttons? true/false */

/* Buttons to be used (if $show_title !== true).
*/
$language_buttons = array(
  "en" => "<span xml:lang='en'>in english</span>",
  "lt" => "<span xml:lang='lt'>"LT"</span>",
  "ru" => "<span xml:lang='ru'>"RU"</span>")
  ;

$page_title = $gCms->variables['page_title']; /* this doesn't work. Someone can help? */
$page_lang = $gCms->smarty->get_template_vars('page_lang');

function smarty_cms_selflink($page,$text) {

  /* Call Smarty {cms_selflink} */

  global $gCms;

  if ( $text == "" ) { $smarty_data = "{cms_selflink page=" . $page . "}"; }
  else { $smarty_data = '{cms_selflink page=' . $page . ' text="' . $text . '"}'; }

  $smarty = &$gCms->GetSmarty();
  $smarty->_compile_source('temporary template', $smarty_data, $_compiled );
  @ob_start();
  $smarty->_eval('?>' . $_compiled);
  $_contents = @ob_get_contents();
  @ob_end_clean();
  echo $_contents;

}


/* Create the menu
*/

echo "<ul>";

foreach ($language_buttons as $language => $button ) {

  if ($language != $page_lang) {
    echo "<li>";
    $alternative_page = $gCms->smarty->get_template_vars('page_'.$language);
    if ($show_title == true ) { smarty_cms_selflink($alternative_page,""); }
    else { smarty_cms_selflink($alternative_page,$button); }
    echo "</li>";
  }
  elseif ( $show_current == true ) {
    echo "<li class='currentpage'>";
    if ($show_title == true) { echo $page_title; }
    else { echo $button; }
    echo "</li>";
  }
}

echo "</ul>";


I have tested it and it works fine. I think I will use it in my site, instead of the first version. Page names in the page language look much better.

Thanks a lot for the instigation!  :)

_________________
Marcos Cruz


Last edited by alinome.net on Sat Feb 02, 2008 12:24 pm, edited 1 time in total.

Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: One more approach to build a multilingual site with the regular CMSMS
PostPosted: Sat Feb 02, 2008 1:00 pm 
Offline
Forum Members
Forum Members
User avatar

Joined: Thu Jan 25, 2007 2:54 pm
Posts: 124
Location: España / Hispanujo / Spain
Two little things:

This simple modification in {language_menu} (second version) is useful to avoid problems when an alternative page has not been specified yet:

\$1:
foreach ($language_buttons as $language => $button ) {

if ($language != $page_lang) {
    $alternative_page = $gCms->smarty->get_template_vars('page_'.$language);
    if ($alternative_page != "") { /* NEW */
      echo "<li>";
      if ($show_title == true ) { smarty_cms_selflink($alternative_page,""); }
      else { smarty_cms_selflink($alternative_page,$button); }
      echo "</li>";
    }
  }


And one more idea: Instead of one content block for every language (one of them always useless) , we could use only one content block for all alternative languages. The UDT would transform its content into an array with the PHP function explode() or something like that.

\$1:
{content block="Alternative pages" assign="alternative_pages"}


Its content would be something like "lt page_name_in_lt;ru page_name_in_ru;en page_name_in_en". Right now I'm not sure about the most convenient "sintax" for that string to get an indexed array from it, but I will explore the question...

_________________
Marcos Cruz


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: One more approach to build a multilingual site with the regular CMSMS
PostPosted: Sat Feb 02, 2008 3:40 pm 
Offline
Support Guru
Support Guru

Joined: Mon Jul 24, 2006 3:27 pm
Posts: 3679
Location: Paris
Hello,

this is interesting. I'd rather test CMSms v2 (pre-alpha in SVN) but your way of doing things (vanillia CMSms) seems sane :-)

I'm not a coder, I've not tested, but may I suggest something :
You have
\$1:
$language_codes = array(
  "1" => "es",
  "2" => "eo")

and
\$1:
<div id='menu'>
{if $page_lang == "es"}{menu template='menu_1' start_element='1' number_of_levels='3'}
{else}{menu template='menu_1' start_element='2' number_of_levels='3'}
{/if}
</div>

May be instead of if/elsif the array could be used to assign the start_element ?

Pierre M.

_________________
-- Pierre, former support team member.
Please read "how to submit installation/support requests" before posting. Don't send private messages to ask for support.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: One more approach to build a multilingual site with the regular CMSMS
PostPosted: Sat Feb 02, 2008 3:45 pm 
Offline
Forum Members
Forum Members
User avatar

Joined: Thu Jan 25, 2007 2:54 pm
Posts: 124
Location: España / Hispanujo / Spain
Karolis \Karolis:
2. You have to have page titles in other language (so that they are the same). So instead of having About | Apie | O nac, I have to have about-en, about-lt, about-ru. That was single reason I didn't try MLE version.


This second solution I propose is more user friendly (though maybe slower): only one content block to specify all alternative pages.

Put this in your template:

\$1:
{content block="Other languages" oneline="true" assign="other_languages"}


In every english page, fill that content block like this:

lt=page-name-in-lt;ru=page-name-in-ru

In every russian page, fill that content block like this:

lt=page-name-in-lt;en=page-name-in-en

An so on for every language.

The order and number of the languages doesn't matter. Maybe some pages don't have all translations avalaible. Or one single page has more translations than the rest. That's no problem if the arrays in both UDT have all the language information needed. No spaces in the string, though, just to make things easier and faster in the code. The language codes must be two letters long (the UTD should be modified to use three letters).

Then use this (third) version of {language_menu}:

\$1:
/*
Create a language menu.

Third version:
Different page names in every language,
all specified in one content block.

2008-02-01 Por/Far/By Marcos Cruz (alinome.net)
*/

global $gCms;

/* Parameters
*/
$show_current = $params['show_current']; /* Show an inactive link to the current page in the menu? true/false */
$show_title = $params['show_title']; /* Use the page titles instead of the defined buttons? true/false */

/* Buttons to be used (if $show_title !== true).
*/

$language_buttons = array(
  "en" => "<span xml:lang='en'>in english</span>",
  "lt" => "<span xml:lang='lt'>"LT"</span>",
  "ru" => "<span xml:lang='ru'>"RU"</span>");

$page_title = $gCms->variables['page_title']; /* this doesn't work. Someone can help? */
$page_lang = $gCms->smarty->get_template_vars('page_lang');
$other_languages = $gCms->smarty->get_template_vars('other_languages'); /* format: "c1=page1;c2=page2;c3=page3" where c(n) are language codes (two letters), any number of languages can be specified */

$other_languages_tmp=explode(';', $other_languages);

foreach ($other_languages_tmp as $other_language ) {
  $language_codes[]=substr($other_language,0,2);
  $language_pages[]=substr($other_language,3);
}

$language_versions = array_combine($language_codes,$language_pages);

function smarty_cms_selflink($page,$text) {

  /* Call Smarty {cms_selflink}
  Doc found in:
  http://wiki.cmsmadesimple.org/index.php/User_Handbook/Admin_Panel/Extensions/User_Defined_Tags#How_to_Execute_Smarty_Tags_from_A_User_Defined_Tag_.28UDT.29
  */

  global $gCms;

  if ( $text == "" ) { $smarty_data = "{cms_selflink page=" . $page . "}"; }
  else { $smarty_data = '{cms_selflink page=' . $page . ' text="' . $text . '"}'; }

  $smarty = &$gCms->GetSmarty();
  $smarty->_compile_source('temporary template', $smarty_data, $_compiled );
  @ob_start();
  $smarty->_eval('?>' . $_compiled);
  $_contents = @ob_get_contents();
  @ob_end_clean();
  echo $_contents;

}


/* Create the menu
*/

echo "<ul>";

foreach ($language_buttons as $language => $button ) {

  if ($language != $page_lang) {
    $alternative_page = $language_versions[$language];
    if ($alternative_page != "") {
      echo "<li>";
      if ($show_title == true ) { smarty_cms_selflink($alternative_page,""); }
      else { smarty_cms_selflink($alternative_page,$button); }
      echo "</li>";
    }
  }
  elseif ( $show_current == true ) {
    echo "<li class='currentpage'>";
    if ($show_title == true) { echo $page_title; }
    else { echo $button; }
    echo "</li>";
  }
}

echo "</ul>";



I think this is a good solution too.

_________________
Marcos Cruz


Last edited by alinome.net on Tue Feb 05, 2008 10:27 am, edited 1 time in total.

Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: One more approach to build a multilingual site with the regular CMSMS
PostPosted: Sat Feb 02, 2008 3:58 pm 
Offline
Forum Members
Forum Members
User avatar

Joined: Thu Jan 25, 2007 2:54 pm
Posts: 124
Location: España / Hispanujo / Spain
Pierre M. \Pierre M.:
\$1:
<div id='menu'>
{if $page_lang == "es"}{menu template='menu_1' start_element='1' number_of_levels='3'}
{else}{menu template='menu_1' start_element='2' number_of_levels='3'}
{/if}
</div>

May be instead of if/elsif the array could be used to assign the start_element ?


Right, I had the same idea, but I did'nt know how to use, in Smarty, arrays defined in UDT, or vice versa, and I haven't explored the question yet. As I told, I'm not very used to PHP and I don't know Smarty enough. I think it is possible to do what you suggest. That would simplify the template when there are several languages.

Also, I would like to use one single array for all language information (now one is needed in {assign_page_lang} and another in {language_menu}, but it's not very important.

Thanks!

_________________
Marcos Cruz


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: One more approach to build a multilingual site with the regular CMSMS
PostPosted: Sat Feb 02, 2008 4:03 pm 
Offline
Support Guru
Support Guru

Joined: Mon Jul 24, 2006 3:27 pm
Posts: 3679
Location: Paris
Hello again Marcos,

Single array, simplified template... tasty :-)
I hope a Smarty Guru or the Smarty doc will answer.

Have fun with CMSms

Pierre M.

_________________
-- Pierre, former support team member.
Please read "how to submit installation/support requests" before posting. Don't send private messages to ask for support.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: One more approach to build a multilingual site with the regular CMSMS
PostPosted: Sat Feb 02, 2008 6:07 pm 
Offline
Support Guru
Support Guru
User avatar

Joined: Mon Jul 04, 2005 5:12 pm
Posts: 4809
Location: Ferrara, Italy
alinome.net \alinome.net:
Pierre M. \Pierre M.:
\$1:
<div id='menu'>
{if $page_lang == "es"}{menu template='menu_1' start_element='1' number_of_levels='3'}
{else}{menu template='menu_1' start_element='2' number_of_levels='3'}
{/if}
</div>

May be instead of if/elsif the array could be used to assign the start_element ?


Right, I had the same idea, but I did'nt know how to use, in Smarty, arrays defined in UDT, or vice versa, and I haven't explored the question yet. As I told, I'm not very used to PHP and I don't know Smarty enough. I think it is possible to do what you suggest. That would simplify the template when there are several languages.



\$1:
$language_codes = array(
  "1" => "es",
  "2" => "eo",
);

global $gCms;
$smarty = &$gCms->GetSmarty();
$smarty->assign_by_ref('language_codes', $language_codes);



\$1:
<div id='menu'>
{foreach from=$language_codes key=key_code item=code}
 {if $page_lang == $code}{menu template='menu_1' start_element='{$key_code}' number_of_levels='3'}
{/foreach}
</div>




Karolis \Karolis:
2. You have to have page titles in other language (so that they are the same). So instead of having About | Apie | O nac, I have to have about-en, about-lt, about-ru. That was single reason I didn't try MLE version.


For info only:
In MLE: title, menu_text and content (and in extended: metadata and description) are separated for each language in a similar way to version 2.0

Alby

_________________
Former Italian Admin and Moderator
Multilingual: MLE is not CMSMS


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: One more approach to build a multilingual site with the regular CMSMS
PostPosted: Sat Feb 02, 2008 7:06 pm 
Offline
Forum Members
Forum Members
User avatar

Joined: Thu Jan 25, 2007 2:54 pm
Posts: 124
Location: España / Hispanujo / Spain
Thank you Alby for the improvement and for the - Smarty teaching.

alby \alby:
In MLE: title, menu_text and content (and in extended: metadata and description) are separated for each language in a similar way to version 2.0


I'll try MLE too.

_________________
Marcos Cruz


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: One more approach to build a multilingual site with the regular CMSMS
PostPosted: Sat Feb 02, 2008 7:22 pm 
Offline
Forum Members
Forum Members
User avatar

Joined: Thu Jan 25, 2007 2:54 pm
Posts: 124
Location: España / Hispanujo / Spain
Pierre M. \Pierre M.:
Single array, simplified template... tasty :-)


I've just found what I needed to do without the array in {assign_page_lang}: Get a page's root parent's alias.

With that code I can do what I thought in the beginning: to get the language id of any page from its root parent name. The new version of {assign_page_lang} is:

\$1:
/*
Assign the Smarty variable page_lang depending on the menu branch the current page belongs to.
*/

/* 2008-02-02 Second version, without array
Code found here:
http://wiki.cmsmadesimple.org/index.php/Share_your_tags_here#Get_a_page.27s_root_parent.27s_alias
*/

global $gCms;
global $smarty;

$manager =& $gCms->GetHierarchyManager();

$result = "??";
$thisPage = $gCms->variables['content_id'];
$currentNode = &$manager->sureGetNodeById($thisPage);
while( isset($currentNode) && $currentNode->getLevel() >= 0 )
{
    $currentContent =& $currentNode->getContent();
    $result = $currentContent->Alias();
    $currentNode =& $currentNode->getParentNode();
}
$smarty->assign('page_lang',$result);


Now the name of the root parents must be the language code (with the prior method that was not mandatory).

_________________
Marcos Cruz


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: One more approach to build a multilingual site with the regular CMSMS
PostPosted: Sun Feb 03, 2008 9:50 am 
Offline
Forum Members
Forum Members
User avatar

Joined: Thu Jan 25, 2007 2:54 pm
Posts: 124
Location: España / Hispanujo / Spain
Karolis \Karolis:
could you possibly post A to Z instructions once again? I think many non-programmer people can find it a little difficult to navigate through all the corrections and so on.


You're right, I will post the result and will explain how to implement it step by step for non-programmers (as I did in the first post of the thread). I think the last version with no array in {assign_page_lang} and only one content block to specify all alternative languages is the most practical for both the programmer and the content editor. What do you think?

Maybe I wait a little untill you and maybe others test it a bit. It's working fine in my site; the code is simple so I think there should be no bug left.

Thanks

Marcos

_________________
Marcos Cruz


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: One more approach to build a multilingual site with the regular CMSMS
PostPosted: Tue Feb 05, 2008 10:34 am 
Offline
Forum Members
Forum Members
User avatar

Joined: Thu Jan 25, 2007 2:54 pm
Posts: 124
Location: España / Hispanujo / Spain
Karolis \Karolis:
When I try to save language_menu (third version) UDT, I get the following error:

    * Invalid code entered.
    * Parse error: syntax error, unexpected T_STRING, expecting ')' in C:\Program Files\WAMP\www\cmsms\access\adduserplugin.php(94) : eval()'d code on line 23

It should be

\$1:
$language_buttons = array(
  "en" => "<span xml:lang='en'>EN</span>",
  "lt" => "<span xml:lang='lt'>LT</span>",
  "ru" => "<span xml:lang='ru'>RU</span>");



Thanks. That's a typo of mine: I added that languages on the fly, as an example for you. I have corrected the mistake in the the original message.

_________________
Marcos Cruz


Last edited by alinome.net on Tue Feb 05, 2008 10:38 am, edited 1 time in total.

Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: One more approach to build a multilingual site with the regular CMSMS
PostPosted: Tue Feb 05, 2008 10:48 am 
Offline
Forum Members
Forum Members
User avatar

Joined: Thu Jan 25, 2007 2:54 pm
Posts: 124
Location: España / Hispanujo / Spain
Karolis \Karolis:
One request through: if the page is not entered for the other language, or it is entered incorrectly, could the link still be shown that would lead to the first page (1.1, 2.1, 3.1) of the other language?


That's a good idea! You never can trust content editors...  :D I'll try to implement that.

Karolis \Karolis:
sometimes I need to show all available languages. It is currently impossible to do so, because the current language is hidden. Can you make a parameter to show inactive link of current language? Maybe that's what "show_current" is supposed to do, but it does not seem to work for me.


Right, "show_current" should show an inactive link to the current page. It worked fine for me. I'll explore the question.

Till a bit later

_________________
Marcos Cruz


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: One more approach to build a multilingual site with the regular CMSMS
PostPosted: Tue Feb 05, 2008 11:11 am 
Offline
Forum Members
Forum Members
User avatar

Joined: Thu Jan 25, 2007 2:54 pm
Posts: 124
Location: España / Hispanujo / Spain
Karolis \Karolis:
Maybe that's what "show_current" is supposed to do, but it does not seem to work for me.


Tested: It works fine for me. Maybe you made some inadvertent change?

The tag call works this way:

\$1:
{language_menu show_current=true}


Or this:

\$1:
{language_menu show_current="true"}


Verify this line in the code of {language_menu}:

\$1:
$show_current = $params['show_current'];


And these too:

\$1:
  elseif ( $show_current == true ) {
    echo "<li class='currentpage'>";
    if ($show_title == true) { echo $page_title; }
    else { echo $button; }
    echo "</li>";
  }


Is it all right?

_________________
Marcos Cruz


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 131 posts ]  Go to page 1, 2, 3, 4, 5 ... 9  Next

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
A2 Hosting