creative / symfony-db-i18n-bundle
Allow store i18n-messages in database
Installs: 11 736
Dependents: 0
Suggesters: 0
Security: 0
Stars: 17
Watchers: 1
Forks: 11
Open Issues: 1
Type:symfony-bundle
Requires
- php: ^7.2||>=8.0
- doctrine/common: ^2.12|^3.1
- doctrine/doctrine-bundle: ^1.8|^2.0
- doctrine/orm: ^2.7
- doctrine/persistence: ^2
- ramsey/uuid: ^3.8|^4
- ramsey/uuid-doctrine: ^1.5
- symfony/config: ^4.1|^5
- symfony/dependency-injection: ^4.1|^5
- symfony/doctrine-bridge: ^4.1|^5
- symfony/finder: ^4.1|^5
- symfony/framework-bundle: ^4.1|^5
- symfony/polyfill-mbstring: *
- symfony/translation: ^4.1|^5
- symfony/twig-bridge: ^4.1|^5
- symfony/twig-bundle: ^4.1|^5
- symfony/yaml: ^4.1|^5
- twig/twig: ^2.4|^3
Requires (Dev)
- phpunit/phpunit: ^8.1
- symfony/console: ^4.1|^5
- symfony/css-selector: ^4.1|^5
- symfony/dom-crawler: ^4.1|^5
- symfony/phpunit-bridge: ^4.1|^5
- symfony/var-dumper: ^4.1|^5
This package is auto-updated.
Last update: 2024-10-20 12:56:59 UTC
README
Sometimes You have to give the visual interface of i18n message CRUD for a customer. To do this, You need to have storage, which is not under version control and allowed from a form.
I18n messages stored in database
With this bundle i18n messages stored in a database instead of files, then, you can implement web-interface to manage it.
Installation
composer require creative/symfony-db-i18n-bundle
Bundle has not (yet) a flex auto-configurator. Add
Creative\DbI18nBundle\DbI18nBundle::class => ['all' => true],
to you config/bundles.php
file, and (optional) place the db_i18n.yaml
with configuration (see below) file to your config directory.
Some rules:
- you application service container must have aa array
locales
parameter with possible application locales. For example:# config/services.yaml parameters: locales: [ 'ru', 'en', 'de' ]
- implementation of
Symfony\Contracts\Translation\TranslatorInterface
must have agetCatalogue
method (usually, it have) for import messages from translation files to database. - You must define the default messages domain as
db_messages
in you views to use messages from database. For example:# templates/main.html.twig {% trans_default_domain 'db_messages' %}
- update you database schema after install this bundle — use
bin/console doctrine:schema:update
command or make migration for this.
So, now you can load messages from old translation files to the database. Command
bin/console creative:db-i18n:migrate translations/messages.en.yaml
will import all messages from [project root]/translations/messages.en.yaml
. You can set absolute path instead, nevermind, but file name must be compatible with Symfony localization files agreement — <domain>.<locale>.<format>
.
After (or instead of) that, make your forms/interfaces and add, change and so on with your messages.
Defaults
Default config is
# src/Resources/config/db_i18n.yaml db_i18n: entity: Creative\DbI18nBundle\Entity\Translation domain: db_messages
Copy this wherever you want and modify.
As you can see, the default messages domain is db_messages
. If you want to override this and store default Symfony domain messages
in a database, don't forget to remove (or rename) you translations/messages.<locale>.[yaml|csv|xlf]
file.