This plugins adds a control panel interface for your clients to edit your static translations for each language side by side.
-
Add, edit or delete translations in the Control Panel with each language side by side.
-
Choose a category, filter by missing translations, search by keywords and sort by key/date.
-
Export all or a subset of your translations to a CSV file and import it back after translators worked on it.
-
Translations will be kept inside your database instead of PHP files for a better workflow.
-
Optionally, missing translations are automatically added to the database when a page is visited.
-
Ability to parse your twig templates or migrate from your existing PHP translations (and export it back to PHP files).
-
GraphQL support to query your translations.
This plugin requires Craft CMS 4.0.0 or later.
Install the plugin via the Plugin Store or by command line:
composer require mutation/translate
php craft install/plugin translations-admin
You can now edit your translations in the control panel /admin/translations-admin
.
You have special permissions for the Translations admin plugin:
- Save translations
- Add translations
- Delete translations
- Update translations
- Export translations
- Import translations
- Use translations utilities
- Change translations settings
You can either go the settings page or create a file translations-admin.php
in your config
directory.
- Plugin Name: How the plugin should be named in the CP
- Categories: Choose the source message categories you want to have in your database and control panel.
- Add missing translations: Controls whether missing translations are automatically added to the database when a page is visited.
- Add missing translations for site request only: Controls whether missing translations are only added when the request is from the site.
Config file example:
<?php
return [
'pluginName' => 'Translations',
'categories' => [
['category' => 'site'],
['category' => 'app']
],
'addMissingTranslations' => false,
'addMissingSiteRequestOnly' => false
];
Query static messages this way:
{
staticMessages(language:["en-CA", "fr-CA"], category: ["site", "app"]) {
key
message
language
category
dateCreated
}
}
You can use these custom events in your plugin or module to do any actions after translations are added, saved or deleted (example: empty the cache):
use mutation\translate\services\MessagesService;
Event::on(MessagesService::class, MessagesService::EVENT_AFTER_SAVE_MESSAGES, function (Event $e) { ... });
Event::on(MessagesService::class, MessagesService::EVENT_AFTER_ADD_MESSAGE, function (Event $e) { ... });
Event::on(MessagesService::class, MessagesService::EVENT_AFTER_DELETE_MESSAGES, function (Event $e) { ... });