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

Commit29f6749

Browse files
committed
[Translation] Store and show fallback locale
1 parent98d36d5 commit29f6749

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

‎src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/translation.html.twig‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
{%settext %}
1515
<divclass="sf-toolbar-info-piece">
16-
<b>Locale</b>
16+
<b>Default locale</b>
1717
<spanclass="sf-toolbar-status">
1818
{{collector.locale|default('-') }}
1919
</span>
@@ -73,7 +73,7 @@
7373
<divclass="metrics">
7474
<divclass="metric">
7575
<spanclass="value">{{collector.locale|default('-') }}</span>
76-
<spanclass="label">Locale</span>
76+
<spanclass="label">Default locale</span>
7777
</div>
7878
<divclass="metric">
7979
<spanclass="value">{{collector.fallbackLocales|join(',')|default('-') }}</span>
@@ -190,6 +190,7 @@
190190
<thead>
191191
<tr>
192192
<th>Locale</th>
193+
<th>Fallback locale</th>
193194
<th>Domain</th>
194195
<th>Times used</th>
195196
<th>Message ID</th>
@@ -200,6 +201,7 @@
200201
{%formessageinmessages %}
201202
<tr>
202203
<tdclass="font-normal text-small nowrap">{{message.locale }}</td>
204+
<tdclass="font-normal text-small nowrap">{{message.fallbackLocale|default('-') }}</td>
203205
<tdclass="font-normal text-small text-bold nowrap">{{message.domain }}</td>
204206
<tdclass="font-normal text-small nowrap">{{message.count }}</td>
205207
<td>

‎src/Symfony/Component/Translation/DataCollectorTranslator.php‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,27 @@ private function collectMessage($locale, $domain, $id, $translation, $parameters
145145
$id = (string)$id;
146146
$catalogue =$this->translator->getCatalogue($locale);
147147
$locale =$catalogue->getLocale();
148+
$fallbackLocale =null;
148149
if ($catalogue->defines($id,$domain)) {
149150
$state =self::MESSAGE_DEFINED;
150151
}elseif ($catalogue->has($id,$domain)) {
151152
$state =self::MESSAGE_EQUALS_FALLBACK;
153+
154+
$fallbackCatalogue =$catalogue->getFallbackCatalogue();
155+
while ($fallbackCatalogue) {
156+
if ($fallbackCatalogue->defines($id,$domain)) {
157+
$fallbackLocale =$fallbackCatalogue->getLocale();
158+
break;
159+
}
160+
$fallbackCatalogue =$fallbackCatalogue->getFallbackCatalogue();
161+
}
152162
}else {
153163
$state =self::MESSAGE_MISSING;
154164
}
155165

156166
$this->messages[] = [
157167
'locale' =>$locale,
168+
'fallbackLocale' =>$fallbackLocale,
158169
'domain' =>$domain,
159170
'id' =>$id,
160171
'translation' =>$translation,

‎src/Symfony/Component/Translation/Tests/DataCollectorTranslatorTest.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function testCollectMessages()
3434
'id' =>'foo',
3535
'translation' =>'foo (en)',
3636
'locale' =>'en',
37+
'fallbackLocale' =>'',
3738
'domain' =>'messages',
3839
'state' => DataCollectorTranslator::MESSAGE_DEFINED,
3940
'parameters' => [],
@@ -43,6 +44,7 @@ public function testCollectMessages()
4344
'id' =>'bar',
4445
'translation' =>'bar (fr)',
4546
'locale' =>'en',
47+
'fallbackLocale' =>'fr',
4648
'domain' =>'messages',
4749
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
4850
'parameters' => [],
@@ -52,6 +54,7 @@ public function testCollectMessages()
5254
'id' =>'choice',
5355
'translation' =>'choice',
5456
'locale' =>'en',
57+
'fallbackLocale' =>'',
5558
'domain' =>'messages',
5659
'state' => DataCollectorTranslator::MESSAGE_MISSING,
5760
'parameters' => [],
@@ -61,6 +64,7 @@ public function testCollectMessages()
6164
'id' =>'bar_ru',
6265
'translation' =>'bar (ru)',
6366
'locale' =>'en',
67+
'fallbackLocale' =>'ru',
6468
'domain' =>'messages',
6569
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
6670
'parameters' => [],
@@ -70,6 +74,7 @@ public function testCollectMessages()
7074
'id' =>'bar_ru',
7175
'translation' =>'bar (ru)',
7276
'locale' =>'en',
77+
'fallbackLocale' =>'ru',
7378
'domain' =>'messages',
7479
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
7580
'parameters' => ['foo' =>'bar'],

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp