Reputation: 830
I am transforming an old app into a new one using Symfony2.
A little part of the text was translated in the old app, where I used a personal library for translation.
The goal is: when the trans
filter or {% trans %}
block is called in Twig, I wish Symfony2 to check if translation exists. If it does, then it returns the right translation using user's locale. Nothing foreign here, this is how Symfony2 works.
But what I am facing is that my old library works a little bit better: if translation does not exists, then it writes it into a file for translation to be noticed to translators. I was using a little backoffice which we could see all missing translations, so the translators could work with a free mind, and as a developer, I could also develop and show text to be translated with a free mind, as I knew I wouldn't have to add the text myself into the translation file. And the people using the backoffice and adding text in the database could also work with a free mind, knowing that their texts will be automatically written into the files and the translators can see it in their interface.
I know that the Symfony2 console can dump all these translations for it to be written in some files, but there are two problems for me with this system:
trans
filter or block, and then write missing datas into the translation file). Then, when all the pages are loaded, I can expect all the text to be sent and written into the files.I really wish to find a solution for this.
Of course, I could implement my old library into Symfony2, and create my own twig translation filter (already done that) but it would be slightly better for me to use native Symfony2 system, or even install another bundle for that inside the vendors directory, as I don't want to handle development depending on bundles and so on (as translation is saved for each bundle).
Do you have a native solution for this? (if there is none, I'll give up and use my own library, but it's not gonna be as pretty as Symfony2 translation system)
I created my own library with a really simple system which is available on my Github page. It simply adds the translation into the files when the translation is not available.
However, I decided to make another library, inspired by this one, but relying on the database. The module is currently in development, but its system is simple:
It loads translation with the native translator, and if the translation is not available (i.e. the native translator returns an empty string), it loads all translations in the database, depending of the translation_domain value. Then, a service (launched either in a controller and command line tool) will write all database translations in files, for the native translator to load them faster, and for them to be stored in the SF2 cache.
Upvotes: 1
Views: 1547
Reputation: 830
⚠️ EDIT: The library I created was Orbitale/TranslationBundle and it had serious flaws, so I stopped maintaining it, and do not recommend using it. Instead, the Symfony translator must be overriden and you will have to deal with translation formats etc. by yourself.
For consistency and maintainability, I changed my expectations and accepted the native Symfony behavior (which is to use fallback locales, and if none has a translation, display the initial text).
Contact me if you'd like advices on how one could achieve this override.
Original answer:
Finally, thanks for helping.
I tried JMSTranslationBundle, and it was breaking all Symfony2's cache.
Finally, I decided to create my own library, and I put it on both Github and Packagist, you can find it on packagist.org it's named orbitale/translation-bundle.
It's brand new, so don't blame me if it's not complete ! :)
Upvotes: 2
Reputation: 1013
I think you may like https://github.com/schmittjoh/JMSTranslationBundle to achieve your goal. It even has the little backoffice thing you want.
Upvotes: 1