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

Skip to content

Commit 147627a

Browse files
committed
Fix: Allow using dashes for target language and locale in file name
1 parent 14edf83 commit 147627a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,16 @@ 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(
133+
'(%s|%s)',
134+
$targetLanguage,
135+
preg_quote(str_replace('-', '_', $targetLanguage), '/')
136+
);
133137
// strict file names require translation files to be named '____.locale.xlf'
134138
// otherwise, both '____.locale.xlf' and 'locale.____.xlf' are allowed
135139
// also, the regexp matching must be case-insensitive, as defined for 'target-language' values
136140
// 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);
141+
$expectedFilenamePattern = $this->requireStrictFileNames ? sprintf('/^.*\.(?i:%s)\.(?:xlf|xliff)/', $normalizedLocalePattern) : sprintf('/^(?:.*\.(?i:%s)|(?i:%s)\..*)\.(?:xlf|xliff)/', $normalizedLocalePattern, $normalizedLocalePattern);
138142

139143
if (0 === preg_match($expectedFilenamePattern, basename($file))) {
140144
$errors[] = [

0 commit comments

Comments
 (0)
0