10000 Fix: Allow using dashes for target language and locale in file name · symfony/symfony@b3c8c14 · GitHub
[go: up one dir, main page]

Skip to content

Commit b3c8c14

Browse files
committed
Fix: Allow using dashes for target language and locale in file name
1 parent 7bfb693 commit b3c8c14

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Symfony/Component/Translation/Command/XliffLintCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ private function validate(string $content, string $file = null): array
129129
$document->loadXML($content);
130130

131131
if (null !== $targetLanguage = $this->getTargetLanguageFromFile($document)) {
132-
$normalizedLocale = preg_quote(str_replace('-', '_', $targetLanguage), '/');
132+
$normalizedLocalePattern = sprintf('(%s|%s)',preg_quote($targetLanguage, '/'), preg_quote(str_replace('-', '_', $targetLanguage), '/'));
133133
// strict file names require translation files to be named '____.locale.xlf'
134134
// otherwise, both '____.locale.xlf' and 'locale.____.xlf' are allowed
135135
// also, the regexp matching must be case-insensitive, as defined for 'target-language' values
136136
// http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html#target-language
137-
$expectedFilenamePattern = $this->requireStrictFileNames ? sprintf('/^.*\.(?i:%s)\.(?:xlf|xliff)/', $normalizedLocale) : sprintf('/^(?:.*\.(?i:%s)|(?i:%s)\..*)\.(?:xlf|xliff)/', $normalizedLocale, $normalizedLocale);
137+
$expectedFilenamePattern = $this->requireStrictFileNames ? sprintf('/^.*\.(?i:%s)\.(?:xlf|xliff)/', $normalizedLocalePattern) : sprintf('/^(?:.*\.(?i:%s)|(?i:%s)\..*)\.(?:xlf|xliff)/', $normalizedLocalePattern, $normalizedLocalePattern);
138138

139139
if (0 === preg_match($expectedFilenamePattern, basename($file))) {
140140
$errors[] = [

0 commit comments

Comments
 (0)
0