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

Commitaa21944

Browse files
committed
bug#40172 [Translation] Allow using dashes in locale when linting Xliff files (localheinz)
This PR was squashed before being merged into the 4.4 branch.Discussion----------[Translation] Allow using dashes in locale when linting Xliff files| Q | A| ------------- | ---| Branch? | 4.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Tickets |fixes#40170| License | MIT| Doc PR | n/aThis pull request* [x] asserts that the `XliffLintCommand` succeeds linting an Xliff file where both the the target language and the locale in the file name use dashes as separators* [x] adjusts the `XliffLintCommand` to allow using the same value for target language and locale in the corresponding file nameCommits-------d106aa3 [Translation] Allow using dashes in locale when linting Xliff files
2 parents4ee48c4 +d106aa3 commitaa21944

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