mirror of
https://github.com/silverstripe/silverstripe-translatable
synced 2024-10-22 11:05:59 +02:00
Merge branch '2.2' into 2.3
This commit is contained in:
commit
50f145a891
10
.travis.yml
10
.travis.yml
@ -3,19 +3,17 @@
|
|||||||
language: php
|
language: php
|
||||||
|
|
||||||
php:
|
php:
|
||||||
- 5.3
|
- 5.6
|
||||||
|
|
||||||
env:
|
env:
|
||||||
- DB=MYSQL CORE_RELEASE=3
|
- DB=MYSQL CORE_RELEASE=3
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- php: 5.4
|
|
||||||
env: DB=PGSQL CORE_RELEASE=3
|
|
||||||
- php: 5.5
|
|
||||||
env: DB=MYSQL CORE_RELEASE=3.2
|
|
||||||
- php: 5.6
|
- php: 5.6
|
||||||
env: DB=MYSQL CORE_RELEASE=3.2
|
env: DB=PGSQL CORE_RELEASE=3
|
||||||
|
- php: 5.6
|
||||||
|
env: DB=MYSQL CORE_RELEASE=3
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- pear -q install --onlyreqdeps pear/PHP_CodeSniffer
|
- pear -q install --onlyreqdeps pear/PHP_CodeSniffer
|
||||||
|
@ -21,7 +21,7 @@ class LanguageDropdownField extends GroupedDropdownField {
|
|||||||
* @param string $list Indicates the source language list.
|
* @param string $list Indicates the source language list.
|
||||||
* Can be either Common-English, Common-Native, Locale-English, Locale-Native
|
* Can be either Common-English, Common-Native, Locale-English, Locale-Native
|
||||||
*/
|
*/
|
||||||
function __construct($name, $title, $excludeLocales = array(),
|
public function __construct($name, $title = null, $excludeLocales = array(),
|
||||||
$translatingClass = 'SiteTree', $list = 'Common-English', $instance = null
|
$translatingClass = 'SiteTree', $list = 'Common-English', $instance = null
|
||||||
) {
|
) {
|
||||||
$usedLocalesWithTitle = Translatable::get_existing_content_languages($translatingClass);
|
$usedLocalesWithTitle = Translatable::get_existing_content_languages($translatingClass);
|
||||||
|
@ -743,7 +743,12 @@ class Translatable extends DataExtension implements PermissionProvider {
|
|||||||
if(!$obj || $obj->ObsoleteClassName) continue;
|
if(!$obj || $obj->ObsoleteClassName) continue;
|
||||||
|
|
||||||
$obj->Locale = Translatable::default_locale();
|
$obj->Locale = Translatable::default_locale();
|
||||||
$obj->writeToStage($stage);
|
|
||||||
|
$oldMode = Versioned::get_reading_mode();
|
||||||
|
Versioned::reading_stage($stage);
|
||||||
|
$obj->writeWithoutVersion();
|
||||||
|
Versioned::set_reading_mode($oldMode);
|
||||||
|
|
||||||
$obj->addTranslationGroup($obj->ID);
|
$obj->addTranslationGroup($obj->ID);
|
||||||
$obj->destroy();
|
$obj->destroy();
|
||||||
unset($obj);
|
unset($obj);
|
||||||
@ -932,7 +937,7 @@ class Translatable extends DataExtension implements PermissionProvider {
|
|||||||
$fresh = Versioned::get_one_by_stage(
|
$fresh = Versioned::get_one_by_stage(
|
||||||
$baseDataClass,
|
$baseDataClass,
|
||||||
Versioned::current_stage(),
|
Versioned::current_stage(),
|
||||||
'"ID" = ' . $this->owner->ID,
|
'"'.$baseDataClass.'"."ID" = ' . $this->owner->ID,
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
if ($fresh) {
|
if ($fresh) {
|
||||||
@ -1065,69 +1070,71 @@ class Translatable extends DataExtension implements PermissionProvider {
|
|||||||
$alreadyTranslatedLocales[$this->owner->Locale] = $this->owner->Locale;
|
$alreadyTranslatedLocales[$this->owner->Locale] = $this->owner->Locale;
|
||||||
$alreadyTranslatedLocales = array_combine($alreadyTranslatedLocales, $alreadyTranslatedLocales);
|
$alreadyTranslatedLocales = array_combine($alreadyTranslatedLocales, $alreadyTranslatedLocales);
|
||||||
|
|
||||||
// Check if fields exist already to avoid adding them twice on repeat invocations
|
if ($fields->hasTabSet()) {
|
||||||
$tab = $fields->findOrMakeTab('Root.Translations', _t('Translatable.TRANSLATIONS', 'Translations'));
|
// Check if fields exist already to avoid adding them twice on repeat invocations
|
||||||
if(!$tab->fieldByName('CreateTransHeader')) {
|
$tab = $fields->findOrMakeTab('Root.Translations', _t('Translatable.TRANSLATIONS', 'Translations'));
|
||||||
$tab->push(new HeaderField(
|
if(!$tab->fieldByName('CreateTransHeader')) {
|
||||||
'CreateTransHeader',
|
$tab->push(new HeaderField(
|
||||||
_t('Translatable.CREATE', 'Create new translation'),
|
'CreateTransHeader',
|
||||||
2
|
_t('Translatable.CREATE', 'Create new translation'),
|
||||||
));
|
2
|
||||||
}
|
|
||||||
if(!$tab->fieldByName('NewTransLang') && !$tab->fieldByName('AllTransCreated')) {
|
|
||||||
$langDropdown = LanguageDropdownField::create(
|
|
||||||
"NewTransLang",
|
|
||||||
_t('Translatable.NEWLANGUAGE', 'New language'),
|
|
||||||
$alreadyTranslatedLocales,
|
|
||||||
'SiteTree',
|
|
||||||
'Locale-English',
|
|
||||||
$this->owner
|
|
||||||
)->addExtraClass('languageDropdown no-change-track');
|
|
||||||
$tab->push($langDropdown);
|
|
||||||
$canAddLocale = (count($langDropdown->getSource()) > 0);
|
|
||||||
|
|
||||||
if($canAddLocale) {
|
|
||||||
// Only add create button if new languages are available
|
|
||||||
$tab->push(
|
|
||||||
$createButton = InlineFormAction::create(
|
|
||||||
'createtranslation',
|
|
||||||
_t('Translatable.CREATEBUTTON', 'Create')
|
|
||||||
)->addExtraClass('createTranslationButton')
|
|
||||||
);
|
|
||||||
$createButton->includeDefaultJS(false); // not fluent API...
|
|
||||||
} else {
|
|
||||||
$tab->removeByName('NewTransLang');
|
|
||||||
$tab->push(new LiteralField(
|
|
||||||
'AllTransCreated',
|
|
||||||
_t('Translatable.ALLCREATED', 'All allowed translations have been created.')
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
if(!$tab->fieldByName('NewTransLang') && !$tab->fieldByName('AllTransCreated')) {
|
||||||
if($alreadyTranslatedLocales) {
|
$langDropdown = LanguageDropdownField::create(
|
||||||
if(!$tab->fieldByName('ExistingTransHeader')) {
|
"NewTransLang",
|
||||||
$tab->push(new HeaderField(
|
_t('Translatable.NEWLANGUAGE', 'New language'),
|
||||||
'ExistingTransHeader',
|
$alreadyTranslatedLocales,
|
||||||
_t('Translatable.EXISTING', 'Existing translations'),
|
'SiteTree',
|
||||||
3
|
'Locale-English',
|
||||||
));
|
$this->owner
|
||||||
if (!$tab->fieldByName('existingtrans')) {
|
)->addExtraClass('languageDropdown no-change-track');
|
||||||
$existingTransHTML = '<ul>';
|
$tab->push($langDropdown);
|
||||||
if ($existingTranslations = $this->getTranslations()) {
|
$canAddLocale = (count($langDropdown->getSource()) > 0);
|
||||||
foreach ($existingTranslations as $existingTranslation) {
|
|
||||||
if ($existingTranslation && $existingTranslation->hasMethod('CMSEditLink')) {
|
if($canAddLocale) {
|
||||||
$existingTransHTML .= sprintf(
|
// Only add create button if new languages are available
|
||||||
'<li><a href="%s">%s</a></li>',
|
$tab->push(
|
||||||
Controller::join_links(
|
$createButton = InlineFormAction::create(
|
||||||
$existingTranslation->CMSEditLink(),
|
'createtranslation',
|
||||||
'?Locale=' . $existingTranslation->Locale
|
_t('Translatable.CREATEBUTTON', 'Create')
|
||||||
),
|
)->addExtraClass('createTranslationButton')
|
||||||
i18n::get_locale_name($existingTranslation->Locale)
|
);
|
||||||
);
|
$createButton->includeDefaultJS(false); // not fluent API...
|
||||||
|
} else {
|
||||||
|
$tab->removeByName('NewTransLang');
|
||||||
|
$tab->push(new LiteralField(
|
||||||
|
'AllTransCreated',
|
||||||
|
_t('Translatable.ALLCREATED', 'All allowed translations have been created.')
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($alreadyTranslatedLocales) {
|
||||||
|
if(!$tab->fieldByName('ExistingTransHeader')) {
|
||||||
|
$tab->push(new HeaderField(
|
||||||
|
'ExistingTransHeader',
|
||||||
|
_t('Translatable.EXISTING', 'Existing translations'),
|
||||||
|
3
|
||||||
|
));
|
||||||
|
if (!$tab->fieldByName('existingtrans')) {
|
||||||
|
$existingTransHTML = '<ul>';
|
||||||
|
if ($existingTranslations = $this->getTranslations()) {
|
||||||
|
foreach ($existingTranslations as $existingTranslation) {
|
||||||
|
if ($existingTranslation && $existingTranslation->hasMethod('CMSEditLink')) {
|
||||||
|
$existingTransHTML .= sprintf(
|
||||||
|
'<li><a href="%s">%s</a></li>',
|
||||||
|
Controller::join_links(
|
||||||
|
$existingTranslation->CMSEditLink(),
|
||||||
|
'?Locale=' . $existingTranslation->Locale
|
||||||
|
),
|
||||||
|
i18n::get_locale_name($existingTranslation->Locale)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$existingTransHTML .= '</ul>';
|
||||||
|
$tab->push(new LiteralField('existingtrans', $existingTransHTML));
|
||||||
}
|
}
|
||||||
$existingTransHTML .= '</ul>';
|
|
||||||
$tab->push(new LiteralField('existingtrans', $existingTransHTML));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1572,15 +1579,15 @@ class Translatable extends DataExtension implements PermissionProvider {
|
|||||||
function MetaTags(&$tags) {
|
function MetaTags(&$tags) {
|
||||||
$template = '<link rel="alternate" type="text/html" title="%s" hreflang="%s" href="%s" />' . "\n";
|
$template = '<link rel="alternate" type="text/html" title="%s" hreflang="%s" href="%s" />' . "\n";
|
||||||
$translations = $this->owner->getTranslations();
|
$translations = $this->owner->getTranslations();
|
||||||
if($translations) {
|
if($translations->count()) {
|
||||||
$translations = $translations->toArray();
|
$translations = $translations->toArray();
|
||||||
$translations[] = $this->owner;
|
$translations[] = $this->owner;
|
||||||
|
|
||||||
foreach($translations as $translation) {
|
foreach($translations as $translation) {
|
||||||
$tags .= sprintf($template,
|
$tags .= sprintf($template,
|
||||||
Convert::raw2xml($translation->Title),
|
Convert::raw2xml($translation->Title),
|
||||||
i18n::convert_rfc1766($translation->Locale),
|
i18n::convert_rfc1766($translation->Locale),
|
||||||
$translation->AbsoluteLink()
|
$translation->AbsoluteLink()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1766,7 +1773,7 @@ class Translatable extends DataExtension implements PermissionProvider {
|
|||||||
* @deprecated 2.4 Use get_reading_locale()
|
* @deprecated 2.4 Use get_reading_locale()
|
||||||
*/
|
*/
|
||||||
static function get_reading_lang() {
|
static function get_reading_lang() {
|
||||||
return i18n::get_lang_from_locale(self::get_reading_locale());
|
return i18n::get_lang_from_locale(self::get_current_locale());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,6 +22,9 @@ class TranslatableSiteConfigTest extends SapphireTest {
|
|||||||
|
|
||||||
$this->origLocale = Translatable::default_locale();
|
$this->origLocale = Translatable::default_locale();
|
||||||
Translatable::set_default_locale("en_US");
|
Translatable::set_default_locale("en_US");
|
||||||
|
|
||||||
|
// Delete any default records created outside of fixtures
|
||||||
|
SiteConfig::get()->exclude('ID', $this->allFixtureIDs('SiteConfig'))->removeAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
function tearDown() {
|
function tearDown() {
|
||||||
|
Loading…
Reference in New Issue
Block a user