raffaelj/cockpit-babel

Manage translations of Cockpit CMS v1 and v2 modules

Installs: 28

Dependents: 2

Suggesters: 0

Security: 0

Stars: 2

Watchers: 1

Forks: 0

Open Issues: 2

Language:Hack

Type:cockpit-module

0.3.2 2023-02-05 10:44 UTC

This package is auto-updated.

Last update: 2024-12-10 16:02:18 UTC


README

Manage translations of Cockpit CMS v1, Cockpit CMS v2 modules and Multiplane themes with a graphical user interface.

Usage

  • Login as admin (or with manage rights for babel)
  • Go to "Settings" --> "Babel"
  • If you use Cockpit CMS v1
    • Click on "Other" tab
    • Click on "Restructure i18n files" button. Now the Babel addon is initialized and the file/folder structure is adapted to new locations.
  • Translate strings and click the "Save" button

Config

<?php
return [
    'app.name' => 'My app',

    // set entry level languages in cockpit cms v1
    // use the gui instead to change locales in cockpit cms v2
    'i18n' => 'de',
    'languages' => [
        'default' => 'Deutsch',
        'fr' => 'Francais',
    ],

    // set admin ui languages
    'babel' => [
        'languages' => [
            'de' => 'Deutsch',
            'fr' => 'Francais',
        ],
    ],
];

Requirements

  • PHP >= 7.4

Concepts

Cockpit CMS v1

File/folder structure:

  • config/cockpit/i18n/{locale}.php
    • must exist for user language selection
  • wysiwyg field (tinymce): #pstorage:assets/cockpit/i18n/tinymce/{locale}.js
.
├── config
|   ├── cockpit
|   |   └── i18n
|   |       ├── de.php (must exist)
|   |       └── fr.php (must exist)
|   └── config.php
├── storage
|   └── assets
|       └── cockpit
|           └── i18n
|               └── tinymce
|                   ├── de.js
|                   └── fr.js

Cockpit CMS v2

File/folder structure:

  • config/i18n/App/{locale}.php
    • must exist for user language selection
    • must exist to load other module i18n files
  • wysiwyg field (tinymce): should be translatable via App.on('field-wysiwyg-init', function(opts) {opts.language_url = 'path/to/tinymce/locale.js';}); (not tested)
.
├── config
|   ├── i18n
|   |   ├── App
|   |   |   ├── de.php (must exist)
|   |   |   └── fr.php (must exist)
|   |   └── {module}
|   |       ├── de.php
|   |       └── fr.php
|   └── config.php
├── path/to/tinymce/{locale}.js (not tested)

Babel addon

I like the new folder structure of Cockpit v2 and adapted it in this addon.

File/folder structure:

.
├── config
|   ├── i18n
|   |   ├── {module}
|   |   |   ├── de.php
|   |   |   └── fr.php
|   |   ├── de.php (must exist - @meta and unassigned strings)
|   |   └── fr.php (must exist - @meta and unassigned strings)
|   └── config.php
├── storage/assets/cockpit/i18n/tinymce/{locale.js} (not automated, yet)

Installation

Copy this repository into /addons and name it Babel or use the cli.

via git

cd path/to/cockpit
git clone https://github.com/raffaelj/cockpit_Babel.git addons/Babel

via cp cli (Cockpit CMS v1)

cd path/to/cockpit
./cp install/addon --name Babel --url https://github.com/raffaelj/cockpit_Babel/archive/main.zip

via composer (Cockpit CMS v1)

Make sure, that the path to cockpit addons is defined in your projects' composer.json file.

{
    "name": "my/cockpit-project",
    "extra": {
        "installer-paths": {
            "addons/{$name}": ["type:cockpit-module"]
        }
    }
}
cd path/to/cockpit-root
composer create-project --ignore-platform-reqs aheinze/cockpit .
composer config extra.installer-paths.addons/{\$name} "type:cockpit-module"

composer require --ignore-platform-reqs raffaelj/cockpit-babel

Copyright and License

Copyright 2022 Raffael Jesche under the MIT license.

See LICENSE for more information.