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.

General Questions /

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

Translatable custom data object?


Reply


18 Posts   3518 Views

Avatar
spyrosk

Community Member, 16 Posts

24 December 2010 at 10:23pm

I believe I have the right stuff on my _config.php as I am able to translate pages and view the sitetree per language. I haven't added yet the language flags as I am trying to make this work in the back-end first.
I am testing code to implement this functionality right now:
Create ProjectPage's with a hasOne relationship to ProjectCountry.
ProjectCountry is a dataObject with 2 fields, name and countryCode.
And I want to create a couple of entries in the countryCode, translated both in English and Greek. Then when a user tries to add a ProductPage I want him to be able to select the corresponding ProjectCountry while viewing the list in his selected language.
Is this making sense to you?

Thank you again.

Avatar
swaiba

Forum Moderator, 1798 Posts

24 December 2010 at 10:33pm

That is great! My advice would be to focus entirely on a solution with pages right now - so complete what you have to the point that the website can operate in different languages.

As I said I cannot help with translation of dataobjects yet because I have only briefly looked at the module... that is why I advise using the stuff tried, tested and documented with pages right now :)

Avatar
spyrosk

Community Member, 16 Posts

24 December 2010 at 10:42pm

Thank you Barry, well I could not get it to work as I wanted using pages so I'll keep trying with translatableModelAdmin.
Have you implemented something like this in the past using Pages?
In any case thank you very much!

Spyros

Avatar
swaiba

Forum Moderator, 1798 Posts

24 December 2010 at 10:51pm

I have used translations to provide plain page translations. But I do need to start having dataobject translatable too - but not yet!

Please post back your solution when it's working I am very interested in this area.

Avatar
spyrosk

Community Member, 16 Posts

24 December 2010 at 11:53pm

I will post it since I haven't found any tutorial that accomplishes this and I suppose there are a lot of people interested.

Avatar
hammuh

Community Member, 15 Posts

20 January 2011 at 11:42pm

Edited: 21/01/2011 8:44pm

Hi Spyrosk,

I'm in the same situation. The page translation is no problem with :

Object::add_extension('SiteTree', 'Translatable');
Object::add_extension('SiteConfig', 'Translatable');
Translatable::set_allowed_locales( array('nl_NL', 'en_US', 'es_ES'));

But the translations of the DataObject managed in ModelAdmin is much more difficult.

A possible solution is adding a field to your DataObjects called "Lang" or something like that. Make it a dropdown field with the available languages. In my case nl_NL, en_EN and es_ES. Everytime you create a new DataObject, you select what language it is.

In your template you can put this:

<% control ObjectByLang %>
<!-- whatever you want -->
<% end_control %>

In your controller:

public function ObjectByLang() {
$currentReadingLocale = Translatable::get_current_locale();

$MyObject= DataObject::get(
   $callerClass = "classname",
   $filter = "Lang = '$currentReadingLocale'",
   $sort = "",
   $join = "",
   $limit = ""
);
return $MyObject;
}

Only with this solution you have to create 3 different DataObject instead of one.

If you already have another solution, I'll hope you ost it back!

Avatar
spyrosk

Community Member, 16 Posts

11 February 2011 at 2:43am

Hi hammuh,
first of all I'm sorry I didn't reply for so long but I haven't really solved this. The workaround I used was to create two separate installations of SS on different directories, one for each language.
This means that now I have to edit the code twice for each change, but it is easier to edit content that doesn't apply to both languages, i.e. some data should only be visible to visitors from country X.
I will try your solution in the future where a 1 to 1 relationship (on translated content) is required.
Thank you very much for your help.
Spyros

Avatar
Chris_Bryer

Community Member, 35 Posts

14 February 2011 at 7:39pm

hey spyrosk,
you may have the same problem others (including me) have had.
this requires 2 patches, entered in bug tracker [url=http://open.silverstripe.org/ticket/4199]here[/url]

-Chris