Make the settings of Unit of time translatable in administration pages

Created on 12 February 2023, almost 2 years ago
Updated 11 March 2023, almost 2 years ago

Problem/Motivation

Hi everyone,
I encountered an error translating the module strings in administration pages. The part related to "Unit of time" does not add its strings after the installation finished.

Unit of time:

Default (only minute) without text
Only Minute
Minute and Second
Minute and Second, 1 minute if words < words per minute

Steps to reproduce

Install Drupal 10
Add second language
Enable the module
Try to adjust the administration page strings in the second language, or in other word translate the time unit settings.
Hope this report would make the module at its best, no matter what site configurations are.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

1.9

Component

User interface

Created by

🇮🇷Iran tsotoodeh

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

Comments & Activities

  • Issue created by @tsotoodeh
  • 🇧🇬Bulgaria yivanov

    The units of time are wrapped in a t() function, which means they are available to be translated in the UI Translate interface.

  • 🇻🇳Vietnam tra.duong

    @yivanov
    `tsotoodeh` see an error, he may not explained it clear.
    You can install a fresh Drupal site. Enable languages and interface translation, config translations..etc to check.
    You won't see the options in the 'Unit of time' which is `tsotoodeh` mentioned.
    If you search for

    • @minute
    • @second
    • @custom
    • @default

    You will see the translation string of them. You can see `@minute` but cannot see `Only Minute`.
    These are arguments as the code as this line provide:

    $this->t('@minute', ['@minute' => 'Only Minute']);
    

    So, if you translate the string by arguments, it may only available for developers or someone can read the code. It is not translate the text, just a replacement argument.

    There are 2 options to improve/correct this translations:

    // Your code:
      $only_minute = $this->t('@minute', ['@minute' => 'Only Minute']);
      $minute_second = $this->t('@second', ['@second' => 'Minute and Second']);
      $below = $this->t('@custom', ['@custom' => 'Minute and Second, 1 minute if words < words per minute']);
      $default = $this->t('@default', ['@default' => 'Default (only minute) without text']);
    
    
    /* Option 1:*/
      $only_minute = $this->t('Only Minute');
      $minute_second = $this->t('Minute and Second');
      $below = $this->t('Minute and Second, 1 minute if words < words per minute');
      $default = $this->t('Default (only minute) without text');
    
    
    /* Option 2:*/
      $only_minute = $this->t('@minute', ['@minute' =>  $this->t('Only Minute')]);
      $minute_second = $this->t('@second', ['@second' =>  $this->t('Minute and Second')]);
      $below = $this->t('@custom', ['@custom' =>  $this->t('Minute and Second, 1 minute if words < words per minute')]);
      $default = $this->t('@default', ['@default' =>  $this->t('Default (only minute) without text')]);
    
    

    Option 1: will provide 1 string in the translation text.
    Option 2: will provide 2 strings (ex: `@minute` and `Only Minute`).

    Note
    I think `tsotoodeh` mentioned about Option1 and this Option1 is correct.
    Besides, the @minute, @second ... may cause conflicts on translation string. They are so popular.

  • 🇮🇷Iran tsotoodeh

    @tra.duong
    I confirm your clarification 'tra.duong'. Both options mentioned does not convey the correct meaning and functionality that the module presents. And yes the context strings has popular use cases which makes it not possible to translate it in other forms. Are we clear 'yivanov'? Thank you.

  • Status changed to Needs review almost 2 years ago
  • 🇻🇳Vietnam tra.duong

    I made a commit on 3341137-make-the-settings
    Please review.

    • eb19abbc committed on 8.x-1.x
      git commit -m 'Issue #3341137 by tra.duong, tsotoodeh: Make the settings...
  • 🇧🇬Bulgaria yivanov

    Looks good, thanks !

  • Status changed to Fixed almost 2 years ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024