One more approach to build a multilingual site with the regular CMSMS

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
ZIGRIB
Forum Members
Forum Members
Posts: 20
Joined: Wed Apr 23, 2008 3:31 pm

Re: One more approach to build a multilingual site with the regular CMSMS

Post by ZIGRIB »

In the tag {language_menu} :

$languages = array(
  'en' => array('home', 'English'),
  'fr' => array('accueil', 'Français') );

For the moment I just have 3 pages in french & 3 in english

In french :
Accueil alias accueil          Other Languages: en=home
Et encore alias encore        Other Languages: en=else
Une journée au parc alias une-journee-au-parc  Other Languages: en=a-day-in-the-park

In english:
Home alias home              Other Languages: fr=accueil
else alias else                  Other Languages: fr=encore
A day in the park alias a-day-in-the-park  Other Languages: fr=une-journee-au-parc
Last edited by ZIGRIB on Wed May 21, 2008 3:03 pm, edited 1 time in total.
User avatar
alinome.net
Forum Members
Forum Members
Posts: 124
Joined: Thu Jan 25, 2007 2:54 pm
Location: España / Hispanujo / Spain

Re: One more approach to build a multilingual site with the regular CMSMS

Post by alinome.net »

Everything looks right.

Let's try another thing: Are the languages links right? Do they really point to the right page alias in the other language or to the home page? I mean, when you move the mouse over a language link, what goal URL is shown on the status bar of your browser? As an alternative, you can take a look into the XHTML source: What href URL is inside the tag?
Marcos Cruz
ZIGRIB
Forum Members
Forum Members
Posts: 20
Joined: Wed Apr 23, 2008 3:31 pm

Re: One more approach to build a multilingual site with the regular CMSMS

Post by ZIGRIB »

when I move the mouse over a language link it's always the same gaol :

when i'm oven english link :
http://localhost/site/index.php?page=home

when i'm over french link :
http://localhost/site

As an alternative, you can take a look into the XHTML source: What href URL is inside the tag
How can i do it ?
If I see the source code of the page "Et encore" with firefox :


English

It's that what you mean ?
User avatar
alinome.net
Forum Members
Forum Members
Posts: 124
Joined: Thu Jan 25, 2007 2:54 pm
Location: España / Hispanujo / Spain

Re: One more approach to build a multilingual site with the regular CMSMS

Post by alinome.net »

ZIGRIB wrote: when i'm oven english link :
http://localhost/site/index.php?page=home
when i'm over french link :
http://localhost/site
That means the links are build wrong in the tag {language_menu}, as if you didn't filled the "Other languages" field. I cannot guess what's wrong. I am going to take a look at the code now to get it back fresh in my mind. Wait a little.
Marcos Cruz
User avatar
alinome.net
Forum Members
Forum Members
Posts: 124
Joined: Thu Jan 25, 2007 2:54 pm
Location: España / Hispanujo / Spain

Re: One more approach to build a multilingual site with the regular CMSMS

Post by alinome.net »

Hello again ZIGRIB,

1) What parameters are you using in the {language_menu} tag?:

Code: Select all

// ----------------------------------------------------------------
// Parameters

// Show the page title in the links? (true/false)
// (if false, show the defined buttons)
$show_title = isset($params['show_title']) ? $params['show_title'] : false;

// Show an inactive link to the current page in the menu? (true/false)
// (if false, don't create a menu entry for the current page)
$show_current = isset($params['show_current']) ? $params['show_current'] : false; 

// If there's no valid translation, then show a link to the default page? (true/false)
// (if false, don't create a menu entry for that language)
$show_default = isset($params['show_default']) ? $params['show_default'] : true;

// If  $show_default==false or there's no valid default page, then show an inactive link? (true/false)
// (if false, don't create a menu entry for that language)
$show_inactive = isset($params['show_inactive']) ? $params['show_inactive'] : true; 
2) Please activate all the debug lines in the foreach loop inside the {language_menu} tag. I mean, delete the initial "//" of the lines that have "// DEBUG" at the end. Then refresh your pages and tell me what warnings you see in the language menu.
Marcos Cruz
ZIGRIB
Forum Members
Forum Members
Posts: 20
Joined: Wed Apr 23, 2008 3:31 pm

Re: One more approach to build a multilingual site with the regular CMSMS

Post by ZIGRIB »

1) What parameters are you using in the {language_menu} tag?

I don't modify anything in parameters :

// ----------------------------------------------------------------
// Parameters

// Show the page title in the links? (true/false)
// (if false, show the defined buttons)
$show_title = isset($params['show_title']) ? $params['show_title'] : false;

// Show an inactive link to the current page in the menu? (true/false)
// (if false, don't create a menu entry for the current page)
$show_current = isset($params['show_current']) ? $params['show_current'] : false;

// If there's no valid translation, then show a link to the default page? (true/false)
// (if false, don't create a menu entry for that language)
$show_default = isset($params['show_default']) ? $params['show_default'] : true;

