Locale IDs are chaotically assigned
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3545152. -->
Reported by: [claudiu.cristea](https://www.drupal.org/user/56348)
Related to !56
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>Source hashes are wrongly linked to Locale IDs.</p>
<p>The problem is located in <code>BabelLocaleTranslation::getStringTranslation()</code> and <code>BabelLocaleLookup</code>.</p>
<p>When a string translation is already cached, <code>BabelLocaleLookup::resolveCacheMiss()</code> is not called, so <code>BabelLocaleLookup::$sid</code> is not set for that string. Then <code>BabelLocaleTranslation::getStringTranslation()</code> tries to get the string translation by calling <code>BabelLocaleLookup::getSourceId()</code> which will return ID of the string that was last time fetched from the backend. And that it's an incorect string.</p>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<p>On a site with some content visit pages with a non-English language to get Locale tables populated.</p>
<p>Run this query:</p>
<pre>SELECT bs.hash, COUNT(bsi.id) AS c, GROUP_CONCAT(ls.source)<br>FROM babel_source bs<br>INNER JOIN babel_source_instance bsi ON bs.hash = bsi.hash<br>INNER JOIN locales_source ls ON bsi.id = ls.lid<br>GROUP BY bs.hash<br>HAVING c > 1</pre><p>You will notice different strings concatenated at the same hash. But different strings cannot have the same hash.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>When caching the translations, in <code>BabelLocaleLookup</code>, cache also the Locale source ID, so we can properly retrieve it.</p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<p>None.</p>
<h3 id="summary-ui-changes">User interface changes</h3>
<p>None.</p>
<h3 id="summary-api-changes">API changes</h3>
<p>None.</p>
<h3 id="summary-data-model-changes">Data model changes</h3>
<p>None.</p>
issue