Giter VIP home page Giter VIP logo

symfony-db-i18n-bundle's Introduction

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 a getCatalogue 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.

symfony-db-i18n-bundle's People

Contributors

andrew72ru avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

symfony-db-i18n-bundle's Issues

How do you handle cache?

Hello, if I remember correctly - if you use Loader and you change the translation - you need to refresh cache. How do you handle that?

Allow ramsey/uuid v4

Currently the bundle can't be installed with the latest version of the ramsey/uuid library. I don't think this bundle directly requires the library, so I propose removing it from composer.json.

Uncompatible with doctrine/doctrine-bundle ^2.0

During composer installation on Symfony 4.4 and doctrine/doctrine-bundle 2.0.7 (in my case), the package throws:

Using version ^0.2.3 for creative/symfony-db-i18n-bundle
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Restricting packages listed in "symfony/symfony" to "4.4.*"
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for creative/symfony-db-i18n-bundle ^0.2.3 -> satisfiable by creative/symfony-db-i18n-bundle[v0.2.3].
    - Conclusion: remove doctrine/doctrine-bundle 2.0.7
    - Conclusion: don't install doctrine/doctrine-bundle 2.0.7
    - creative/symfony-db-i18n-bundle v0.2.3 requires doctrine/doctrine-bundle ^1.8 -> satisfiable by doctrine/doctrine-bundle[1.10.0, 1.10.1, 1.10.2, 1.10.3, 1.11.0, 1.11.1, 1.11.2, 1.12.0, 1.12.1, 1.12.2, 1.12.3, 1.12.4, 1.12.5, 1.12.6, 1.12.7, 1.8.0, 1.8.1, 1.9.0, 1.9.1].
    - Can only install one of: doctrine/doctrine-bundle[1.10.0, 2.0.7].
    - Can only install one of: doctrine/doctrine-bundle[1.10.1, 2.0.7].
    - Can only install one of: doctrine/doctrine-bundle[1.10.2, 2.0.7].
    - Can only install one of: doctrine/doctrine-bundle[1.10.3, 2.0.7].
    - Can only install one of: doctrine/doctrine-bundle[1.11.0, 2.0.7].
    - Can only install one of: doctrine/doctrine-bundle[1.11.1, 2.0.7].
    - Can only install one of: doctrine/doctrine-bundle[1.11.2, 2.0.7].
    - Can only install one of: doctrine/doctrine-bundle[1.12.0, 2.0.7].
    - Can only install one of: doctrine/doctrine-bundle[1.12.1, 2.0.7].
    - Can only install one of: doctrine/doctrine-bundle[1.12.2, 2.0.7].
    - Can only install one of: doctrine/doctrine-bundle[1.12.3, 2.0.7].
    - Can only install one of: doctrine/doctrine-bundle[1.12.4, 2.0.7].
    - Can only install one of: doctrine/doctrine-bundle[1.12.5, 2.0.7].
    - Can only install one of: doctrine/doctrine-bundle[1.12.6, 2.0.7].
    - Can only install one of: doctrine/doctrine-bundle[1.12.7, 2.0.7].
    - Can only install one of: doctrine/doctrine-bundle[1.8.0, 2.0.7].
    - Can only install one of: doctrine/doctrine-bundle[1.8.1, 2.0.7].
    - Can only install one of: doctrine/doctrine-bundle[1.9.0, 2.0.7].
    - Can only install one of: doctrine/doctrine-bundle[1.9.1, 2.0.7].
    - Installation request for doctrine/doctrine-bundle (locked at 2.0.7) -> satisfiable by doctrine/doctrine-bundle[2.0.7].


Installation failed, reverting ./composer.json to its original content.

Symfony 5.2 loader not loaded

On Symfony 5.2 the dev-master / v3 is not working.

It seems that the loading logic has changed.
Before on https://github.com/andrew72ru/symfony-db-i18n-bundle/blob/d28877b168e3ac10cd69cb6dadf0d6377262016d/src/DependencyInjection/DbI18nExtension.php#L38 there was the cache folder specified and it seems to work.

But now the cache:clear created catalogue.de.sxKOD8d.php.meta file doesnt contains the cache folder so no translations are load.

