8000 [Translation] Collect original locale in case of fallback translation · symfony/symfony@5564e14 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5564e14

Browse files
digilistfabpot
authored andcommitted
[Translation] Collect original locale in case of fallback translation
1 parent 2b0f2de commit 5564e14

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

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

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

1414
{% set text %}
1515
<div class="sf-toolbar-info-piece">
16-
<b>Locale</b>
16+
<b>Default locale</b>
1717
<span class="sf-toolbar-status">
1818
{{ collector.locale|default('-') }}
1919
</span>
@@ -73,7 +73,7 @@
7373
<div class="metrics">
7474
<div class="metric">
7575
<span class="value">{{ collector.locale|default('-') }}</span>
76-
<span class="label">Locale</span>
76+
<span class="label">Default locale</span>
7777
</div>
7878
<div class="metric">
7979
<span class="value">{{ collector.fallbackLocales|join(', ')|default('-') }}</span>
@@ -152,7 +152,7 @@
152152
</div>
153153
{% else %}
154154
{% block fallback_messages %}
155-
{{ helper.render_table(messages_fallback) }}
155+
{{ helper.render_table(messages_fallback, true) }}
156156
{% endblock %}
157157
{% endif %}
158158
</div>
@@ -185,11 +185,14 @@
185185

186186
{% endblock %}
187187

188-
{% macro render_table(messages) %}
188+
{% macro render_table(messages, is_fallback) %}
189189
<table>
190190
<thead>
191191
<tr>
192192
<th>Locale</th>
193+
{% if is_fallback %}
194+
<th>Fallback locale</th>
195+
{% endif %}
193196
<th>Domain</th>
194197
<th>Times used</th>
195198
<th>Message ID</th>
@@ -200,6 +203,9 @@
200203
{% for message in messages %}
201204
<tr>
202205
<td class="font-normal text-small nowrap">{{ message.locale }}</td>
206+
{% if is_fallback %}
207+
<td class="font-normal text-small nowrap">{{ message.fallbackLocale|default('-') }}</td>
208+
{% endif %}
203209
<td class="font-normal text-small text-bold nowrap">{{ message.domain }}</td>
204210
<td class="font-normal text-small nowrap">{{ message.count }}</td>
205211
<td>

src/Symfony/Component/Translation/DataCollectorTranslator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ 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)) {
@@ -153,10 +154,9 @@ private function collectMessage($locale, $domain, $id, $translation, $parameters
153154
$fallbackCatalogue = $catalogue->getFallbackCatalogue();
154155
while ($fallbackCatalogue) {
155156
if ($fallbackCatalogue->defines($id, $domain)) {
156-
$locale = $fallbackCatalogue->getLocale();
157+
$fallbackLocale = $fallbackCatalogue->getLocale();
157158
break;
158159
}
159-
160160
$fallbackCatalogue = $fallbackCatalogue->getFallbackCatalogue();
161161
}
162162
} else {
@@ -165,6 +165,7 @@ private function collectMessage($locale, $domain, $id, $translation, $parameters
165165

166166
$this->messages[] = [
167167
'locale' => $locale,
168+
'fallbackLocale' => $fallbackLocale,
168169
'domain' => $domain,
169170
'id' => $id,
170171
'translation' => $translation,

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

Lines changed: 8 additions & 3 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' => null,
3738
'domain' => 'messages',
3839
'state' => DataCollectorTranslator::MESSAGE_DEFINED,
3940
'parameters' => [],
@@ -42,7 +43,8 @@ public function testCollectMessages()
4243
$expectedMessages[] = [
4344
'id' => 'bar',
4445
'translation' => 'bar (fr)',
45-
'locale' => 'fr',
46+
'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' => null,
5558
'domain' => 'messages',
5659
'state' => DataCollectorTranslator::MESSAGE_MISSING,
5760
'parameters' => [],
@@ -60,7 +63,8 @@ public function testCollectMessages()
6063
$expectedMessages[] = [
6164
'id' => 'bar_ru',
6265
'translation' => 'bar (ru)',
63-
'locale' => 'ru',
66+
'locale' => 'en',
67+
'fallbackLocale' => 'ru',
6468
'domain' => 'messages',
6569
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
6670
'parameters' => [],
@@ -69,7 +73,8 @@ public function testCollectMessages()
6973
$expectedMessages[] = [
7074
'id' => 'bar_ru',
7175
'translation' => 'bar (ru)',
72-
'locale' => 'ru',
76+
'locale' => 'en',
77+
'fallbackLocale' => 'ru',
7378
'domain' => 'messages',
7479
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
7580
'parameters' => ['foo' => 'bar'],

0 commit comments

Comments
 (0)
1639
0