diff --git a/app/Models/Page.php b/app/Models/Page.php index 7d53c08..9ed2493 100644 --- a/app/Models/Page.php +++ b/app/Models/Page.php @@ -5,10 +5,12 @@ namespace App\Models; use App\Models\ModelTrait; use App\Models\User; use Illuminate\Database\Eloquent\Model; +use Dimsav\Translatable\Translatable; class Page extends Model { use ModelTrait; + use Translatable; /** * The database table used by the model. * @@ -16,6 +18,8 @@ class Page extends Model */ protected $table; + public $translatedAttributes = ['title', 'description']; + /** * The guarded field which are not mass assignable. * @@ -40,6 +44,7 @@ class Page extends Model { parent::__construct($attributes); $this->table = 'pages'; //config('module.pages.table'); + // $this->defaultLocale = 'de'; } public function owner() diff --git a/app/Models/PageTranslation.php b/app/Models/PageTranslation.php new file mode 100644 index 0000000..b5e6316 --- /dev/null +++ b/app/Models/PageTranslation.php @@ -0,0 +1,13 @@ +=5.4.0" + }, + "require-dev": { + "orchestra/testbench": "3.5.*", + "phpunit/phpunit": "~6.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Dimsav\\Translatable\\TranslatableServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Dimsav\\Translatable\\": "src/Translatable/" + }, + "classmap": [ + "tests" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Dimitrios Savvopoulos", + "email": "ds@dimsav.com", + "homepage": "http://dimsav.com" + } + ], + "description": "A Laravel package for multilingual models", + "keywords": [ + "database", + "language", + "laravel", + "translation" + ], + "time": "2018-01-04T20:11:56+00:00" + }, { "name": "dnoegel/php-xdg-base-dir", "version": "0.1", @@ -1511,16 +1569,16 @@ }, { "name": "swiftmailer/swiftmailer", - "version": "v6.1.2", + "version": "v6.1.3", "source": { "type": "git", "url": "https://github.com/swiftmailer/swiftmailer.git", - "reference": "7d760881d266d63c5e7a1155cbcf2ac656a31ca8" + "reference": "8ddcb66ac10c392d3beb54829eef8ac1438595f4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/7d760881d266d63c5e7a1155cbcf2ac656a31ca8", - "reference": "7d760881d266d63c5e7a1155cbcf2ac656a31ca8", + "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/8ddcb66ac10c392d3beb54829eef8ac1438595f4", + "reference": "8ddcb66ac10c392d3beb54829eef8ac1438595f4", "shasum": "" }, "require": { @@ -1566,7 +1624,7 @@ "mail", "mailer" ], - "time": "2018-07-13T07:04:35+00:00" + "time": "2018-09-11T07:12:52+00:00" }, { "name": "symfony/console", diff --git a/config/translatable.php b/config/translatable.php new file mode 100644 index 0000000..3c7b7ab --- /dev/null +++ b/config/translatable.php @@ -0,0 +1,117 @@ + [ + 'en', + 'de', + 'fr', + 'es' => [ + 'MX', // mexican spanish + 'CO', // colombian spanish + ], + ], + + /* + |-------------------------------------------------------------------------- + | Locale separator + |-------------------------------------------------------------------------- + | + | This is a string used to glue the language and the country when defining + | the available locales. Example: if set to '-', then the locale for + | colombian spanish will be saved as 'es-CO' into the database. + | + */ + 'locale_separator' => '-', + + /* + |-------------------------------------------------------------------------- + | Default locale + |-------------------------------------------------------------------------- + | + | As a default locale, Translatable takes the locale of Laravel's + | translator. If for some reason you want to override this, + | you can specify what default should be used here. + | + */ + 'locale' => null, + + /* + |-------------------------------------------------------------------------- + | Use fallback + |-------------------------------------------------------------------------- + | + | Determine if fallback locales are returned by default or not. To add + | more flexibility and configure this option per "translatable" + | instance, this value will be overridden by the property + | $useTranslationFallback when defined + | + */ + 'use_fallback' => false, + + /* + |-------------------------------------------------------------------------- + | Use fallback per property + |-------------------------------------------------------------------------- + | + | The property fallback feature will return the translated value of + | the fallback locale if the property is empty for the selected + | locale. Note that 'use_fallback' must be enabled. + | + */ + 'use_property_fallback' => true, + + /* + |-------------------------------------------------------------------------- + | Fallback Locale + |-------------------------------------------------------------------------- + | + | A fallback locale is the locale being used to return a translation + | when the requested translation is not existing. To disable it + | set it to false. + | + */ + 'fallback_locale' => 'en', + + /* + |-------------------------------------------------------------------------- + | Translation Suffix + |-------------------------------------------------------------------------- + | + | Defines the default 'Translation' class suffix. For example, if + | you want to use CountryTrans instead of CountryTranslation + | application, set this to 'Trans'. + | + */ + 'translation_suffix' => 'Translation', + + /* + |-------------------------------------------------------------------------- + | Locale key + |-------------------------------------------------------------------------- + | + | Defines the 'locale' field name, which is used by the + | translation model. + | + */ + 'locale_key' => 'locale', + + /* + |-------------------------------------------------------------------------- + | Always load translations when converting to array + |-------------------------------------------------------------------------- + | Setting this to false will have a performance improvement but will + | not return the translations when using toArray(), unless the + | translations relationship is already loaded. + | + */ + 'to_array_always_loads_translations' => true, +]; diff --git a/database/migrations/translation/2018_09_13_075552_create_page_translations_table.php b/database/migrations/translation/2018_09_13_075552_create_page_translations_table.php new file mode 100644 index 0000000..fc528f5 --- /dev/null +++ b/database/migrations/translation/2018_09_13_075552_create_page_translations_table.php @@ -0,0 +1,38 @@ +increments('id'); + $table->integer('page_id')->unsigned(); + $table->string('locale')->index(); + + $table->string('title'); + $table->text('description'); + + $table->unique(['page_id','locale']); + $table->foreign('page_id')->references('id')->on('pages')->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('page_translations'); + } +} diff --git a/resources/views/settings/layouts/app.blade.php b/resources/views/settings/layouts/app.blade.php index b606f5b..79c0bfe 100644 --- a/resources/views/settings/layouts/app.blade.php +++ b/resources/views/settings/layouts/app.blade.php @@ -134,7 +134,9 @@
-

Dashboard

+
+

Dashboard

+
-
+ {{--
{{ Form::label('language', 'Language..', ['class' => 'col-lg-2 control-label required']) }}
{{ Form::select('language', $languages, $page->language, ['placeholder' => '--no language--']) }}
-
+
--}}
{{ Form::label('cannonical_link', trans('validation.attributes.backend.pages.cannonical_link'), ['class' => 'col-lg-2 control-label']) }}