// If  $show_default==false or there's no valid default page, then show an inactive link? (true/false)
// (if false, don't create a menu entry for that language)
$show_inactive = isset($params['show_inactive']) ? $params['show_inactive'] : true;



2) Please activate all the debug lines in the foreach loop inside the {language_menu} tag. I mean, delete the initial "//" of the lines that have "// DEBUG" at the end. Then refresh your pages and tell me what warnings you see in the language menu.

Results :
# alternative_page=NO ALTERNATIVE! DEFAULT: English when i'm in french page
# alternative_page=NO ALTERNATIVE! DEFAULT: Français when i'm in english page
User avatar
alinome.net
Forum Members
Forum Members
Posts: 124
Joined: Thu Jan 25, 2007 2:54 pm
Location: España / Hispanujo / Spain

Re: One more approach to build a multilingual site with the regular CMSMS

Post by alinome.net »

ZIGRIB wrote: I don't modify anything in parameters :
So that means in your template you put just {language_menu}, literally. So the defaults values are used for the parameters:

Code: Select all

$show_title = false;
$show_current = false; 
$show_default = true;
$show_inactive = true;
ZIGRIB wrote: Results :
# alternative_page=NO ALTERNATIVE! DEFAULT: English when i'm in french page
# alternative_page=NO ALTERNATIVE! DEFAULT: Français when i'm in english page
That happens here:

Code: Select all

if ( $show_default == true and valid_page($language[DEFAULT_PAGE]) )
      {
        echo '<li>';
        // echo 'NO ALTERNATIVE! DEFAULT: '; // DEBUG
        smarty_cms_selflink($language[DEFAULT_PAGE],( ($show_title == true ) ? "" : $language[BUTTON] ) , "hreflang='".$language_code."'");
        echo '</li>';
      }
$show_default is true, we have seen. That means valid_page($language[DEFAULT_PAGE]) outputs false:

Code: Select all

function valid_page($page_alias)
{

  // Is a page alias valid?

  // References:
  // http://forum.cmsmadesimple.org/index.php/topic,3778.msg20921.html#msg20921

  global $gCms;

  $manager =& $gCms->GetHierarchyManager();
  $node =& $manager->getNodeByAlias($page_alias);
  return ( $node != null );

}
It's very strange. Are you sure you didn't mistype the alias of the pages in the Other languages content block? Please add the three "echo" commands to the function, like this:

Code: Select all

function valid_page($page_alias)
{

  // Is a page alias valid?

  // References:
  // http://forum.cmsmadesimple.org/index.php/topic,3778.msg20921.html#msg20921

  global $gCms;

echo '<p><strong>DEBUG</strong>:';
echo "<br/>page_alias=$page_alias";
echo '</p>';

  $manager =& $gCms->GetHierarchyManager();
  $node =& $manager->getNodeByAlias($page_alias);
  return ( $node != null );

}
Are the alias shown the good ones? Are they the same than the alias defined in the pages?

Also, uncomment the debug line here:

Code: Select all

