Skip to content

js-translation.json does not pick up strings in *.phtml files #33245

Open
@amenk

Description

@amenk

Follow up of #8508 (comment)

Background

Magento automatically picks up strings which should be supplied for the frontend translation via component via js-translation.json. This misses some strings, leaving hard-to-debug problems with translations to other languages.

Summary (*)

The process of fetching strings for js-translation.json has problems in 2.3.5 - and I am pretty sure it's still a problem in the dev master.

We struggled to translate the string "items" for the knockout component "minicart".

Steps to reproduce (*)

  1. Create a new custom module.
  2. Set Locale language to French (France) in Admin configurations Stores->Configurations->General->Locale Options.
  3. Add French translation for ‘foo bar 123’ in Admin Panel to “barre de foo 123”
  4. Keep string in newly created module phtml file to check if string is getting translated.
  5. Flush cache and check module on frontend.

Result: String is not getting translated with knockout js tag. It is displayed as ‘foo bar 123’ only.

Examples (*)

The extraction of the files happens here:

$files = array_merge(
$this->filesUtility->getJsFiles('base', $themePath),
$this->filesUtility->getJsFiles($areaCode, $themePath),
$this->filesUtility->getStaticHtmlFiles('base', $themePath),
$this->filesUtility->getStaticHtmlFiles($areaCode, $themePath)
);

The translatable string "items" is introduced here:

But the above extraction method does not count *.phtml files in - so translations like this are lost. (it eventually might still end up in the js-translation.json if the same string is used somewhere else in the theme, so such would cover up this bug)

Proposed solution

Include \Magento\Framework\App\Utility\Files::getPhtmlFiles or something similar in the list of files - but this might have a performance impact.

Or remove the whole automatic string extraction and add a manual list of strings which should be included in js-translation.json - this would make the whole process much simpler and less magic.

--
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

  • Severity: S0 - Affects critical data or functionality and leaves users with no workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: ContentComponent: TranslationIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P3May be fixed according to the position in the backlog.Progress: ready for devReproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions