Jump to:

10928 Posts in 2612 Topics by 1809 members

All other Modules

SilverStripe Forums » All other Modules » TranslatableModelAdmin: Locale is always the default locale

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 2189 Views
  • dacar
    Avatar
    Community Member
    168 Posts

    TranslatableModelAdmin: Locale is always the default locale Link to this post

    Hi,

    i have just found and installed TranslatableModelAdmin. Installation works fine. The promised dropdown is visible. But if i select e.g. english (en_US) and create a new data object, then there will be "de_DE" to the locale field of my table.

    in my _config.php i use:

    // Einstellungen für die Mehrsprachigkeit:
    Object::add_extension('SiteTree', 'Translatable');
    Translatable::set_default_locale('de_DE');
    Translatable::enable();
    Translatable::set_allowed_locales(array(
       'de_DE',
       'en_US',
       'ru_RU',
       'fr_FR',
       'es_ES'
       )
    );

    Can anybody help on this problem?

    Greeetings, Carsten.

  • dacar
    Avatar
    Community Member
    168 Posts

    Re: TranslatableModelAdmin: Locale is always the default locale Link to this post

    hi,

    TranslatableModelAdmin is still not working, even after a coplete new database setup

    here is my _config.php:

    Object::add_extension('SiteTree', 'Translatable');
    Object::add_extension('DATAOBJECTTOBETRANSLATED', 'Translatable');
    Translatable::set_default_locale('de_DE');
    Translatable::set_allowed_locales(array(
       'de_DE',
       'en_US',
       'ru_RU',
       'fr_FR',
       'es_ES'
       )
    );

    Even if i select a language different from my default locale, always the default locale is written into the db.

    in TranslatableModelAdmin.php i found the following:

       /**
    * Returns all languages with languages already used appearing first.
    * Called by the SSViewer when rendering the template.
    */
    function LangSelector() {
          if(Object::has_extension($this->modelClass, 'Translatable')) {
             $member = Member::currentUser(); //check to see if the current user can switch langs or not
             if(Permission::checkMember($member, 'VIEW_LANGS')) {
                $dropdown = new LanguageDropdownField(
                   'LangSelector',
                   'Language',
                   array(),
                   $this->modelClass,
                   'Locale-English'
                );
                $dropdown->setValue(Translatable::get_current_locale());
                return $dropdown;
        }

        //user doesn't have permission to switch langs so just show a string displaying current language
        return i18n::get_locale_name( Translatable::get_current_locale() );
       }
    }
    }

    The method summary from http://api.silverstripe.org/sapphire/core/LanguageDropdownField.html says:

    Constructor __construct (line 17)

    Create a new LanguageDropdownField
    LanguageDropdownField __construct (string $name, string $title, [array $dontInclude = array()], [string $translatingClass = 'SiteTree'], [string $list = 'Common-English'])

    * string $name
    * string $title
    * array $dontInclude: list of languages that won't be included
    * string $translatingClass: Name of the class with translated instances where to look for used languages
    * string $list: Indicates the source language list. Can be either Common-English, Common-Native Locale


    what is the job of $list? Why is it set to 'Locale-English'?
    Why is it $dropdown->setValue(Translatable::get_current_locale());? Mustn't it be the value from line 19: Session::set('TranslatableModelAdmin.Locale', $_GET['locale']);?

    There must be a reason why the default locale is written to db and not the selected language. Is nobody saving translations of dataobjects to db?

    I am working on this for a couple of days and still got a answer from anybody. Pleaseeee help...

  • dacar
    Avatar
    Community Member
    168 Posts

    Re: TranslatableModelAdmin: Locale is always the default locale Link to this post

    Hi, unfortunately i still got it not working! Can't anybody give an example how to use TranslatableModelAdmin? How can i refer to a dataobject that is set to be locale (de_DE)? When you edit an element from sitetree you can select the "translations-Tab" and translate an existing item to the selected language. I can't find out how to do this with TranslatableModelAdmin.

    Thanks for your help.

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: TranslatableModelAdmin: Locale is always the default locale Link to this post

    Uhm, it seems like the button for actually creating translations was never included in the module, but must be somewhere in custom code where the module was first used. As you can see from its version history, its a very young module...

    I've rewritten it a bit in http://open.silverstripe.org/changeset/90808 and ensured that a "create translation" button is visible and creates the correct language. There's a couple of minor bugs (see TODO's in the commit) that I wasn't able to fix right now.

  • dacar
    Avatar
    Community Member
    168 Posts

    Re: TranslatableModelAdmin: Locale is always the default locale Link to this post

    Hi Ingo, thank you so much for your reply. I was wondering so much that nobody replys. I will check your patches tomorrow. What do you mean by "see TODO's in the commit". Where can i find it?

    @all others: how do you manage content that can't be managed with sitetree (e.g. daylie news)? How do you translate it?

    Greetings from germany, Carsten.

  • dacar
    Avatar
    Community Member
    168 Posts

    Re: TranslatableModelAdmin: Locale is always the default locale Link to this post

    Hi Ingo, i gave it a try and it seems to be working fine. Thanks again.

    2189 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.