if ( $language_code != $page_lang )
  {
    $alternative_page = $language_versions[$language_code];
   echo "alternative_page=$alternative_page"; // DEBUG
What alternative page is shown?
Marcos Cruz
ZIGRIB
Forum Members
Forum Members
Posts: 20
Joined: Wed Apr 23, 2008 3:31 pm

Re: One more approach to build a multilingual site with the regular CMSMS

Post by ZIGRIB »

hello Marcos

1 - Are the alias shown the good ones? Are they the same than the alias defined in the pages?

After i have put the 3 echo in fonction valid page :

when i'm in french page:
DEBUG:
page_alias=

DEBUG:
page_alias=home

when i'm in english page :
DEBUG:
page_alias=

DEBUG:
page_alias=accueil




Also, uncomment the debug line here:
Code:
if ( $language_code != $page_lang )
  {
    $alternative_page = $language_versions[$language_code];
  echo "alternative_page=$alternative_page"; // DEBUG
What alternative page is shown?

result :
alternative_page=

it is really strange...
Perhaps i made a mistake when i followed the instructions...
I have create two pages :
the first is  name : français    type : Section Header  alias: fr
the second is name : anglais  type : Section Header  alias : en

then I created all french pages with as français page and English with as anglais page.
I mean i have :
1 - français            type : section header
1.1 - accueil          type : content
1.2 - ...                type : content

2 - Anglais            type : section header
2.1 - home            type content
2.2 - ...                type content

I have create two tags assign_page_lang & language_menu by copy and paste the code of the instructions

I put in each templates :

- on the top : {assign_page_lang}
- just after body tag : {language_menu}
- in the content : {content block='Other languages' oneline='true' assign=other_languages wysiwyg='false'}

I have prove that alias entered in other language are the same definitely in the concerned pages
for example for the homepage I put this:
on the page accueil (alias accueil)---> en=home
on the page home (alias home)---> fr=accueil


Is it correct ?
Last edited by ZIGRIB on Thu May 22, 2008 1:50 pm, edited 1 time in total.
User avatar
alinome.net
Forum Members
Forum Members
Posts: 124
Joined: Thu Jan 25, 2007 2:54 pm
Location: España / Hispanujo / Spain

Re: One more approach to build a multilingual site with the regular CMSMS

Post by alinome.net »

ZIGRIB wrote:

Code: Select all

if ( $language_code != $page_lang )
  {
    $alternative_page = $language_versions[$language_code];
   echo "alternative_page=$alternative_page"; // DEBUG
What alternative page is shown?
result :
alternative_page=
The problem is that the array $language_versions is empty! Are you using PHP 4? The function array_combine() is a PHP-5-only function. If you use PHP 4 you must add some code to ensure PHP 4 compatibility.

To see the version of your PHP, create a file called phpinfo.php with this content:

Code: Select all

<?php phpinfo(); ?> 
Upload it into your web serber space and visit it with your browser. What PHP version is it?
Last edited by alinome.net on Thu May 22, 2008 5:40 pm, edited 1 time in total.
Marcos Cruz
ZIGRIB
Forum Members
Forum Members
Posts: 20
Joined: Wed Apr 23, 2008 3:31 pm

Re: One more approach to build a multilingual site with the regular CMSMS

Post by ZIGRIB »

On localhost i have php5 and
i try the fonctionnality online with php4 + code compatibility php4
the result is the same...
User avatar
alinome.net
Forum Members
Forum Members
Posts: 124
Joined: Thu Jan 25, 2007 2:54 pm
Location: España / Hispanujo / Spain

Re: One more approach to build a multilingual site with the regular CMSMS

Post by alinome.net »

ZIGRIB wrote: On localhost i have php5 and
This is a "poltergeist"  :)

Let's see what happens about the language arrays. Uncomment these debug lines and copy and paste me the result:

Code: Select all

/*
echo '<p><strong>DEBUG</strong>:';
echo "<br/>language_codes="; print_r($language_codes);
echo "<br/>language_pages="; print_r($language_pages);
echo "<br/>language_versions="; print_r($language_versions);
echo '</p>';
*/
Marcos Cruz
ZIGRIB
Forum Members
Forum Members
Posts: 20
Joined: Wed Apr 23, 2008 3:31 pm

Re: One more approach to build a multilingual site with the regular CMSMS

Post by ZIGRIB »

Result  under php4:
DEBUG:
language_codes=Array ( [0] => )
language_pages=Array ( [0] => )
language_versions=Array ( [0] => )

result under php5
DEBUG:
language_codes=Array ( [0] => )
language_pages=Array ( [0] => )
language_versions=Array ( [] => )
Last edited by ZIGRIB on Thu May 22, 2008 6:56 pm, edited 1 time in total.
User avatar
alinome.net
Forum Members
Forum Members
Posts: 124
Joined: Thu Jan 25, 2007 2:54 pm
Location: España / Hispanujo / Spain

Re: One more approach to build a multilingual site with the regular CMSMS

Post by alinome.net »

It seems the problem is here:

Code: Select all

$other_languages = $gCms->smarty->get_template_vars('other_languages');
foreach ( explode(';', $other_languages) as $other_language )
{
  $language_codes[]=substr($other_language, 0, 2);
  $language_pages[]=substr($other_language, 3);
}
Add the two "echo" lines:

Code: Select all

$other_languages = $gCms->smarty->get_template_vars('other_languages');
echo "<p>other_languages=$other_languages</p>";
foreach ( explode(';', $other_languages) as $other_language )
{
  echo "<p>other_language=$other_language</p>";
  $language_codes[]=substr($other_language, 0, 2);
  $language_pages[]=substr($other_language, 3);
}
What is the result?
Marcos Cruz
ZIGRIB
Forum Members
Forum Members
Posts: 20
Joined: Wed Apr 23, 2008 3:31 pm

Re: One more approach to build a multilingual site with the regular CMSMS

Post by ZIGRIB »

result :

other_languages=

other_language=

DEBUG:
language_codes=Array ( [0] => )
language_pages=Array ( [0] => )
language_versions=Array ( [] => )
User avatar
alinome.net
Forum Members
Forum Members
Posts: 124
Joined: Thu Jan 25, 2007 2:54 pm
Location: España / Hispanujo / Spain

Re: One more approach to build a multilingual site with the regular CMSMS

Post by alinome.net »

ZIGRIB wrote: other_languages=
That means the "Other languages" content block is empty, or the variable it's assigned to cannot be fetched. I have this in my site template:

Code: Select all

{content block='Other languages' oneline='true' assign='other_languages' wysiwyg='false'}
If the words "block" or "assign" or their values were mistyped, that would explain the problem. You said:
ZIGRIB wrote: - in the content : {content block='Other languages' oneline='true' assign=other_languages wysiwyg='false'}
The difference is the quotes around 'other_languages', but they are not needed (I forgot them in the published code). Are you putting that content block in the template that is associated with your pages?
Marcos Cruz
Post Reply

Return to “Tips and Tricks”