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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

james.williams created an issue. See original summary.

james.williams’s picture

J-Lee’s picture

The patch is working for us. Great work. Thank you.

J-Lee’s picture

Status: Needs review » Reviewed & tested by the community

  • james.williams committed 64008dcb on 2.x
    Issue #3223255 by julien.sibi: Inherited translations for javascript...
james.williams’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.