ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Switch lang for guest

January 24, 2011 6:27am

Subscribe [4]
  • #1 / Jan 24, 2011 6:27am

    Silentium

    19 posts

    Hi.

    I have a problem about changing the language in the front-end for guest on the site.

    In my index.php file I have the following code that I thought would to the trick, but no :(

    $uri_parts = explode('/', $_SERVER['REQUEST_URI']);
         if(empty($uri_parts[1])) {
             $uri_lang = 'en';
             $lang = 'english';
         } else {
             $uri_lang = $uri_parts[1];
             switch($uri_lang) {
                 case en: $lang = 'english'; break;
                 case it: $lang = 'italian'; break;
                 case es: $lang = 'spanish'; break;
                 case de: $lang = 'german'; break;
                 case da: $lang = 'danish'; break;
                 case nl: $lang = 'dutch'; break;
                 case fi: $lang = 'finnish'; break;
                 case el: $lang = 'greek'; break;
                 case nb: $lang = 'norwegian'; break;
                 case pt: $lang = 'portuguese'; break;
                 case ru: $lang = 'russian'; break;
                 case sv: $lang = 'swedish'; break;
                 case chs: $lang = 'chinese (Simplified)'; break;
                 case cht: $lang = 'Chinese (Traditional)'; break;
             }
         }
         
        $assign_to_config['template_group'] = '';
        $assign_to_config['template'] = '';
        $assign_to_config['site_index'] = '';
        $assign_to_config['site_404'] = '';
        $assign_to_config['global_vars'] = array(
            "country_code" => $uri_lang,
            "language" => $lang,
            "user_language" => $lang
        ); // This array must be associative

    I have tested in a browser that where complete cleared from cookies and browser history. When going to a URL like mydomain.com/sv/ the part of the site that is translated to Swedish should change to Swedish, but the don’t. They are still in English.

    the country_code, language and user_language returns right value so no problem there.

    Anyone have a suggestion whats might be wrong or have a solution on this?

    If I’m logged in and set my language to Swedish in my profile, it works as it should.

    / Mattias

  • #2 / Jan 24, 2011 10:17am

    Sue Crocker

    26054 posts

    Hi, Mattias.

    In the templates you’re using, how are you checking for the language?

  • #3 / Jan 24, 2011 10:37am

    Silentium

    19 posts

    I use the “country_code” to get the right entries depending on there status and that works fine.

    What don’t work is the system output like logging in and out, register form and so on. The more “static” content from EE and the content that I have in the third-party plugin “Multi Language” don’t get translated.

    Do I have to do a specific checking for the system output as well?

  • #4 / Jan 24, 2011 5:13pm

    Ingmar

    29245 posts

    Do you have the required language packs all installed?

  • #5 / Jan 25, 2011 4:46am

    Silentium

    19 posts

    I have default English and Swedish installed for the moment and it is with those two I have tested.

    When selecting Swedish in my profile, while logged in, it’s translate the system output to Swedish.

    But logged out (in another browser clean from cookies and browsing history) and switch to Swedish as guest visitor on the site, the system output stays in English.

  • #6 / Jan 25, 2011 5:51pm

    Barry Cogan

    291 posts

    Hi Mattias,

    Could you provide the two addresses you are using as examples.  For example: two full addresses which access the same page for the separate languages (logged in and out)?

    switch($uri_lang) {
                 case 'en': $lang = 'english'; break;
                 case 'it': $lang = 'italian'; break;
                 case 'es': $lang = 'spanish'; break;
                 case 'de': $lang = 'german'; break;
                 case 'da': $lang = 'danish'; break;
                 case 'nl': $lang = 'dutch'; break;
                 case 'fi': $lang = 'finnish'; break;
                 case 'el': $lang = 'greek'; break;
                 case 'nb': $lang = 'norwegian'; break;
                 case 'pt': $lang = 'portuguese'; break;
                 case 'ru': $lang = 'russian'; break;
                 case 'sv': $lang = 'swedish'; break;
                 case 'chs': $lang = 'chinese (Simplified)'; break;
                 case 'cht': $lang = 'Chinese (Traditional)'; break;
             }

    On your case statements you should have the strings you are comparing within quotes (as above).  Just something I noticed.

    Regards,
    Barry

  • #7 / Jan 26, 2011 4:23am

    Silentium

    19 posts

    Hi

    The case statements works good even without the quotes, but yes, you are right, I should have quotes.

    The English site is at http://www.evolutiongaming.com/ or http://www.evolutiongaming.com/en/
    The same page in Swedish will be http://www.evolutiongaming.com/sv/

    Notice that the Swedish page is very empty since there is no Swedish content yet (the site is only launched in English so far). But, down to the right, you have the newsletter signup. As you can see, the text just above the form field is in Swedish, that is translated with a third party plugin.

    But, if you sign up for the newsletter, the message that you get after submitting and the email you get should also be in Swedish but they are not. This text is EE system output.

    With a logged in user with Swedish chosen in the profile this text is in Swedish.

    I hope my description is understandable.

    / Mattias

  • #8 / Jan 26, 2011 4:18pm

    Ingmar

    29245 posts

    I am afraid there is no supported way to provide language-specific content for non-logged in users. All localisation is done via language packs, and you can also provide a default one to be used for people not having signed up (yet).

  • #9 / Jan 27, 2011 3:57am

    Silentium

    19 posts

    Okay. Thank you for the information, I have report that to my customer.

    Is there any plans/ides of implementing this into EE in the future?

  • #10 / Jan 27, 2011 4:20pm

    Ingmar

    29245 posts

    I would recommend to check out some possible third-party add-ons over at devot-ee.com. You’re also welcome to make a Feature Request, of course.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases