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.

All other Modules

Discuss all other Modules here.

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

TranslatableModelAdmin: Locale is always the default locale


Reply

6 Posts   2226 Views

Avatar
dacar

27 October 2009 at 2:16am Community Member, 168 Posts

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.

Avatar
dacar

31 October 2009 at 2:21am (Last edited: 31 October 2009 2:22am), Community Member, 168 Posts

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 [url]http://api.silverstripe.org/sapphire/core/LanguageDropdownField.html[/url] 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...

Avatar
dacar

3 November 2009 at 2:37am Community Member, 168 Posts

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.

Avatar
Ingo

5 November 2009 at 9:47am Forum Moderator, 801 Posts

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.

Avatar
dacar

5 November 2009 at 11:52am Community Member, 168 Posts

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.

Avatar
dacar

25 November 2009 at 11:49am Community Member, 168 Posts

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