kikwik / db-trans-bundle
Database translation loader with on-page translations edit for symfony 5
Installs: 36
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=7.2.5
- doctrine/doctrine-bundle: ^2.0
- symfony/console: ^5.3|^6.0
- symfony/form: ^5.3|^6.0
- symfony/framework-bundle: ^5.3|^6.0
- symfony/security-bundle: ^5.3|^6.0
- symfony/translation: ^5.3|^6.0
- symfony/twig-bundle: ^5.3|^6.0
README
Translation loader from database for symfony 5.
This bundle is inspired by the work of andrew72ru in creative/symfony-db-i18n-bundle
Installation
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require kikwik/db-trans-bundle
Update the database to create the translations tables:
$ php bin/console make:migration $ php bin/console doctrine:migrations:migrate
Configuration
Create the config/packages/kikwik_db_trans.yaml
config file and define the locales (and clear the cache)
kikwik_db_trans: locales: [ it, en ]
Import routes bundle in config/routes/kikwik_db_trans.yaml
:
kikwik_db_trans_bundle: resource: '@KikwikDbTransBundle/Resources/config/routes.xml' prefix: '/'
Run the kikwik:db-trans:import-messages
command to init the database translation and import messages from an existing catalogue with the domain as parameter:
$ ./bin/console kikwik:db-trans:import-messages myDomain
In the translation directory of the project will be created a file named db_myDomain.locale.db
for each enabled locale
Usage
You can use these twig translation functions:
db_trans
will display database translations.editable_db_trans
will display database translations for normal users, but:- if user has the
ROLE_TRANSLATOR
permission then the translation can be modified directly on the page (an icon will appear when the mouse is over the translation) - be ware that this function will surround the translated string with a span element.
- if user has the
For both functions parameters are same as trans twig filter:
- message
- arguments (optional)
- domain (optional)
- locale (optional)
Both functions will try to translate appending the domainPrefix so the {{ db_trans('some.mesage',{},'myDomain') }}
function will search for some.mesage
key in the db_myDomain
domain.
If this translation is not found it will fallback to the original domain translation (equivalent to {{ 'some.mesage'| trans({},'myDomain') }}
)