When I change it to the following it works.

$container->setParameter('db_i18n.translation_dir', $container->getParameter('kernel.project_dir') . '/translations');

Maybe there is another way to overwrite the path or injecting the loader directly into the translation system.

Latest Twig version support

In symfony 5 project, after running
composer require creative/symfony-db-i18n-bundle
there is an error of not supporting latest twig version.

`Using version ^0.3.0 for creative/symfony-db-i18n-bundle
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Restricting packages listed in "symfony/symfony" to "5.1.*"
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for creative/symfony-db-i18n-bundle ^0.3.0 -> satisfiable by creative/symfony-db-i18n-bundle[v0.3.0].
- Conclusion: remove twig/twig v3.0.3
- Conclusion: don't install twig/twig v3.0.3
- creative/symfony-db-i18n-bundle v0.3.0 requires twig/twig ^2.4 -> satisfiable by twig/twig[v2.10.0, v2.11.0, v2.11.1, v2.11.2, v2.11.3, v2.12.0, v2.12.1, v2.12.2, v2.12.3, v2.12.4, v2.12.5, v2.13.0, v2.13.1, v2.4.0, v2.4.1, v2.4.2, v2.4.3, v2.4.4, v2.4.5, v2.4.6, v2.4.7, v2.4.8, v2.5.0, v2.6.0, v2.6.1, v2.6.2, v2.7.0, v2.7.1, v2.7.2, v2.7.3, v2.7.4, v2.8.0, v2.8.1, v2.9.0].
- Can only install one of: twig/twig[v2.10.0, v3.0.3].
- Can only install one of: twig/twig[v2.11.0, v3.0.3].
- Can only install one of: twig/twig[v2.11.1, v3.0.3].
- Can only install one of: twig/twig[v2.11.2, v3.0.3].
- Can only install one of: twig/twig[v2.11.3, v3.0.3].
- Can only install one of: twig/twig[v2.12.0, v3.0.3].
- Can only install one of: twig/twig[v2.12.1, v3.0.3].
- Can only install one of: twig/twig[v2.12.2, v3.0.3].
- Can only install one of: twig/twig[v2.12.3, v3.0.3].
- Can only install one of: twig/twig[v2.12.4, v3.0.3].
- Can only install one of: twig/twig[v2.12.5, v3.0.3].
- Can only install one of: twig/twig[v2.13.0, v3.0.3].
- Can only install one of: twig/twig[v2.13.1, v3.0.3].
- Can only install one of: twig/twig[v2.4.0, v3.0.3].
- Can only install one of: twig/twig[v2.4.1, v3.0.3].
- Can only install one of: twig/twig[v2.4.2, v3.0.3].
- Can only install one of: twig/twig[v2.4.3, v3.0.3].
- Can only install one of: twig/twig[v2.4.4, v3.0.3].
- Can only install one of: twig/twig[v2.4.5, v3.0.3].
- Can only install one of: twig/twig[v2.4.6, v3.0.3].
- Can only install one of: twig/twig[v2.4.7, v3.0.3].
- Can only install one of: twig/twig[v2.4.8, v3.0.3].
- Can only install one of: twig/twig[v2.5.0, v3.0.3].
- Can only install one of: twig/twig[v2.6.0, v3.0.3].
- Can only install one of: twig/twig[v2.6.1, v3.0.3].
- Can only install one of: twig/twig[v2.6.2, v3.0.3].
- Can only install one of: twig/twig[v2.7.0, v3.0.3].
- Can only install one of: twig/twig[v2.7.1, v3.0.3].
- Can only install one of: twig/twig[v2.7.2, v3.0.3].
- Can only install one of: twig/twig[v2.7.3, v3.0.3].
- Can only install one of: twig/twig[v2.7.4, v3.0.3].
- Can only install one of: twig/twig[v2.8.0, v3.0.3].
- Can only install one of: twig/twig[v2.8.1, v3.0.3].
- Can only install one of: twig/twig[v2.9.0, v3.0.3].
- Installation request for twig/twig (locked at v3.0.3) -> satisfiable by twig/twig[v3.0.3].

Installation failed, reverting ./composer.json to its original content.`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.