Compare commits
36 Commits
Author | SHA1 | Date |
---|---|---|
Steve Boyd | ed155503d2 | |
Steve Boyd | 8fee2b2372 | |
Steve Boyd | 6a191b09f9 | |
Maxime Rainville | d168dc7830 | |
Sam Minnee | 97379fc92b | |
Sam Minnee | ae1155cd04 | |
Ingo Schommer | a8385e1f43 | |
Maxime Rainville | 23a6c875e6 | |
Aaron Carlino | bed7d9a068 | |
Aaron Carlino | 2f4fc13743 | |
Aaron Carlino | 9b89384aa2 | |
Guy Marriott | 7806356ddc | |
Robbie Averill | a353d52372 | |
Robbie Averill | bff0c63b4f | |
Robbie Averill | f761674834 | |
Robbie Averill | 78694caff3 | |
Robbie Averill | 220e49271c | |
Guy Marriott | 34e5b0bc60 | |
Robbie Averill | c09866f586 | |
Robbie Averill | 43b44f4800 | |
wernerkrauss | 66593d8bb3 | |
Guy | 4cf60e9393 | |
Robbie Averill | 9c8609f788 | |
Dylan Wagstaff | ec34959baa | |
Damian Mooyman | 603abfe1d6 | |
Guy | 6a6bc6d677 | |
Robbie Averill | b8d794a5c2 | |
Damian Mooyman | bea626eba3 | |
Robbie Averill | 50f145a891 | |
Robbie Averill | dfa1c965a5 | |
Robbie Averill | 2c81a62b00 | |
Robbie Averill | 99dd1012b6 | |
Will Rossiter | 4ef5d462dd | |
Micah Sheets | 62523e23df | |
Damian Mooyman | 345bb7a0ec | |
Damian Mooyman | d9f88049d6 |
|
@ -0,0 +1,14 @@
|
|||
name: Build Docs
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- '2.1'
|
||||
paths:
|
||||
- 'docs/en/userguide/**'
|
||||
jobs:
|
||||
build:
|
||||
name: build-docs
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Run build hook
|
||||
run: curl -X POST -d {} https://api.netlify.com/build_hooks/${{ secrets.NETLIFY_BUILD_HOOK }}
|
27
.travis.yml
27
.travis.yml
|
@ -1,27 +1,26 @@
|
|||
# See https://github.com/silverstripe-labs/silverstripe-travis-support for setup details
|
||||
# See https://github.com/silverstripe/silverstripe-travis-support for setup details
|
||||
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.6
|
||||
|
||||
env:
|
||||
- DB=MYSQL CORE_RELEASE=3
|
||||
dist: trusty
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- php: 5.6
|
||||
env: DB=PGSQL CORE_RELEASE=3
|
||||
- php: 5.6
|
||||
env: DB=MYSQL CORE_RELEASE=3
|
||||
- php: '7.1'
|
||||
env: DB=PGSQL CORE_RELEASE=3.7
|
||||
- php: '7.1'
|
||||
env: DB=MYSQL CORE_RELEASE=3.7
|
||||
- php: '7.2'
|
||||
env: DB=MYSQL CORE_RELEASE=3.7
|
||||
- php: '7.3'
|
||||
env: DB=MYSQL CORE_RELEASE=3.7
|
||||
|
||||
before_script:
|
||||
- pear -q install --onlyreqdeps pear/PHP_CodeSniffer
|
||||
- phpenv rehash
|
||||
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support
|
||||
- git clone git://github.com/silverstripe/silverstripe-travis-support.git ~/travis-support
|
||||
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss
|
||||
- cd ~/builds/ss
|
||||
|
||||
script:
|
||||
- vendor/bin/phpunit translatable/tests/
|
||||
- phpcs --encoding=utf-8 --tab-width=4 --standard=translatable/tests/phpcs -np translatable
|
||||
- vendor/bin/phpunit translatable/tests
|
||||
- vendor/bin/phpcs --encoding=utf-8 --tab-width=4 --standard=translatable/tests/phpcs -np translatable
|
||||
|
|
11
README.md
11
README.md
|
@ -1,6 +1,13 @@
|
|||
# IMPORTANT NOTE
|
||||
|
||||
Silverstripe Translatable is only compatible with Silverstripe CMS 3. [Silverstripe CMS 3 has entered limited support in June 2018](https://www.silverstripe.org/blog/update-on-silverstripe-5-x/). This means we'll only be fixing critical bugs and security issues for Silverstripe CMS 3 going forward. This applies to _Translatable_ as well.
|
||||
|
||||
[`silverstripe/fluent`](https://github.com/tractorcow-farm/silverstripe-fluent) is the recommended alternative for Silverstripe CMS 4.
|
||||
|
||||
# Translatable module for SilverStripe CMS #
|
||||
|
||||
[![Build Status](https://secure.travis-ci.org/silverstripe/silverstripe-translatable.png?branch=2.1)](http://travis-ci.org/silverstripe/silverstripe-translatable)
|
||||
[![SilverStripe supported module](https://img.shields.io/badge/silverstripe-supported-0071C4.svg)](https://www.silverstripe.org/software/addons/silverstripe-commercially-supported-module-list/)
|
||||
|
||||
## Introduction ##
|
||||
|
||||
|
@ -27,7 +34,7 @@ third party translation interface, transifex.com.
|
|||
Newly added strings will be periodically uploaded there for translation,
|
||||
and any new translations will be merged back to the project source code.
|
||||
|
||||
Please use [https://www.transifex.com/projects/p/silverstripe-translatable/](https://www.transifex.com/projects/p/silverstripe-translatable/) to contribute translations,
|
||||
Please use [https://www.transifex.com/silverstripe/silverstripe-translatable/](https://www.transifex.com/projects/p/silverstripe-translatable/) to contribute translations,
|
||||
rather than sending pull requests with YAML files.
|
||||
|
||||
See the ["i18n" topic](http://doc.silverstripe.org/framework/en/trunk/topics/i18n) on doc.silverstripe.org for more details.
|
||||
See the ["i18n" topic](https://docs.silverstripe.org/en/3/developer_guides/i18n/) on doc.silverstripe.org for more details.
|
||||
|
|
|
@ -933,13 +933,7 @@ class Translatable extends DataExtension implements PermissionProvider {
|
|||
// This is to prevent the overhead of writing all translations when
|
||||
// the class didn't actually change.
|
||||
$baseDataClass = ClassInfo::baseDataClass($this->owner->class);
|
||||
$currentStage = Versioned::current_stage();
|
||||
$fresh = Versioned::get_one_by_stage(
|
||||
$baseDataClass,
|
||||
Versioned::current_stage(),
|
||||
'"'.$baseDataClass.'"."ID" = ' . $this->owner->ID,
|
||||
null
|
||||
);
|
||||
$fresh = DataObject::get($baseDataClass)->byId($this->owner->ID);
|
||||
if ($fresh) {
|
||||
$changed = $changedFields['ClassName']['after'] != $fresh->ClassName;
|
||||
}
|
||||
|
@ -1300,20 +1294,16 @@ class Translatable extends DataExtension implements PermissionProvider {
|
|||
// exclude the language of the current owner
|
||||
$filter .= sprintf(' AND "%s"."Locale" != \'%s\'', $baseDataClass, $this->owner->Locale);
|
||||
}
|
||||
$currentStage = Versioned::current_stage();
|
||||
$joinOnClause = sprintf('"%s_translationgroups"."OriginalID" = "%s"."ID"', $baseDataClass, $baseDataClass);
|
||||
if($this->owner->hasExtension("Versioned")) {
|
||||
if($stage) Versioned::reading_stage($stage);
|
||||
if($this->owner->hasExtension("Versioned") && $stage) {
|
||||
$translations = Versioned::get_by_stage(
|
||||
$baseDataClass,
|
||||
Versioned::current_stage(),
|
||||
$stage,
|
||||
$filter,
|
||||
null
|
||||
)->leftJoin("{$baseDataClass}_translationgroups", $joinOnClause);
|
||||
if($stage) Versioned::reading_stage($currentStage);
|
||||
} else {
|
||||
$class = $this->owner->class;
|
||||
$translations = $baseDataClass::get()
|
||||
$translations = DataObject::get($baseDataClass)
|
||||
->where($filter)
|
||||
->leftJoin("{$baseDataClass}_translationgroups", $joinOnClause);
|
||||
}
|
||||
|
@ -1483,6 +1473,11 @@ class Translatable extends DataExtension implements PermissionProvider {
|
|||
$urlSegment = $newTranslation->URLSegment;
|
||||
}
|
||||
|
||||
if (URLSegmentFilter::singleton()->getAllowMultibyte()) {
|
||||
// Decode the URL segment, it will be re-encoded again on write
|
||||
$urlSegment = rawurldecode($urlSegment);
|
||||
}
|
||||
|
||||
// Only make segment unique if it should be enforced
|
||||
if(Config::inst()->get('Translatable', 'enforce_global_unique_urls')) {
|
||||
$newTranslation->URLSegment = $urlSegment . '-' . i18n::convert_rfc1766($locale);
|
||||
|
@ -1591,6 +1586,22 @@ class Translatable extends DataExtension implements PermissionProvider {
|
|||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Added to comply with current Google recommendations
|
||||
// If no translations found for this page, add a self referencing hreflang tag so Google does not complain
|
||||
// Language and Local tag
|
||||
$tags .= sprintf($template,
|
||||
Convert::raw2xml($this->owner->Title),
|
||||
i18n::convert_rfc1766($this->owner->Locale),
|
||||
$this->owner->AbsoluteLink()
|
||||
);
|
||||
// Language only tag
|
||||
$tags .= sprintf($template,
|
||||
Convert::raw2xml($this->owner->Title),
|
||||
i18n::get_lang_from_locale($this->owner->Locale),
|
||||
$this->owner->AbsoluteLink()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function providePermissions() {
|
||||
|
|
|
@ -1,44 +1,39 @@
|
|||
{
|
||||
"name": "silverstripe/translatable",
|
||||
"type": "silverstripe-module",
|
||||
"description": "Allows translation of DataObject and SiteTree records into multiple languages ",
|
||||
"keywords": [
|
||||
"silverstripe",
|
||||
"cms",
|
||||
"i18n",
|
||||
"localization",
|
||||
"globalization"
|
||||
],
|
||||
"license": "BSD-3-Clause",
|
||||
"homepage": "https://github.com/silverstripe/silverstripe-translatable/",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ingo Schommer",
|
||||
"homepage": "http://chillu.com",
|
||||
"email": "ingo@silverstripe.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.2",
|
||||
"silverstripe/framework": "~3.2",
|
||||
"silverstripe/cms": "~3.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"silverstripe/postgresql": "*",
|
||||
"silverstripe/sqlite3": "*",
|
||||
"silverstripe/mssql": "*",
|
||||
"phpunit/PHPUnit": "~3.7@stable"
|
||||
},
|
||||
"extra": {
|
||||
"screenshots": [
|
||||
"http://www.silverstripe.org/assets/Uploads/translatable4-small.png"
|
||||
],
|
||||
"branch-alias": {
|
||||
"2.x-dev": "2.2.x-dev"
|
||||
}
|
||||
},
|
||||
"support": {
|
||||
"issues": "https://github.com/silverstripe/silverstripe-translatable/issues?state=open"
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
"name": "silverstripe/translatable",
|
||||
"type": "silverstripe-module",
|
||||
"description": "Allows translation of DataObject and SiteTree records into multiple languages ",
|
||||
"keywords": [
|
||||
"silverstripe",
|
||||
"cms",
|
||||
"i18n",
|
||||
"localization",
|
||||
"globalization"
|
||||
],
|
||||
"license": "BSD-3-Clause",
|
||||
"homepage": "https://github.com/silverstripe/silverstripe-translatable/",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ingo Schommer",
|
||||
"homepage": "http://chillu.com",
|
||||
"email": "ingo@silverstripe.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.2",
|
||||
"silverstripe/framework": "~3.2",
|
||||
"silverstripe/cms": "~3.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^5.7",
|
||||
"squizlabs/php_codesniffer": "^3.0"
|
||||
},
|
||||
"extra": {
|
||||
"screenshots": [
|
||||
"http://www.silverstripe.org/assets/Uploads/translatable4-small.png"
|
||||
]
|
||||
},
|
||||
"support": {
|
||||
"issues": "https://github.com/silverstripe/silverstripe-translatable/issues?state=open"
|
||||
},
|
||||
"minimum-stability": "dev"
|
||||
}
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
The SilverStripe Translatable module allows you to create and edit multiple pages in various languages. This module also adds the ability for your users to select which language of a page they wish to view.
|
||||
|
||||
<div class="note" markdown="1">
|
||||
[note]
|
||||
Notes:
|
||||
|
||||
The SilverStripe Translatable module does not translate content automatically, content authors will need to enter the translated content manually for each translated page.
|
||||
</div>
|
||||
[/note]
|
||||
|
||||
To begin translating content select a page in your site tree from the "Pages" admin. You can see in the below image:
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
---
|
||||
title: Working with translations
|
||||
summary: Adding translated content to your website.
|
||||
---
|
||||
|
||||
# Working with translations
|
||||
|
||||
|
|
|
@ -459,7 +459,32 @@ class TranslatableTest extends FunctionalTest {
|
|||
Config::inst()->update('Translatable', 'enforce_global_unique_urls', true);
|
||||
Translatable::set_current_locale('en_US');
|
||||
}
|
||||
|
||||
|
||||
public function testMultibyteUrlsWorkWhenTranslated()
|
||||
{
|
||||
Config::inst()->update('URLSegmentFilter', 'default_allow_multibyte', true);
|
||||
|
||||
$page = new Page();
|
||||
$page->URLSegment = 'schön-döner';
|
||||
$page->Content = 'Kebabs in Berlin are amazing.';
|
||||
$page->write();
|
||||
$page->doPublish();
|
||||
|
||||
$translatedPage = $page->createTranslation('de_DE');
|
||||
$translatedPage->Content = 'Döner in Berlin sind unglaublich';
|
||||
$translatedPage->doPublish();
|
||||
$this->assertSame('schön-döner-de-de', rawurldecode($translatedPage->URLSegment));
|
||||
|
||||
// Test pinging the page on the frontend
|
||||
$pageResult = $this->get('schön-döner');
|
||||
$this->assertEquals(200, $pageResult->getStatusCode());
|
||||
$this->assertContains('Kebabs in Berlin', (string) $pageResult->getBody());
|
||||
|
||||
$translatedPageResult = $this->get('schön-döner-de-de');
|
||||
$this->assertEquals(200, $translatedPageResult->getStatusCode());
|
||||
$this->assertContains('Döner in Berlin', (string) $translatedPageResult->getBody());
|
||||
}
|
||||
|
||||
function testUpdateCMSFieldsOnSiteTree() {
|
||||
$pageOrigLang = new TranslatableTest_Page();
|
||||
$pageOrigLang->write();
|
||||
|
|
Loading…
Reference in New Issue