-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Translation] Added support for translation files with other filename patterns #27655
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
Conversation
$expectedFileExtension = sprintf('%s.xlf', str_replace('-', '_', $targetLanguage)); | ||
$realFileExtension = explode('.', basename($file), 2)[1] ?? ''; | ||
$normalizedLocale = str_replace('-', '_', $targetLanguage); | ||
$expectedFilenamePattern = sprintf('/^(.*\.%s\.xlf|%s\..*\.xlf)/', $normalizedLocale, $normalizedLocale); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing preg_quote
on the 2 variables you inject in the regex
In a FrameworkBundle-based project, the file name format must always be |
@stof I've made some changes. Please tell me if that's what you were proposing. Thanks. |
$realFileExtension = explode('.', basename($file), 2)[1] ?? ''; | ||
$normalizedLocale = preg_quote(str_replace('-', '_', $targetLanguage)); | ||
// when this command is used inside Symfony, require filenames to be '____.locale.xlf' | ||
// when used outside Symfony, allow '____.locale.xlf' and 'locale.____.xlf' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comments should be talking about strict vs not strict, not about inside Symfony
. Other projects may put the command in strict mode too.
|
||
public function __construct(string $name = null, callable $directoryIteratorProvider = null, callable $isReadableProvider = null) | ||
public function __construct(string $name = null, callable $directoryIteratorProvider = null, callable $isReadableProvider = null, bool $requireStrictFileNames = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we keep using true
as default, to keep the same behavior than today by default ?
@@ -115,14 +117,16 @@ private function validate($content, $file = null) | |||
$document->loadXML($content); | |||
|
|||
if (null !== $targetLanguage = $this->getTargetLanguageFromFile($document)) { | |||
$expectedFileExtension = sprintf('%s.xlf', str_replace('-', '_', $targetLanguage)); | |||
$realFileExtension = explode('.', basename($file), 2)[1] ?? ''; | |||
$normalizedLocale = preg_quote(str_replace('-', '_', $targetLanguage)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to pass the regex delimiter as second argument to preg_quote
as it needs to be escaped too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some more tests , especially when requireStrictFileNames
is false?
Thank you @javiereguiluz. |
… other filename patterns (javiereguiluz) This PR was squashed before being merged into the 4.2-dev branch (closes #27655). Discussion ---------- [Translation] Added support for translation files with other filename patterns | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #27644 | License | MIT | Doc PR | - This implements the #27644 feature request in case we accept it. My vote is 👍 because the changes required are tiny and the resulting code is even more robust thanks to the new `preg_match()` call. Commits ------- 0ee912d [Translation] Added support for translation files with other filename patterns
This implements the #27644 feature request in case we accept it.
My vote is 👍 because the changes required are tiny and the resulting code is even more robust thanks to the new
preg_match()
call.