Jump to:

23480 Posts in 18951 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Multilingual Content - alternative to '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 3 4 5 6
Go to End
Author Topic: 11005 Views
  • CriaturaCreativaStudio
    Avatar
    Community Member
    73 Posts

    Re: Multilingual Content - alternative to 'translatable' Link to this post

    Hello!

    everything works fine until when i add:

       protected function getField($field) {      
          $lang = MultiLingual::currentLang();
          $langField = $field.'_'.$lang;
          if(isset($this->record[$langField])) {
             return $this->record[$langField];
          } else {
             return isset($this->record[$field]) ? $this->record[$field] : null;
          }
       }

    it's a bit messy because the page.php i have installed in SS 2.3.1 looks pretty different that the one in this example... Could i get the "final looking" files to try to find the error ?

    Regards!

    Eduardo

  • CriaturaCreativaStudio
    Avatar
    Community Member
    73 Posts

    Re: Multilingual Content - alternative to 'translatable' Link to this post

    i'm trying to use your code on version 2.3.1 and everything works fine until i add the following code:

    protected function getField($field) {
    $lang = MultiLingual::currentLang();
    $langField = $field.'_'.$lang;
    if(isset($this->record[$langField])) {
    return $this->record[$langField];
    } else {
    return isset($this->record[$field]) ? $this->record[$field] : null;
    }
    }

    it's a bit messy because the page.php i have installed in SS 2.3.1 looks pretty different that the one in this example... Could i get the "final looking" files to try to find the error ?

    What i see when i enter this code is a blank screen (white).
    If i remove it, i see pages fine, i see the "english" tab on the cms, and the site appears to load fine, but when i try to load a page after i enter this code, things seem don't work here...

    hope you can help me, i see this working very nice until i reach to this point

    Regards

    Eduardo

    Regards!

    Eduardo

  • dab
    Avatar
    Community Member
    50 Posts

    Re: Multilingual Content - alternative to 'translatable' Link to this post

    I use this recipe and it works fine, but forms dont know that they should use different languages, how i may use different strings when i use forms on py pages?

  • CriaturaCreativaStudio
    Avatar
    Community Member
    73 Posts

    Re: Multilingual Content - alternative to 'translatable' Link to this post

    can anyone please help me on this tweak? it doesnt work here........

  • schellmax
    Avatar
    Community Member
    126 Posts

    Re: Multilingual Content - alternative to 'translatable' Link to this post

    hi eduardo, was busy till now,
    looks as though since 2.3 you have to declare 'getField' method as public, not private:

    public function getField($field) {   ...


    if this doesn't help: could you post your page class?

    @dab: what do you mean by 'using forms'?

  • dab
    Avatar
    Community Member
    50 Posts

    Re: Multilingual Content - alternative to 'translatable' Link to this post

    schellmax: i use multilanguages tabs in CMS, so i need to make forms on my pages also with different languages labels/validation messages. I use recipe from http://doc.silverstripe.com/doku.php?id=recipes:multilingual_content

  • Kalileo
    Avatar
    Community Member
    127 Posts

    Re: Multilingual Content - alternative to 'translatable' Link to this post

    Just implemented the recipe at Alternative multilingual recipe on a SS 2.3.1 site, with 3 language versions, and it works fine.

    Big thanks to the author(s)! Lack of exactly this functionality was the main roadblock which stopped me from using SS before. Now I'm quite excited, with this multilanguage feature in a CMS such as SS my life will be easier

    2 hiccups though, here they are with workarounds:

    1) The homepages in the different languages don't work, as described above by schellmax, http://domain.tld/en/home and http://domain.tld/de/home etc all jump back to http://domain.tld/ - which is not what I want and not what I understand as the desired behavior described in the recipe. Couldn't fix it in the code without applying the core code patch as described by schellmax, but as an alternative workaround I changed the homepage to http://domain.tld/index - the language versions are now at http://domain.tld/de/index and http://domain.tld/en/index etc. Disadvantage: The real homepage is now at http://domain.tld/index and not at http://domain.tld/ . Entering http://domain.tld gets redirected to http://domain.tld/index. But that could certainly be fixed somehow, haven't looked at it yet.

    2) Whenever a translated field is a HtmlEditorField and the page has been opened and saved (without entering content in that field) at least once in the CMS admin area, then these fields are saved with "<p></p>" in them, thus isset() and even empty() will report them as set and not empty, resulting in NOT showing the (untranslated) original field if there is no translation entered yet.

    Yes, that sucks. But here is a workaround, the function getField($field) needs to strip the tags and check then if the translated field is empty, before deciding to serve it or the untranslated one. Here's the function getField($field) modified accordingly:

    function getField($field) {
       $lang = MultiLingual::currentLang();
       $langField = $field.'_'.$lang;
       if(!empty($this->record[$langField]) ) {
          $tempField = trim(strip_tags($this->record[$langField]));
          if (!empty($tempField)) {
             return $this->record[$langField];
          }
       }
       return isset($this->record[$field]) ? $this->record[$field] : null;
    }

    ... and then there are still the forms, as dab already mentions, or more precisely the untranslated labels of the form fields of the usual contact form, haven't looked at that yet.

  • Kalileo
    Avatar
    Community Member
    127 Posts

    Re: Multilingual Content - alternative to 'translatable' Link to this post

    i18n

    If you have i18n enabled, and if you want to have the locale set automatically, you can use this modified MultiLingual.php:

    class MultiLingual extends ModelAsController {
    static $lang;
       
       /** added by Kalileo 2009-04-15 to support i18n - START */
    // change or add your locales here as you need
       var $languages = array(
          'de' => 'de_DE',
          'th' => 'th_TH',
          'en' => 'en_US',
          );
       /** added by Kalileo - END */
       
    function init() {
    $baseUrl = Director::baseUrl();
    $requestUri = $_SERVER['REQUEST_URI'];
    $lang = substr($requestUri, strlen($baseUrl), 2);
    self::$lang = $lang;
          
          /** added by Kalileo 2009-04-15 to support i18n - START */
          if (!empty($this->languages[$lang])) {
             i18n::set_locale($this->languages[$lang]); //Setting the locale
          }
          else {
             i18n::set_locale('en_US'); // default locale is English (USA)
          }      
          /** added by Kalileo - END */
          
    //prevents default behaviour of redirecting to '/' for '/en/'
    if($this->URLParams['URLSegment'] == "" || $this->URLParams['URLSegment'] == 'home') {
    $urlparams = array('URLSegment' => 'home', 'Action' => ' ');
    $this->setURLParams($urlparams);
    }
    parent::init();
    }
    static function currentLang() {
    return self::$lang;
    }
    }

    I tried to add this as a comment to the Alternative multilingual recipe, but it wouldn't let me.

    11005 Views
Page: 1 2 3 4 5 6
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.