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

Commitf05d4e4

Browse files
Stadlyfabpot
authored andcommitted
[Translator] Set sources when extracting strings from php files
1 parent446480e commitf05d4e4

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

‎src/Symfony/Component/Translation/Extractor/PhpExtractor.php‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function extract($resource, MessageCatalogue $catalog)
8181
{
8282
$files =$this->extractFiles($resource);
8383
foreach ($filesas$file) {
84-
$this->parseTokens(token_get_all(file_get_contents($file)),$catalog);
84+
$this->parseTokens(token_get_all(file_get_contents($file)),$catalog,$file);
8585

8686
gc_mem_caches();
8787
}
@@ -197,9 +197,15 @@ private function getValue(\Iterator $tokenIterator)
197197
*
198198
* @param array $tokens
199199
* @param MessageCatalogue $catalog
200+
* @param string $filename
200201
*/
201-
protectedfunctionparseTokens($tokens,MessageCatalogue$catalog)
202+
protectedfunctionparseTokens($tokens,MessageCatalogue$catalog/*, string $filename*/)
202203
{
204+
if (\func_num_args() <3 &&__CLASS__ !==\get_class($this) &&__CLASS__ !== (new \ReflectionMethod($this,__FUNCTION__))->getDeclaringClass()->getName() && !$thisinstanceof \PHPUnit\Framework\MockObject\MockObject && !$thisinstanceof \Prophecy\Prophecy\ProphecySubjectInterface) {
205+
@trigger_error(sprintf('The "%s()" method will have a new "string $filename" argument in version 5.0, not defining it is deprecated since Symfony 4.3.',__METHOD__),E_USER_DEPRECATED);
206+
}
207+
$filename =2 <\func_num_args() ?\func_get_arg(2) :'';
208+
203209
$tokenIterator =new \ArrayIterator($tokens);
204210

205211
for ($key =0;$key <$tokenIterator->count(); ++$key) {
@@ -236,6 +242,10 @@ protected function parseTokens($tokens, MessageCatalogue $catalog)
236242

237243
if ($message) {
238244
$catalog->set($message,$this->prefix.$message,$domain);
245+
$metadata =$catalog->getMetadata($message,$domain) ?? [];
246+
$normalizedFilename =preg_replace('{[\\\\/]+}','/',$filename);
247+
$metadata['sources'][] =$normalizedFilename.':'.$tokens[$key][2];
248+
$catalog->setMetadata($message,$metadata,$domain);
239249
break;
240250
}
241251
}

‎src/Symfony/Component/Translation/Tests/Extractor/PhpExtractorTest.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public function testExtraction($resource)
6969
$actualCatalogue =$catalogue->all();
7070

7171
$this->assertEquals($expectedCatalogue,$actualCatalogue);
72+
73+
$filename =__DIR__.'/../fixtures/extractor/translation.html.php';
74+
$this->assertEquals(['sources' => [$filename.':2']],$catalogue->getMetadata('single-quoted key'));
75+
$this->assertEquals(['sources' => [$filename.':43']],$catalogue->getMetadata('other-domain-test-no-params-short-array','not_messages'));
7276
}
7377

7478
publicfunctionresourcesProvider()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp