Inherited translations for javascript strings still missing

Created on 12 July 2021, over 3 years ago
Updated 19 January 2023, almost 2 years ago

As reported in #3024767-50: Drupal.t() doesn't inherit parent translations. by julien.sibi , who also provided the attached patch:

Hi,

on my local drupal instance working with 2.0-rc3, i still don't get inherited translations in drupalTranslations DOM variable.

In my language_hierarchy_configuration, i have some local languages inheriting parents languages. In my example 'at-de' is inheriting 'de'.

in _locale_rebuild_js (core locale module) . I can see this :

  // Construct the array for JavaScript translations.
  // Only add strings with a translation to the translations array.
  $conditions = [
    'type' => 'javascript',
    'language' => $language->getId(),
    'translated' => TRUE,
  ];
..
  foreach (\Drupal::service('locale.storage')->getTranslations($conditions) as $data) {
    $translations[$data->context][$data->source] = $data->translation;
  }

so when $conditions array is build, we get $conditions['translated'] to TRUE.

it will lead to call dbStringSelect in StringDatabaseStorageDecorator.php with same $conditions.

  protected function dbStringSelect(array $conditions, array $options = []) {
    $query = $this->stringStorage->dbStringSelect($conditions, $options);

    // The 'translated' meta-condition bypasses fallbacks, since it is used for
    // querying specifically for a given language.
    if (!isset($conditions['translated'])) {

in this moment the condition on $conditions['translated'] will avoid building a query using JOIN to build translation js files..

My only way to get it working was to modify the condition as you can see it in this patch.

Am i missing something ?

Thanks Julien

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom james.williams

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024