Process translation config files for custom modules

Created on 20 January 2017, almost 8 years ago
Updated 3 September 2024, 3 months ago

Problem/Motivation

It's possible to define a custom content type by placing necessary files into a custom module's directory structure under config/[install | optional]. One might also want that content type to be translatable and may have even gone through the work to define some of the translations. If those translations are placed in config/[install | optional]/language/[language-code], then they should be pulled into the system when the module is enabled. Currently it's not the case, because for `install` folder system ignores scalar values and processes only array values and for the `optional` folder system installs config only in default collection, ignoring all other available collections.

Proposed resolution

Process translation files correctly, when module is installed separately or along with profile installation, by processing all values in configs and taking all available collections for optional configs.

Remaining tasks

Review the patch, give feedback and fix the patch,

API changes

Within current patch function installOptionalConfig() receives 3rd parameter with collection name.

๐Ÿ› Bug report
Status

Needs review

Version

11.0 ๐Ÿ”ฅ

Component
Localeย  โ†’

Last updated 3 days ago

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States vegantriathlete Lakewood, CO

Live updates comments and jobs are added and updated live.
  • D8MI

    (Drupal 8 Multilingual Initiative) is the tag used by the multilingual initiative to mark core issues (and some contributed module issues). For versions other than Drupal 8, use the i18n (Internationalization) tag on issues which involve or affect multilingual / multinational support. That is preferred over Translation.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Moving to NW for the issue summary update. Specifically what's the proposed solution for this?

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia ankithashetty Karnataka, India

    Let's take a simple example:
    We have a module called test, which gets installed during profile installation. It has a configuration for both default language (EN) and another language (for ex: AR)

    test/config/install/test.settings.yml => EN version

    title: 'Contact us'
    // 'title' and 'description' is a scalar value.
    settings:
        confirmation_message: 'Thanks for contacting us!'
        ....
    // 'settings' is an array.
    

    test/config/install/language/ar/test.settings.yml => AR version

    title: 'ุงุชุตู„ ุจู†ุง'
    settings:
      confirmation_message: 'ุดูƒุฑุง ู„ุฅุชุตุงู„ูƒ ุจู†ุง. ุณู†ู‚ูˆู… ุจุงู„ุฑุฏ ุนู„ูŠูƒ ููŠ ุฃู‚ุฑุจ ูˆู‚ุช ู…ู…ูƒู†!'
        ....
    

    During profile installation, when the test is getting installed, the config translations are also imported. But noticed that the scalar values of the config (i.e., title in the above example) are skipped and only array values are considered (like settings)
    So after installation, try doing drsuh cget test.settings for both language, you would notice:

    • Both 'title' and 'settings' in EN version (works fine)
    • Only 'settings' in AR version (issue here)

    Code for ref: https://git.drupalcode.org/project/drupal/-/blob/10.1.x/core/modules/locale/src/LocaleConfigManager.php#L636

    Proposed solution (just a suggestion):
    With the patch in #51, we are trying to process all the config values ('array' and 'string').

    As I raised in #43, I still don't get why 'scalar' values are ignored.
    I might be missing wrong here, but the issue is valid๐Ÿค”

    Thanks!

  • last update over 1 year ago
    Custom Commands Failed
  • last update over 1 year ago
    Custom Commands Failed
  • Status changed to Needs review over 1 year ago
  • last update over 1 year ago
    29,959 pass
  • ๐Ÿ‡ท๐Ÿ‡บRussia sorlov

    Fixed code check issues on 11.x

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    #53 made some suggestions that I think may be worth responding.

    Issue summary still needs to be updated.

  • Status changed to Needs review about 1 year ago
  • last update about 1 year ago
    Custom Commands Failed
  • ๐Ÿ‡ท๐Ÿ‡บRussia ilya.no

    I'm not sure in what way should we update summary, because for me it looks clear. Should we just add text from comment #24 ๐Ÿ› Process translation config files for custom modules Needs work ?

    I'm attaching draft patch, which fixes the case, when we install module on already existing site. So current patch fixes 3/4 cases. Need to fix the case, when module is enabled during site installation.

    I've noticed, that ConfigInstaller manages all available collections, when installs default config, but when it comes to optional config, then only default collection is used. So, I've added code to use all available collections.

  • Status changed to Needs work about 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    CC failure in #57

    Issue summary states the problem but doesn't clearly states the solution to the problem.

    Is this changing the API or Data model? If not could leave those sections blank or put NA

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia gauravvvv Delhi, India

    Fixed CC failure. Attached interdiff for same.
    Leaving NW for summary update.

  • last update about 1 year ago
    Custom Commands Failed
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia gauravvvv Delhi, India

    Fixed failures, attached interdiff for same

  • last update about 1 year ago
    30,384 pass
  • Status changed to Needs review about 1 year ago
  • last update about 1 year ago
    30,411 pass
  • ๐Ÿ‡ท๐Ÿ‡บRussia ilya.no

    Attaching the patch which fixes all 4 cases for me. I test with custom module, which has settings config in install folder and view config in optional folder. For both cases there are translations in language/fr folder.
    Also updated summary.

  • Status changed to Needs work about 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Issue summary updated in #61

    think we need a test case

    If those translations are placed in config/[install | optional]/language/[language-code], then they should be pulled into the system when the module is enabled

    From what I can tell the current test changes don't cover that.

  • Status changed to Needs review 12 months ago
  • ๐Ÿ‡ท๐Ÿ‡บRussia ilya.no

    Attaching patch with test. Not sure, what is the best place for it, so I've chosen locale module, because I haven't found tests for `ConfigInstaller`.

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Environment: PHP 8.1 & MariaDB 10.3.22
    last update 12 months ago
    30,679 pass, 6 fail
  • Status changed to Needs work 12 months ago
  • The Needs Review Queue Bot โ†’ tested this issue.

    While you are making the above changes, we recommend that you convert this patch to a merge request โ†’ . Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance andypost
  • Status changed to Needs review 11 months ago
  • ๐Ÿ‡ท๐Ÿ‡บRussia ilya.no

    I've found, that my new test module's name is already occupied, so I've renamed and relocated it from locale to config_translation module.

  • last update 11 months ago
    30,772 pass
  • Status changed to Needs work 11 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    New tests should have typehints and returns

    May need a CR for installOptionalConfig, just to announce the new parameter.

    Can this be converted to an MR for quicker/easier reviews.

  • Status changed to Needs review 10 months ago
  • ๐Ÿ‡ท๐Ÿ‡บRussia ilya.no

    I've created MR and added typehints. I'm not sure about CR, because I have no feedback about my suggestion so far.

  • Pipeline finished with Success
    10 months ago
    Total: 486s
    #77380
  • Status changed to Needs work 10 months ago
  • The Needs Review Queue Bot โ†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide โ†’ to find step-by-step guides for working with issues.

  • Pipeline finished with Canceled
    9 months ago
    Total: 72s
    #92732
  • Pipeline finished with Canceled
    9 months ago
    Total: 131s
    #92734
  • Status changed to Needs review 9 months ago
  • ๐Ÿ‡ท๐Ÿ‡บRussia sorlov

    Rebased fork branch and rerolled patch. Need review

  • Pipeline finished with Success
    9 months ago
    Total: 490s
    #92737
  • ๐Ÿ‡ซ๐Ÿ‡ทFrance andypost

    Not sure the new method is the best solution but it will need CR anyway

  • Status changed to Needs work 9 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    For the CR

  • Pipeline finished with Canceled
    6 months ago
    Total: 33s
    #179250
  • Status changed to Needs review 6 months ago
  • ๐Ÿ‡ท๐Ÿ‡บRussia ilya.no

    I've added draft CR https://www.drupal.org/node/3449092 โ†’ and rebased MR.

  • Pipeline finished with Failed
    6 months ago
    Total: 180s
    #179251
  • Status changed to Needs work 6 months ago
  • The Needs Review Queue Bot โ†’ tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide โ†’ to find step-by-step guides for working with issues.

  • Pipeline finished with Failed
    6 months ago
    Total: 511s
    #183146
  • Pipeline finished with Success
    6 months ago
    Total: 659s
    #186893
  • Status changed to Needs review 6 months ago
  • ๐Ÿ‡ท๐Ÿ‡บRussia ilya.no

    I've fixed tests errors, so pipeline for the MR is fine now.

  • Status changed to RTBC 6 months ago
  • ๐Ÿ‡ซ๐Ÿ‡ทFrance andypost

    Looks ready now, thank you

  • Status changed to Needs work 6 months ago
  • The Needs Review Queue Bot โ†’ tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide โ†’ to find step-by-step guides for working with issues.

  • Pipeline finished with Success
    5 months ago
    Total: 479s
    #219785
  • Status changed to RTBC 5 months ago
  • ๐Ÿ‡ท๐Ÿ‡บRussia ilya.no

    Restoring previous status, as MR is rebased and pipeline is green.

  • Status changed to Needs work 4 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom alexpott ๐Ÿ‡ช๐Ÿ‡บ๐ŸŒ

    I've added some comments to the MR that need addressing.

  • Pipeline finished with Failed
    3 months ago
    Total: 520s
    #254849
  • Pipeline finished with Failed
    3 months ago
    Total: 215s
    #272524
  • Pipeline finished with Success
    3 months ago
    Total: 514s
    #272533
  • Status changed to Needs review 3 months ago
  • ๐Ÿ‡ท๐Ÿ‡บRussia ilya.no

    Sending issue back to review, as I've added changes for MR's comments and pipeline is green.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Question on the test changes. Are we losing coverage to get the tests to pass?

  • ๐Ÿ‡ท๐Ÿ‡บRussia ilya.no

    I've only added new test, because I haven't found any existing test for core/lib/Drupal/Core/Config/ConfigInstaller.php.
    Concerning changing of existing tests, I find comments #47 ๐Ÿ› Process translation config files for custom modules Needs work and #49 ๐Ÿ› Process translation config files for custom modules Needs work explanatory, but maybe I haven't delved enough into them.

Production build 0.71.5 2024