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

Commit650f179

Browse files
committed
bug#32925 [Translation] Collect original locale in case of fallback translation (digilist)
This PR was squashed before being merged into the 3.4 branch (closes#32925).Discussion----------[Translation] Collect original locale in case of fallback translationBefore, it collected the fallback locale that was used to translate a key. But this information is confusing, as it does not reveal which translation key is missing in the requested language.So I'd like to propose to track the "requested" locale instead, so that the Symfony profiler gives me the information in which locale the key is missing instead of which locale was used as a fallback.| Q | A| ------------- | ---| Branch? | 3.4| Bug fix? | yes| New feature? | no| BC breaks? | yes?| Deprecations? | no| Tests pass? | yes| Fixed tickets || License | MIT| Doc PR |In principle, this change is a BC break, but imho also a bug. It's really confusing when the Profiler tells you that it uses a translation fallback for an ID and locale that is actually translated. Took some debugging so recognize that this fallback came from another locale. If you think it's better to target 5.0, I'll update the PR.Commits-------5564e14 [Translation] Collect original locale in case of fallback translation
2 parents4b2019d +5564e14 commit650f179

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
{%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>
@@ -152,7 +152,7 @@
152152
</div>
153153
{%else %}
154154
{%blockfallback_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+
{%ifis_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
{%formessageinmessages %}
201204
<tr>
202205
<tdclass="font-normal text-small nowrap">{{message.locale }}</td>
206+
{%ifis_fallback %}
207+
<tdclass="font-normal text-small nowrap">{{message.fallbackLocale|default('-') }}</td>
208+
{%endif %}
203209
<tdclass="font-normal text-small text-bold nowrap">{{message.domain }}</td>
204210
<tdclass="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)

[8]ページ先頭

©2009-2025 Movatter.jp