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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

TranslatableModelAdmin: Locale is always the default locale


Go to End


6 Posts   3040 Views

Avatar
dacar

Community Member, 173 Posts

27 October 2009 at 2:16am

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

Community Member, 173 Posts

31 October 2009 at 2:21am

Edited: 31/10/2009 2:22am

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

Avatar
dacar

Community Member, 173 Posts

3 November 2009 at 2:37am

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

Forum Moderator, 801 Posts

5 November 2009 at 9:47am

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

Community Member, 173 Posts

5 November 2009 at 11:52am

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

Community Member, 173 Posts

25 November 2009 at 11:49am

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