Skip to content

Commit

Permalink
Add support for using translate in specific connection (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
MortezaPoussaneh authored and William committed Nov 14, 2019
1 parent 37f5cd0 commit 7bedc0a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
10 changes: 10 additions & 0 deletions config/translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
*/
'source' => env('TRANSLATION_SOURCE', 'files'),

/*
|--------------------------------------------------------------------------
| Default Translation Connection
|--------------------------------------------------------------------------
|
| This option controls the translation's connection. By default is use Laravel default connection. In most cases
| you don't need to change it.
*/
'connection' => config('database.default', env('TRANSLATOR_CONNECTION', 'mysql')),

// In case the files source is selected, please enter here the supported locales for your app.
// Ex: ['en', 'es', 'fr']
'available_locales' => [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CreateLanguagesTable extends Migration
*/
public function up()
{
Schema::create('translator_languages', function ($table) {
Schema::connection(config('translator.connection'))->create('translator_languages', function ($table) {
$table->increments('id');
$table->string('locale', 6)->unique();
$table->string('name', 60)->unique();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CreateTranslationsTable extends Migration
*/
public function up()
{
Schema::create('translator_translations', function ($table) {
Schema::connection(config('translator.connection'))->create('translator_translations', function ($table) {
$table->increments('id');
$table->string('locale', 6);
$table->string('namespace')->default('*');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class IncreaseLocaleLength extends Migration
*/
public function up()
{
Schema::table('translator_languages', function ($table) {
Schema::connection(config('translator.connection'))->table('translator_languages', function ($table) {
$table->string('locale', 10)->change();
});
Schema::table('translator_translations', function ($table) {
Schema::connection(config('translator.connection'))->table('translator_translations', function ($table) {
$table->string('locale', 10)->change();
});
}
Expand Down
11 changes: 11 additions & 0 deletions src/Models/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ class Language extends Model
*/
protected $fillable = ['locale', 'name'];

/**
* Language constructor.
* @param array $attributes
*/
public function __construct(array $attributes = [])
{
parent::__construct($attributes);

$this->setConnection(config('translator.connection'));
}

/**
* Each language may have several translations.
*/
Expand Down
7 changes: 7 additions & 0 deletions src/Models/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ class Translation extends Model
*/
protected $fillable = ['locale', 'namespace', 'group', 'item', 'text', 'unstable'];

public function __construct(array $attributes = [])
{
parent::__construct($attributes);

$this->setConnection(config('translator.connection'));
}

/**
* Each translation belongs to a language.
*/
Expand Down

0 comments on commit 7bedc0a

Please sign in to comment.