Skip to content

duxabilii/craft3-translate

 
 

Repository files navigation

Translations admin plugin for Craft CMS

This plugins adds a control panel interface to edit your static translations in the database.

Screenshot

Features

  • Add, edit or delete translations in the Control Panel with each language side by side.

  • Filter missing translations and search by keywords.

  • Configure which translations categories you'll be able to edit.

  • Translations will be kept inside your database instead of PHP files.

  • When a page is visited on the site, missing translations will automatically be added.

  • Export your translations to a CSV file and import it back after handing it to your translation team.

  • GraphQL support to query static messages

  • Utilities:

    • Parse all site templates to add missing translations
    • Migrate your existing PHP translations to your database
    • Export all your database translations to PHP files
    • Delete all translations

Requirements

This plugin requires Craft CMS 4.0.0 or later.

Installation

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.

Permissions

You have special permissions for the Translations admin plugin:

  • Update translations
  • Export translations
  • Import translations
  • Use utilities
  • Change settings

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
];

GraphQL

Query static messages this way:

{
  staticMessages(language:["en-CA", "fr-CA"], category: ["site", "app"]) {
    key
    message
    language
    category
  }
}

Events

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) { ... });

Roadmap

  • Add mapping for the import and support more format (Excel)
  • Refresh/sync option for the translations overview
  • Allow overriding translations when importing from PHP files
  • Add events when adding, saving and deleting translations

About

Craft CMS plugin for static translations in CP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 57.1%
  • Vue 27.2%
  • JavaScript 7.9%
  • Twig 7.8%