[Translation] Collect original locale in case of fallback translation

This commit is contained in:
Markus Fasselt 2019-08-04 11:58:04 +02:00 committed by Fabien Potencier
parent 2b0f2de485
commit 5564e149cb
3 changed files with 21 additions and 9 deletions

View File

@ -13,7 +13,7 @@
{% set text %}
<div class="sf-toolbar-info-piece">
<b>Locale</b>
<b>Default locale</b>
<span class="sf-toolbar-status">
{{ collector.locale|default('-') }}
</span>
@ -73,7 +73,7 @@
<div class="metrics">
<div class="metric">
<span class="value">{{ collector.locale|default('-') }}</span>
<span class="label">Locale</span>
<span class="label">Default locale</span>
</div>
<div class="metric">
<span class="value">{{ collector.fallbackLocales|join(', ')|default('-') }}</span>
@ -152,7 +152,7 @@
</div>
{% else %}
{% block fallback_messages %}
{{ helper.render_table(messages_fallback) }}
{{ helper.render_table(messages_fallback, true) }}
{% endblock %}
{% endif %}
</div>
@ -185,11 +185,14 @@
{% endblock %}
{% macro render_table(messages) %}
{% macro render_table(messages, is_fallback) %}
<table>
<thead>
<tr>
<th>Locale</th>
{% if is_fallback %}
<th>Fallback locale</th>
{% endif %}
<th>Domain</th>
<th>Times used</th>
<th>Message ID</th>
@ -200,6 +203,9 @@
{% for message in messages %}
<tr>
<td class="font-normal text-small nowrap">{{ message.locale }}</td>
{% if is_fallback %}
<td class="font-normal text-small nowrap">{{ message.fallbackLocale|default('-') }}</td>
{% endif %}
<td class="font-normal text-small text-bold nowrap">{{ message.domain }}</td>
<td class="font-normal text-small nowrap">{{ message.count }}</td>
<td>

View File

@ -145,6 +145,7 @@ class DataCollectorTranslator implements TranslatorInterface, TranslatorBagInter
$id = (string) $id;
$catalogue = $this->translator->getCatalogue($locale);
$locale = $catalogue->getLocale();
$fallbackLocale = null;
if ($catalogue->defines($id, $domain)) {
$state = self::MESSAGE_DEFINED;
} elseif ($catalogue->has($id, $domain)) {
@ -153,10 +154,9 @@ class DataCollectorTranslator implements TranslatorInterface, TranslatorBagInter
$fallbackCatalogue = $catalogue->getFallbackCatalogue();
while ($fallbackCatalogue) {
if ($fallbackCatalogue->defines($id, $domain)) {
$locale = $fallbackCatalogue->getLocale();
$fallbackLocale = $fallbackCatalogue->getLocale();
break;
}
$fallbackCatalogue = $fallbackCatalogue->getFallbackCatalogue();
}
} else {
@ -165,6 +165,7 @@ class DataCollectorTranslator implements TranslatorInterface, TranslatorBagInter
$this->messages[] = [
'locale' => $locale,
'fallbackLocale' => $fallbackLocale,
'domain' => $domain,
'id' => $id,
'translation' => $translation,

View File

@ -34,6 +34,7 @@ class DataCollectorTranslatorTest extends TestCase
'id' => 'foo',
'translation' => 'foo (en)',
'locale' => 'en',
'fallbackLocale' => null,
'domain' => 'messages',
'state' => DataCollectorTranslator::MESSAGE_DEFINED,
'parameters' => [],
@ -42,7 +43,8 @@ class DataCollectorTranslatorTest extends TestCase
$expectedMessages[] = [
'id' => 'bar',
'translation' => 'bar (fr)',
'locale' => 'fr',
'locale' => 'en',
'fallbackLocale' => 'fr',
'domain' => 'messages',
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
'parameters' => [],
@ -52,6 +54,7 @@ class DataCollectorTranslatorTest extends TestCase
'id' => 'choice',
'translation' => 'choice',
'locale' => 'en',
'fallbackLocale' => null,
'domain' => 'messages',
'state' => DataCollectorTranslator::MESSAGE_MISSING,
'parameters' => [],
@ -60,7 +63,8 @@ class DataCollectorTranslatorTest extends TestCase
$expectedMessages[] = [
'id' => 'bar_ru',
'translation' => 'bar (ru)',
'locale' => 'ru',
'locale' => 'en',
'fallbackLocale' => 'ru',
'domain' => 'messages',
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
'parameters' => [],
@ -69,7 +73,8 @@ class DataCollectorTranslatorTest extends TestCase
$expectedMessages[] = [
'id' => 'bar_ru',
'translation' => 'bar (ru)',
'locale' => 'ru',
'locale' => 'en',
'fallbackLocale' => 'ru',
'domain' => 'messages',
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK,
'parameters' => ['foo' => 'bar'],