Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FrameworkBundle][Translation] allow register custom resources paths. #14399

Closed
wants to merge 1 commit into from

Conversation

aitboudad
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Fixed tickets #971
Tests pass? yes
License MIT

This allow to add custom resources path via prepend config or in config.yml

framework:
    translator:
        paths:
            - %kernel.root_dir%/../vendor/Symfony/Component/Form/Resources/translations

->children()
->arrayNode('fallbacks')
->beforeNormalization()->ifString()->then(function ($v) { return array($v); })->end()
->prototype('scalar')->end()
->defaultValue(array('en'))
->end()
->arrayNode('paths')
->beforeNormalization()->ifString()->then(function ($v) { return array($v); })->end()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it really needed ?

foreach ($config['paths'] as $path) {
if (is_dir($path)) {
$dirs[] = $path;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really a good idea to silently ignore values not representing an array? This would make debugging a bit harder I guess. What about doing validation in the Configuration class instead and providing a meaningful error message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not possible to add validation it in the Configuration because we need to resolve parameters before checking directories, so I'll throw an exception here instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, that could still become an issue if a parameter were changed in a compiler pass, couldn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's true, is it safe to move it into TranslatorPass ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TranslatorPass is executed before the optimization passes (in which parameters are resolved). To be on the safe side, the compiler pass must be registered as a PassConfig::TYPE_BEFORE_REMOVING pass.

@aitboudad
Copy link
Contributor Author

what do you think about adding priority[-255|+255] flag to allow to change the loading order of message files.

paths:
    -  { priority: 125, path: ../Resources/translations} # defaul is -10
  • 125 : the app/Resources/translations directory;
  • 10: the app/Resources/BundleName/translations directory;
  • 0: the Resources/translations/ directory inside of any bundle.

@aitboudad
Copy link
Contributor Author

are you agree with adding priority ?

@aitboudad
Copy link
Contributor Author

closed in favor of #14561.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants