Jump to content

Multilanguage: only default language displays


lenoir
 Share

Recommended Posts

Hi everyone!

Can't figure out a problem with my first multi-language website.

I've installed the language modules, created two languages (german (default) and french). I've set up /de/ and /fr/ as paths on the home page.

Of course i filled some content in both languages, but when i switch to french, the path (URL) is correct, but it always displays the default language. 

Can anyone help me? 

Thanks!

Link to comment
Share on other sites

Hi, did you "Activated" the language for each page?

If not:

- Locate the page in the main admin tree.

- Click to "Edit" the page

- Go to "Settings" tab 

- And check the "Active?" checkbox in the right side of the specific language path.

Also remember to set the  $user->language variables (If you are using a link as language switcher).

Link to comment
Share on other sites

Do you set $user->language somewhere in your code? Maybe we could help more seeing your template code.

Hi tpr,

Thanks for this. I can now set the language via $user->language = "fr"; (for instance). But how do I get it automatically?

I'm using this bit of code to switch the language:

foreach($languages as $language) {
if(!$page->viewable($language)) continue; // is page viewable in this language?

$url = $page->localUrl($language); 
$hreflang = $homepage->getLanguageValue($language, 'name'); 
echo "<a style='opacity:0.1' hreflang='$hreflang' href='$url'>$language->title</a></li>";
}

What am i missing? 

Link to comment
Share on other sites

You shouldn't set it manually unless you need a content from a non-current language. I asked if you do set is because if you did your site could show content from other languages.

The language switcher seems OK if it changes the URL. How do you try to echo the content? (where it fails to show the correct language)

  • Like 1
Link to comment
Share on other sites

I find the problem. I had this bit of code in the head that was causing the problem. I deleted it and now it's working. 

    switch ($language){
        case "fr":
            $user->language = $languages->get("fr");
            break;
        default:
            $user->language = $languages->get("default");
            break;
    }

I don't know why i had it there… 

Anyways, thanks for your help!!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...