I just played around with Silverstripe 2.3.2-rc2 and Translatable enabled. Translating pages really works nice with this RC - but translating pages is still a lot of work... you have to manually create translations for each Locale / Language .. after some translations you will go nuts...
So - i am a lazy cms author but a hard-working coder - here are some CMS Batch Actions to make translating pages easier...
Pleae keep in mind: this beta code snippet is just tested (a little bit) against 2.3.2-rc2 - it might not work on older releases .
Please try, improve and let me now.
<?php
/**
* Translate items to all available locales and store new pages as draft - CMS batch action.
* Requires {@link Translatable::enabled} in your _config.php.
*
* Add batch actions by adding this to your _config.php:
* CMSBatchActionHandler::register('translate', 'CMSBatchActionTranslate');
*
* @author Dirk Adler / KLITSCHE.DE
*/
class CMSBatchActionTranslate extends CMSBatchAction
{
function getActionTitle()
{
return _t('CMSBatchActions.TRANSLATE_PAGES_TO_DRAFT', 'Translate to draft');
}
function getDoingText()
{
return _t('CMSBatchActions.TRANSLATING_PAGES_TO_DRAFT', 'Translating pages');
}
function run(DataObjectSet $pages)
{
return $this->batchaction(
$pages,
null,
_t('CMSBatchActions.TRANSLATED_PAGES_TO_DRAFT', 'Processed %d pages and saved %d translations (draft)')
);
}
public function batchaction(DataObjectSet $pages, $helperMethod, $successMessage)
{
if (Translatable::get_allowed_locales() == null)
{
FormResponse::add('statusMessage("'._t('CMSBatchAction.TRANSLATE_ALLOWED_LOCALES','Please add Translatable::set_allowed locales to your _config.php').'","bad");');
}
else
{
$translated = 0;
foreach($pages as $page)
{
foreach (Translatable::get_allowed_locales() as $locale)
{
if ($page->Locale == $locale) continue;
if (! $page->hasTranslation($locale))
{
try
{
$translation = $page->createTranslation($locale);
if ($helperMethod) $translation->$helperMethod();
$translation->destroy();
unset($translation);
$translated++;
}
catch (Exception $e)
{
// no permission - fail gracefully
}
}
}
$page->destroy();
unset($page);
}
$message = sprintf($successMessage, $pages->Count(), $translated);
FormResponse::add('statusMessage("'.$message.'","good");');
}
return FormResponse::respond();
}
}
/**
* Translate and publish items to all other available locales - batch action.
* Requires {@link Translatable::enabled} in your _config.php.
*
* Add batch actions by adding this to your _config.php:
* CMSBatchActionHandler::register('translate-and-publish', 'CMSBatchActionTranslateAndPublish');
*
* @author Dirk Adler / KLITSCHE.DE
*/
class CMSBatchActionTranslateAndPublish extends CMSBatchActionTranslate
{
function getActionTitle()
{
return _t('CMSBatchActions.TRANSLATE_PAGES_TO_LIVE', 'Translate and publish');
}
function getDoingText()
{
return _t('CMSBatchActions.TRANSLATING_PAGES_TO_LIVE', 'Translating and publishing pages');
}
function run(DataObjectSet $pages)
{
return $this->batchaction(
$pages,
'doPublish',
_t('CMSBatchActions.TRANSLATED_PAGES_TO_LIVE', 'Processed %s pages and saved %s translations (live)')
);
}
}
?>
Save code as CMSBatchActionTranslate.php in your site (mysite folder?) and add this to your config.php.
CMSBatchActionHandler::register('translate', 'CMSBatchActionTranslate');
CMSBatchActionHandler::register('translate-and-publish', 'CMSBatchActionTranslateAndPublish');
Happy coding.
drx