"- Select a value -", "- None -" and "- Any -" are not translated in multilingual site

Created on 13 June 2023, over 1 year ago
Updated 3 September 2023, over 1 year ago

Problem/Motivation

Default sting in dropdown such as "- Select a value -", "- None -" and "- Any -" are not translated in multilingual site.
"Add another item" button at the filter area of views is not translated, either.
This symptom occurs with 2.0.0-rc1~rc4, does not occur with 8.x-1.0-alpha5.

Steps to reproduce

a-1. Create a Japanese content which has multi-level dropdown (term w/ child term) field and single-level dropdown (term w/o child term).
a-2. Multi-level dropdown shows "- None -", not Japanese.
On the other hand, single dropdown shows Japanese correctly.
(See case-a.png. upper dropdown is single dropdown.)

b-1. Create views which has multi-level dropdown field and single-level dropdown as filter.
b-2. Access to the views URL, multi-level dropdown shows "- Any -", not Japanese.
There is "Add another item" button under the multi-level dropdown, and it is not Japanese, either.
(See case-b-multi.png.)
Single dropdown also shows "- Any -", not Japanese.
(See case-b-single.png.)

Proposed resolution

Regarding case-b multi-level dropdown, editing /src/Plugin/views/filter/ShsTaxonomyIndexTid.php works for me.
L.64
$settings_additional = [
'required' => $this->options['expose']['required'],
'multiple' => $this->options['expose']['multiple'],
// 'anyLabel' => $this->t('- Any -'),
'anyLabel' => t('- Any -'),
'anyValue' => 'All',
// 'addNewLabel' => $this->t('Add another item'),
'addNewLabel' => t('Add another item'),
];

🐛 Bug report
Status

Needs review

Version

2.0

Component

Compatibility with other modules

Created by

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

Comments & Activities

  • Issue created by @kubokura
  • Assigned to sourabhjain
  • 🇮🇳India sourabhjain

    Let me work on it.

  • Issue was unassigned.
  • Hi, it seems StringTranslationTrait is cause of this issue.
    Proposed resolution
    To Comment out "use StringTranslationTrait;" in ShsTaxonomyIndexTid.php and OptionsShsWidget.php works for me.
    (Proposed resolution of June 13 is unnecessary.)

    [shs/src/Plugin/views/filter/ShsTaxonomyIndexTid.php]
    diff ShsTaxonomyIndexTid.php ShsTaxonomyIndexTid.php.orig
    8c8
    < //use Drupal\shs\StringTranslationTrait;
    ---
    > use Drupal\shs\StringTranslationTrait;
    22c22
    < // use StringTranslationTrait;
    ---
    > use StringTranslationTrait;

    [shs/src/Plugin/Field/FieldWidget/OptionsShsWidget.php]
    diff OptionsShsWidget.php OptionsShsWidget.php.orig
    12c12
    < //use Drupal\shs\StringTranslationTrait;
    ---
    > use Drupal\shs\StringTranslationTrait;
    30c30
    < // use StringTranslationTrait;
    ---
    > use StringTranslationTrait;

  • Status changed to Needs review over 1 year ago
  • 🇫🇷France dydave

    Hi everyone,

    Thank you very much for raising this issue and providing suggestions on how the problem could be fixed, it's greatly appreciated.

    I would like to confirm as well, having the same issue after upgrading to the latest release:

    • shs: '2.0.0-rc4'
    • core: '9.5.10'

     
    For the time being, the following entry was added to project's translations.po file:

    msgctxt "shs:options_widget"
    msgid "- Select a value -"
    msgstr "- Choisir une valeur -"
    

    Watch carefully the added context: msgctxt "shs:options_widget".
    Once the translation file imported, the label should display properly in the corresponding language.

    Otherwise the translations can be provided on the interface translation page at '/admin/config/regional/translate', if you search for "- Select a value -", you should see the missing translations for the shs label with added context.

    Lastly, default translations for the module could probably also be provided on the localize platform, see for example, French translations:
    https://localize.drupal.org/translate/languages/fr/translate?page=2&proj...

    At this point, it doesn't seem like there would be anything to do with the current code of the module ('2.0.x') and the problem should probably be fixed with the different methods outlined above.

    We hope we were able to answer your questions and clear your doubts, but feel free to let us know if we missed anything or if you would need more information on module's translations, we would be glad to help.
    Thanks in advance to everyone for your feedback and comments.

  • 🇫🇷France dydave

    Hi everyone,

    Quick follow-up on this issue:

    After taking a closer look at the problem, it seems all strings going through the shs module, in particular in the exposed filters (with or without exposed operators) will get their strings overriden to use the context shs, for example:

    Is none of
    In context: shs:taxonomy_index_tid
    
    Is none of
    In context: shs:taxonomy_index_tid
    
    Is one of
    In context: shs:taxonomy_index_tid_depth
    
    Is one of
    In context: shs:taxonomy_index_tid
    
    Is all of
    In context: shs:taxonomy_index_tid

    .... etc...

    Whith the addition of the field widget:

    - Select a value -
    In context: shs:options_widget

     

    The fact that we would have to translate every string again, as suggested in my previous reply above (#5), doesn't really seem like a sustainable or acceptable answer to this problem.
    It would imply a lot of work, not to mention the maintenance of the strings, if/when there would be changes.

    Therefore, we would like to recommend a different approach :

    Ideally, it would be great if we could use the translation with context if there is one, or fallback to the default, existing string translation without context, which would allow keeping all the existing Views related string translations, for example, and allow overriding within the `shs` context if needed:

    Please find attached to this ticket a patch on the '2.0.x' branch:
    shs-string-translations-fallback-to-default-without-context-3366382-6.patch

    Which is an attempt to check whether the string has a translation for the given context, otherwise fallback to the ones without context.

    We would greatly appreciate if you could please try testing the patch and let us know if you encounter any issues.

    Feel free to let us know if you have any questions on the patch, or this ticket in general, we would be glad to provide more information.
    Thanks in advance!

  • Hi, DYdave-san, thank you for the patch.
    The patch works for me. Japanese terms appear correctly in Japanese pages.
    (By the way, I also use the patch of 4.diff on 🐛 "- Select a value -" appears at bottom of lists RTBC )

Production build 0.71.5 2024