Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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

"home" & Translatable


Go to End
Reply


13 Posts   3203 Views

Avatar
lazerscience

Community Member, 16 Posts

19 May 2009 at 6:33am

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!

Avatar
lazerscience

Community Member, 16 Posts

21 May 2009 at 4:15am

Noone having experience with that? :-(

Avatar
Ingo

Forum Moderator, 801 Posts

26 May 2009 at 8:22am

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

Avatar
ChrisBryer

Community Member, 95 Posts

10 September 2009 at 3:01pm

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

Avatar
martimiz

Forum Moderator, 1097 Posts

11 September 2009 at 11:00pm

Edited: 11/09/2009 11:02pm

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?

Avatar
ChrisBryer

Community Member, 95 Posts

12 September 2009 at 6:12am

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

Avatar
dkwad

Community Member, 2 Posts

10 December 2009 at 12:10am

Hi Chris,

Did you have any luck with this?

Avatar
ChrisBryer

Community Member, 95 Posts

11 December 2009 at 10:38am

Edited: 11/12/2009 10:42am

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:
[url]http://silverstripe.org/archive/show/235501#post235501[/url]

sub-directory approach:
[url]http://silverstripe.org/archive/show/235501#post235501[/url] 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

Go to Top