Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd106aa3

Browse files
localheinzfabpot
authored andcommitted
[Translation] Allow using dashes in locale when linting Xliff files
1 parentaad1d09 commitd106aa3

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-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[] = [

‎src/Symfony/Component/Translation/Tests/Command/XliffLintCommandTest.php‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,17 @@ public function testLintTargetLanguageIsCaseInsensitive()
105105
$this->assertStringContainsString('[OK] All 1 XLIFF files contain valid syntax.',trim($tester->getDisplay()));
106106
}
107107

108+
publicfunctiontestLintSucceedsWhenLocaleInFileAndInTargetLanguageNameUsesDashesInsteadOfUnderscores()
109+
{
110+
$tester =$this->createCommandTester();
111+
$filename =$this->createFile('note','en-GB','messages.en-GB.xlf');
112+
113+
$tester->execute(['filename' =>$filename], ['decorated' =>false]);
114+
115+
$this->assertSame(0,$tester->getStatusCode());
116+
$this->assertStringContainsString('[OK] All 1 XLIFF files contain valid syntax.',trim($tester->getDisplay()));
117+
}
118+
108119
publicfunctiontestLintFileNotReadable()
109120
{
110121
$this->expectException(\RuntimeException::class);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp