Jump to:

23575 Posts in 19402 Topics by 2893 members

General Questions

SilverStripe Forums » General Questions » "home" & Translatable

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 3177 Views
  • lazerscience
    Avatar
    Community Member
    16 Posts

    "home" & Translatable Link to this post

    Hi!
    I have set up a site, working with "Translatable" and 4 languages! I'm just not exactly sure how to create home/frontpages for the different languages; as I know SS takes the page with the URL home as default home page, how is/should this be handled for more than one language?
    Thanks!

  • lazerscience
    Avatar
    Community Member
    16 Posts

    Re: "home" & Translatable Link to this post

    Noone having experience with that?

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: "home" & Translatable Link to this post

    Sorry for the confusion, the key here is that the translated homepage has to be a direct translation of the default language homepage. I've added some documentation: http://doc.silverstripe.com/doku.php?id=multilingualcontent#translating_the_homepage

  • ChrisBryer
    Avatar
    Community Member
    95 Posts

    Re: "home" & Translatable Link to this post

    Has anyone figured out how to point a .de domain to a German translation and a .com domain to an English translation?

    i set up a name based virtual host to point my german site to the english site's german-translated homepage (mysite.com/haus), but now my language switcher on the german site wont let me switch to the english homepage (because name-based virtual host redirects / to /haus). any advice is really appreciated... i've seen some people handle this through sub domains, but i dont know what the best way to handle this is.

    thanks alot!
    -Chris

  • martimiz
    Avatar
    Forum Moderator
    1091 Posts

    Re: "home" & Translatable Link to this post

    just thinking - what if you force a language only when the user is requesting the site root, as in http://www.[domain].[ext]/ Then after the user enters the site he can switch to where-ever he wants, as long as the site root is not used, that is...

    Suppose something like this could be done in .htaccess?

  • ChrisBryer
    Avatar
    Community Member
    95 Posts

    Re: "home" & Translatable Link to this post

    well, i tried something like this in my .htaccess, and it doesnt work the way i want it:

    RewriteCond %{HTTP_HOST} ^www.mysite.jp$ [NC]
    RewriteRule ^(.*)$ http://www.mysite.com/home-ja-JP/$1 [R=301,L]

    the problem that i have with that is that it redirects .jp to.com/home-ja-jp, while i sort of want an alias instead to hold onto the .jp domain.

    if i force a locale, like making a name-based virtual host for mysite.jp to point to mysite.com/?locale=ja_jp (much like mysite.com/home-ja-jp), anytime a user uses the language chooser, it'll keep redirecting / back to /home-ja-jp..

    if the url for .com/ was .com/home/ than i could easily switch between languages and the name-based virtual hosts would work fine. anyone know how to get / back to /home? this is probably like the 'Use this page as the 'home page' for the following domains' field in the behaviour tab, but i cant get that to work.

    thanks for your thoughts Martimiz,
    -Chris

  • dkwad
    Avatar
    Community Member
    2 Posts

    Re: "home" & Translatable Link to this post

    Hi Chris,

    Did you have any luck with this?

  • ChrisBryer
    Avatar
    Community Member
    95 Posts

    Re: "home" & Translatable Link to this post

    yes, i figured it out. it took me a while because there were so many strategies to dealing with urls and multi-lingual...

    what i ended up doing was forcing anything going to a fr domain to be french, and anything going to .com to be english. there wasnt any real need to have the language switcher stay within the domain, so now the language switcher just points to the fr, jp, it, or whatever domain.

    from a little research, the best approaches ive seen, and most recommended, are either using subdomains or subfolders to funnel traffic to one language or another. they both are just as SEO as each other, but setting up sub-domains is a little more intensive.

    here are other peoples approach to solving.. i did something a little different.

    sub-domain approach:
    http://silverstripe.org/archive/show/235501#post235501

    sub-directory approach:
    http://silverstripe.org/archive/show/235501#post235501 This 'how-to' was written prior to 2.3.2 and didnt completely line up with code in the current release.

    google recommends having multiple top-level domains (.com, .fr, .jp) to distinguish language rather than subdomain or subfolder. (keep-it-simple principle i guess). here's how i set up the htaccess..

    RewriteCond %{HTTP_HOST} ^www\.(domain1|domain2|domain3)\.(.*)$ [NC]
    RewriteRule ^(.*) $1?lang=%2&%{QUERY_STRING}


    for my client, they have multiple comain names.. this.com, this.fr, that.com, that.fr.
    all domains point to the same location. the htaccess takes any domain name, with any extension / TLD, and rewrites it as www.[this or that].[fr].
    it also adds one more param to the query string, a language param, so it would look like www.[this or that].[fr]?lang=fr
    all good, and silverstripe still understands all the params, but the controller needs to know what to do with the lang param.
    here is the code i put in the page_controller class:

    class Page_Controller extends ContentController {
       
       function init(){
          parent::init();
          
          if($this->dataRecord->hasExtension('Translatable')){
             if($_GET['lang']) {
                //find the correct locale
                $curLoc = $this->convertTLD2Locale($_GET['lang']);
                //check to see if our website is serving the right page
                if(Translatable::get_current_locale() != $curLoc){
                   $correctPage = Translatable::get_one_by_locale($this->dataRecord->ClassName, $curLoc);
                   Director::redirect($correctPage->URLSegment);
                }
             } else i18n::set_locale($this->dataRecord->Locale);
          }
    //...
    }
    function convertTLD2Locale($TLD = 'com'){
          //i18n doesnt contain any lookup tables for domains and languages, so we create one.
          $loc = 'en_US';
          switch ($TLD) {
             case 'de': $loc = 'de_DE';
                break;
             case 'jp': $loc = 'ja_JP';
                break;
             default: $loc = 'en_US';
          }
          return $loc;
       }


    the init compares the current locale with the requested, and if different, finds the translated page and redirects. most of the time, it doesnt have to redirect, with the exception of homepages.

    The init method could probably be rewritten to check the domain instead of passing in the the domain in as a param from the htaccess, but it was late, i had tried so many methods that this is what i came up with. works pretty good, but on the .com site, clicking on the homepage link sometimes adds &lang=en_US because of the /home rewrite rules.. not the worst thing, but works. htaccess mods could fix that pretty easily.

    hope it helps.
    -Chris

    3177 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.