JMSTranslationBundle
JMSTranslationBundle copied to clipboard
Translations are not searched for in app/Resources/[BundleName]/translations
I dont know if retreiveDirs() in JMSTranslationBundle\Command\ResourcesListCommand.php is the only function that is used when selecting folders for comparing translation Catalogs but that function ignores valid path for overriden Resources in
app/Resources/[BundleName]/translations
The conditions that are used are valid only for translation files located in app/Resources/translations and src/Bundle/Resources/translations.
See symfony docs for paths here: http://symfony.com/doc/current/book/translation.html#translation-resource-file-names-and-locations
I am not sure how to get only the Bundle name ex. SonataAdminBundle not Sonata\AdminBundle using symfony framework, but if someone knows how this function (and any other that actually extracts and compares Catalogs) should include:
if (is_dir($dir = $this->getContainer()->getParameter('kernel.root_dir'). '/Resources/' . $bundleName . '/translations' )) {
$dirs[] = $dir;
}
Also taking $this->getContainer()->getParameter('kernel.root_dir')
out of function and using as variable will be good.
I think I have the same problem with FOSUserBundle - until the last extraction I had my messages being pulled directly from vendor-specific bundle translation dir. After extract, all messages are being pulled from app/Resources/translations, which does not contain the vendor-specifics.
Any idea how to solve this?
@pculka did you find a solution to your problem ?
Hello @sadortun , yes, solution was more or less simple The app/views/FOSUserBundle/* have the TranslationDomain set to FOSUserBundle and I moved the *_content.html.twig parts into my own bundle, whilst specifying this in the "parent" views and extracted the translations from there. Then the translations will be merged - my custom with FOSUserBundle ones - then it worked
I have added some code that will scan app/Resources
private function retrieveDirs()
{
// Discover translation directories
$dirs = array();
$rootDir = $this->getContainer()->getParameter('kernel.root_dir');
foreach ($this->getContainer()->getParameter('kernel.bundles') as $bundle) {
$reflection = new \ReflectionClass($bundle);
if (is_dir($dir = dirname($reflection->getFilename()).'/Resources/translations')) {
$dirs[] = $dir;
}
/** Scan app/Resources/[Bundle]/translation dir **/
$className = $reflection->getName();
$baseName = basename(dirname($className)); //ex. TwigBundle etc. (not SymfonyTwigBundle)
$bundleVendorNames = str_replace('\\' ,'',dirname($className)); //etc SonataAdminBundle (not AdminBundle see above)
$suspectedBundles = array($baseName, $bundleVendorNames);
foreach ($suspectedBundles as $appBundle) {
if (is_dir($dir = $rootDir . '/Resources/' . $appBundle . '/translations' )) {
$dirs[] = $dir;
}
}
/** END OF SCAN **/
}
if (is_dir($dir = $this->getContainer()->getParameter('kernel.root_dir').'/Resources/translations')) {
$dirs[] = $dir;
}
return $dirs;
}
It does seem to list directories that should be scanned, but the actual update procedure does not take them into account.
PS. I know that invoking translate:update without bundle name will update translation files in app
folder but in my case I use app
folder for application wide strings used in multiple bundles, it also allows me to overwrite some translation strings. If anyone has an idea how to incorporate app/Resources/[bundle]/translations files into update of specific bundle then I'd be glad to help in any way I can.
I know it was a long time ago you posted this issue. Do you still experiencing this? Or is it fixed in the latest version of the bundle?
Still having the problem: custom files in MyBundle/Resources/translations or app/Resources/MyBundle/translations are not taken into account when translations are extracted. I'm using version 1.3.1.
Conf:
jms_translation:
source_language: %locale.default%
locales: %locale.list%
configs:
mybundle:
dir: [%kernel.root_dir%, %kernel.root_dir%/../src]
output_dir: %kernel.root_dir%/Resources/translations
excluded_names: ["*TestCase.php", "*Test.php"]
excluded_dirs: [cache, data, logs]
extractors: [jms_i18n_routing]
output-format: xlf
keep: true
Command line:
php app/console translation:extract --config=mybundle
I tried with xlf and yml formats.
Thx to make this bundle live again ;-)
Up... is there a PR, or update about this issue ? Tks !