Jump to:

1851 Posts in 1606 Topics by 561 members

Blog Module

SilverStripe Forums » Blog Module » i18n multilingual blog

Discuss the Blog Module.

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

Page: 1
Go to End
Author Topic: 3081 Views
  • Anatol
    Avatar
    126 Posts

    i18n multilingual blog Link to this post

    Hi,

    I installed the blog 0.2.0 RC1. According to the change log the blog is now translatable. I can see that the blog folder contains a "lang" directory with language files for template _t variables. But how can I translate the content for a multilingual site? The blog holder page type has a "Translations" tab in the CMS, but blog entries don't.

    Cheers!
    Anatol

  • Anatol
    Avatar
    126 Posts

    Re: i18n multilingual blog Link to this post

    I'm a bit further but eventually I only get an Ajax error.

    I could add the "translatable" tab in the CMS to the blog entry page type. In the BlogEntry class (/blog/code/BlogEntry.php) I added the Translatable extension (see below in red)

    static $extensions = array(
          'Hierarchy',
          'TrackBackDecorator',
          "Versioned('Stage', 'Live')",
          "Translatable('Content')"

       );

    The "Translations" tab is now visible for blog entries. It should do the trick but when rebuild the database with /db/build/?flush=1 and I reload the CMS I cannot add any more translatable pages because of the following Ajax error:

    Error in Ajax evaluator on line 973: missing ; before statement There has been an error

    +++ update +++
    The Ajax error happens because I made a custom field 'ContentMore' translatable. If I just make the standard fields translatable (e.g. 'Content') as shown above it works. There is still a problem with the BlogHolder. It does only show blog entries in the default language. If I switch to the 'secondary' language it does not find any blog entries, even though blog entries exist as children under the blog holder.

    I think I am close but not there yet. Any ideas are highly appreciated.

    Cheers!
    Anatol

  • defunct
    Avatar
    Community Member
    3 Posts

    Re: i18n multilingual blog Link to this post

    Did you ever figure this out?

  • Henk Poley
    Avatar
    30 Posts

    Re: i18n multilingual blog Link to this post

    The official way to enable translation is by adding the following to mysite/_config.php:

    i18n::enable();
    i18n::set_default_lang('nl_NL');

    But use your language instead of 'nl_NL'. Then I think you need to 'translate' the root entry of the blog.

    Everything is described here: http://doc.silverstripe.com/doku.php?id=i18n&s=set%

    [edit] Actually the official news is that Translatable is broken in Silverstripe 2.3.0-2.3.1
    Also see for controls translation: http://silverstripe.org/blog-module-forum/show/257317?start=0#post257386

  • Kalileo
    Avatar
    Community Member
    127 Posts

    Re: i18n multilingual blog Link to this post

    Check out the recipe at Alternative multilingual recipe - works for me on a SS 2.3.1 site, also for the blog, even the ecommerce module. You just have to add the fields you want following the recipe. I did so even for title and meta tags.

    More info about it in the forum discussion here Multilingual Content - alternative to 'translatable' .

  • Kalileo
    Avatar
    Community Member
    127 Posts

    Re: i18n multilingual blog Link to this post

    I just remembered that the Alternative multilingual recipe required some additional code (for me at least) to allow me also to have multilingual blog entries.
    For reasons which I didn't take the time to debug and find out the CMS does not show the content fields for the other language(s) when the page is a blogentry. But don't worry, here's a workaround:

    In /blog/code/BlogEntry.php, in the function getCMSFields(), which is currently at line 66, add the following lines at line 78:

    $fields->removeFieldFromTab("Root.Content.Deutsch","Content_de");
    $fields->addFieldToTab('Root.Content.Deutsch', new TextareaField('Content_de', "De-Content"));

    Of course modify the Root.Content.Deutsch to whatever language(s) you're using.

    Here's the complete getCMSFields() function in /blog/code/BlogEntry.php as I'm using it here for English blog/news cleaning Thailand's waste water and here for the same BlogEntry in German Thailand's Haushalts-Abwasser reinigen, you can see at the comment in the code where the patch needs to get inserted.

    function getCMSFields() {
    Requirements::javascript('blog/javascript/bbcodehelp.js');
    Requirements::themedCSS('bbcodehelp');

    $firstName = Member::currentUser() ? Member::currentUser()->FirstName : '';
    $codeparser = new BBCodeParser();

    $fields = parent::getCMSFields();

    if(!self::$allow_wysiwyg_editing) {
    $fields->removeFieldFromTab("Root.Content.Main","Content");
    $fields->addFieldToTab("Root.Content.Main", new TextareaField("Content", _t("BlogEntry.CN", "Content"), 20));
    /**
    * lines below added by Kalileo 2009-05-03 to make the Content fields visible
    * in the other language tabs.
    * For whatever reason they must NOT be named "Content", otherwise it freezes
    * didn't take the time to debug it, the "other name" workaround is OK for me
    */
    $fields->removeFieldFromTab("Root.Content.Deutsch","Content_de");
    $fields->addFieldToTab('Root.Content.Deutsch', new TextareaField('Content_de', "De-Content"));
    $fields->removeFieldFromTab("Root.Content.Thai","Content_th");
    $fields->addFieldToTab('Root.Content.Thai', new TextareaField('Content_th', "Th-Content"));
    /** Addon by Kalileo - END */
    }

    $fields->addFieldToTab("Root.Content.Main", new PopupDateTimeField("Date", _t("BlogEntry.DT", "Date")),"Content");
    $fields->addFieldToTab("Root.Content.Main", new TextField("Author", _t("BlogEntry.AU", "Author"), $firstName),"Content");

    if(!self::$allow_wysiwyg_editing) {
    $fields->addFieldToTab("Root.Content.Main", new LiteralField("BBCodeHelper", "<div id='BBCode' class='field'>" .
    "<a id=\"BBCodeHint\" target='new'>" . _t("BlogEntry.BBH", "BBCode help") . "</a>" .
    "<div id='BBTagsHolder' style='display:none;'>".$codeparser->useable_tagsHTML()."</div></div>"));
    }

    $fields->addFieldToTab("Root.Content.Main", new TextField("Tags", _t("BlogEntry.TS", "Tags (comma sep.)")),"Content");
    return $fields;
    }

    This is not my preferred solution, because an update of the blog module will overwrite it, but for now it works

    3081 Views
Page: 1
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.