Skip to content

Commit

Permalink
Merge pull request #13542 from craftcms/feature/i18n-message-tables
Browse files Browse the repository at this point in the history
Basic support for DbMessageSource
  • Loading branch information
brandonkelly authored Aug 10, 2023
2 parents 63add36 + 13764a8 commit 9dd17cb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
### Administration
- Added the “Slug Translation Method” setting to entry types. ([#8962](https://github.com/craftcms/cms/discussions/8962), [#13291](https://github.com/craftcms/cms/pull/13291))
- Added the “Show the Status field” setting to entry types. ([#12837](https://github.com/craftcms/cms/discussions/12837), [#13265](https://github.com/craftcms/cms/pull/13265))
- Added the `setup/message-tables` command, which can be run to set the project up for database-stored static translations via [DbMessageSource](https://www.yiiframework.com/doc/api/2.0/yii-i18n-dbmessagesource). ([#13542](https://github.com/craftcms/cms/pull/13542))
- Entry types created via the `entrify/global-set` command now have “Show the Status field” disabled by default. ([#12837](https://github.com/craftcms/cms/discussions/12837))
- Added the `defaultCountryCode` config setting. ([#13478](https://github.com/craftcms/cms/discussions/13478))
- Custom element sources can now be configured to only appear for certain sites. ([#13344](https://github.com/craftcms/cms/discussions/13344))
Expand Down
32 changes: 32 additions & 0 deletions src/console/controllers/SetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use craft\helpers\StringHelper;
use craft\migrations\CreateDbCacheTable;
use craft\migrations\CreatePhpSessionTable;
use m150207_210500_i18n_init;
use PDOException;
use Seld\CliPrompt\CliPrompt;
use Throwable;
Expand Down Expand Up @@ -523,6 +524,37 @@ public function actionPhpSessionTable(): int
return ExitCode::OK;
}

/**
* Creates database tables for storing message translations. (EXPERIMENTAL!)
*
* @return int
* @since 4.5.0
*/
public function actionMessageTables(): int
{
$db = Craft::$app->getDb();
if ($db->tableExists('{{%source_message}}')) {
$this->stdout("The `source_message` table already exists.\n", Console::FG_YELLOW);
return ExitCode::OK;
}
if ($db->tableExists('{{%message}}')) {
$this->stdout("The `message` table already exists.\n", Console::FG_YELLOW);
return ExitCode::OK;
}

require Craft::getAlias('@vendor/yiisoft/yii2/i18n/migrations/m150207_210500_i18n_init.php');
/** @phpstan-ignore-next-line */
$migration = new m150207_210500_i18n_init();
/** @phpstan-ignore-next-line */
if ($migration->up() === false) {
$this->stderr("An error occurred while creating the `source_message` and `message` tables.\n", Console::FG_RED);
return ExitCode::UNSPECIFIED_ERROR;
}

$this->stdout("The `source_message` and `message` tables were created successfully.\n", Console::FG_GREEN);
return ExitCode::OK;
}

/**
* Creates a database table for storing DB caches.
*
Expand Down

0 comments on commit 9dd17cb

Please sign in to comment.