mirror of
https://github.com/silverstripe/silverstripe-translatable
synced 2024-10-22 11:05:59 +02:00
Misc 3.1 compat changes
Removed nested_urls check, its the only supported mode now
This commit is contained in:
parent
a3ff187938
commit
cadfdf3400
@ -27,7 +27,7 @@ class LanguageDropdownField extends GroupedDropdownField {
|
|||||||
else if('Common-Native' == $list) $allLocalesWithTitle = i18n::get_common_languages(true);
|
else if('Common-Native' == $list) $allLocalesWithTitle = i18n::get_common_languages(true);
|
||||||
else if('Locale-English' == $list) $allLocalesWithTitle = i18n::get_common_locales();
|
else if('Locale-English' == $list) $allLocalesWithTitle = i18n::get_common_locales();
|
||||||
else if('Locale-Native' == $list) $allLocalesWithTitle = i18n::get_common_locales(true);
|
else if('Locale-Native' == $list) $allLocalesWithTitle = i18n::get_common_locales(true);
|
||||||
else $allLocalesWithTitle = i18n::get_locale_list();
|
else $allLocalesWithTitle = i18n::config()->all_locales;
|
||||||
|
|
||||||
if(isset($allLocales[Translatable::default_locale()])) {
|
if(isset($allLocales[Translatable::default_locale()])) {
|
||||||
unset($allLocales[Translatable::default_locale()]);
|
unset($allLocales[Translatable::default_locale()]);
|
||||||
|
@ -12,20 +12,14 @@
|
|||||||
*
|
*
|
||||||
* <h2>Configuration</h2>
|
* <h2>Configuration</h2>
|
||||||
*
|
*
|
||||||
* <h3>Through Object::add_extension()</h3>
|
* The extension is automatically enabled for SiteTree and SiteConfig records,
|
||||||
* Enabling Translatable through {@link Object::add_extension()} in your _config.php:
|
* if they can be found. Add the following to your config.yml in order to
|
||||||
|
* register a custom class:
|
||||||
|
*
|
||||||
* <code>
|
* <code>
|
||||||
* MyClass::add_extension('Translatable');
|
* MyClass:
|
||||||
* </code>
|
* extensions:
|
||||||
* This is the recommended approach for enabling Translatable.
|
* Translatable
|
||||||
*
|
|
||||||
* <h3>Through $extensions</h3>
|
|
||||||
* <code>
|
|
||||||
* class MyClass extends DataObject {
|
|
||||||
* static $extensions = array(
|
|
||||||
* "Translatable"
|
|
||||||
* );
|
|
||||||
* }
|
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* Make sure to rebuild the database through /dev/build after enabling translatable.
|
* Make sure to rebuild the database through /dev/build after enabling translatable.
|
||||||
@ -76,12 +70,8 @@
|
|||||||
*
|
*
|
||||||
* <h2>Usage for SiteTree</h2>
|
* <h2>Usage for SiteTree</h2>
|
||||||
*
|
*
|
||||||
* Translatable can be used for subclasses of {@link SiteTree} as well.
|
* Translatable can be used for subclasses of {@link SiteTree},
|
||||||
*
|
* it is automatically configured if this class is foun.
|
||||||
* <code>
|
|
||||||
* SiteTree::add_extension('Translatable');
|
|
||||||
* SiteConig::add_extension('Translatable');
|
|
||||||
* </code>
|
|
||||||
*
|
*
|
||||||
* If a child page translation is requested without the parent
|
* If a child page translation is requested without the parent
|
||||||
* page already having a translation in this language, the extension
|
* page already having a translation in this language, the extension
|
||||||
@ -277,7 +267,7 @@ class Translatable extends DataExtension implements PermissionProvider {
|
|||||||
throw new InvalidArgumentException(sprintf('Invalid locale "%s"', $locale));
|
throw new InvalidArgumentException(sprintf('Invalid locale "%s"', $locale));
|
||||||
}
|
}
|
||||||
|
|
||||||
$localeList = i18n::get_locale_list();
|
$localeList = i18n::config()->all_locales;
|
||||||
if(isset($localeList[$locale])) {
|
if(isset($localeList[$locale])) {
|
||||||
self::$default_locale = $locale;
|
self::$default_locale = $locale;
|
||||||
} else {
|
} else {
|
||||||
@ -1524,7 +1514,7 @@ class Translatable extends DataExtension implements PermissionProvider {
|
|||||||
$originalLocale = self::get_current_locale();
|
$originalLocale = self::get_current_locale();
|
||||||
|
|
||||||
self::set_current_locale(self::default_locale());
|
self::set_current_locale(self::default_locale());
|
||||||
$original = SiteTree::get_by_link(RootURLController::get_default_homepage_link());
|
$original = SiteTree::get_by_link(RootURLController::config()->default_homepage_link);
|
||||||
self::set_current_locale($originalLocale);
|
self::set_current_locale($originalLocale);
|
||||||
|
|
||||||
if($original) {
|
if($original) {
|
||||||
@ -1692,12 +1682,10 @@ class Translatable extends DataExtension implements PermissionProvider {
|
|||||||
$IDFilter = ($this->owner->ID) ? "AND \"SiteTree\".\"ID\" <> {$this->owner->ID}" : null;
|
$IDFilter = ($this->owner->ID) ? "AND \"SiteTree\".\"ID\" <> {$this->owner->ID}" : null;
|
||||||
$parentFilter = null;
|
$parentFilter = null;
|
||||||
|
|
||||||
if(SiteTree::nested_urls()) {
|
if($this->owner->ParentID) {
|
||||||
if($this->owner->ParentID) {
|
$parentFilter = " AND \"SiteTree\".\"ParentID\" = {$this->owner->ParentID}";
|
||||||
$parentFilter = " AND \"SiteTree\".\"ParentID\" = {$this->owner->ParentID}";
|
} else {
|
||||||
} else {
|
$parentFilter = ' AND "SiteTree"."ParentID" = 0';
|
||||||
$parentFilter = ' AND "SiteTree"."ParentID" = 0';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$existingPage = SiteTree::get()
|
$existingPage = SiteTree::get()
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
class TranslatableTest extends FunctionalTest {
|
class TranslatableTest extends FunctionalTest {
|
||||||
|
|
||||||
static $fixture_file = 'translatable/tests/unit/TranslatableTest.yml';
|
protected static $fixture_file = 'translatable/tests/unit/TranslatableTest.yml';
|
||||||
|
|
||||||
protected $extraDataObjects = array(
|
protected $extraDataObjects = array(
|
||||||
'TranslatableTest_DataObject',
|
'TranslatableTest_DataObject',
|
||||||
@ -928,7 +928,6 @@ class TranslatableTest extends FunctionalTest {
|
|||||||
$grandchildTranslation = $grandchild->createTranslation('en_AU');
|
$grandchildTranslation = $grandchild->createTranslation('en_AU');
|
||||||
$grandchildTranslation->write();
|
$grandchildTranslation->write();
|
||||||
|
|
||||||
SiteTree::enable_nested_urls();
|
|
||||||
Translatable::set_current_locale('en_AU');
|
Translatable::set_current_locale('en_AU');
|
||||||
|
|
||||||
$this->assertEquals (
|
$this->assertEquals (
|
||||||
@ -983,14 +982,14 @@ class TranslatableTest extends FunctionalTest {
|
|||||||
class TranslatableTest_DataObject extends DataObject implements TestOnly {
|
class TranslatableTest_DataObject extends DataObject implements TestOnly {
|
||||||
// add_extension() used to add decorator at end of file
|
// add_extension() used to add decorator at end of file
|
||||||
|
|
||||||
static $db = array(
|
private static $db = array(
|
||||||
'TranslatableProperty' => 'Text'
|
'TranslatableProperty' => 'Text'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
class TranslatableTest_Extension extends DataExtension implements TestOnly {
|
class TranslatableTest_Extension extends DataExtension implements TestOnly {
|
||||||
|
|
||||||
static $db = array(
|
private static $db = array(
|
||||||
'TranslatableDecoratedProperty' => 'Text'
|
'TranslatableDecoratedProperty' => 'Text'
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1000,7 +999,7 @@ class TranslatableTest_Page extends Page implements TestOnly {
|
|||||||
// static $extensions is inherited from SiteTree,
|
// static $extensions is inherited from SiteTree,
|
||||||
// we don't need to explicitly specify the fields
|
// we don't need to explicitly specify the fields
|
||||||
|
|
||||||
static $db = array(
|
private static $db = array(
|
||||||
'TranslatableProperty' => 'Text'
|
'TranslatableProperty' => 'Text'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user