Skip to content

Numbers in locale files result in incorrect translations on PDP #14647

Closed
@cherreman

Description

@cherreman

Numeric values in locale files are causing incorrect translations in Magento frontend.

Preconditions

  1. Magento version 2.2.2
  2. PHP 7.1.12

Steps to reproduce

  1. Include the translation file of the module CmsStaging (https://crowdin.com/translate/magento-2/1360/enus-nlbe, Head > app/code/Magento/CmsStaging/i18n/en_US.csv). This file contains the following key-value pairs:

"200","200"
"100","100"
"50","50"
"30","30"
"20","20"

  1. Create a product attribute of type dropdown
  2. Add the numeric value "5" as admin key and leave translations empty.
  3. Configure the attribute to be shown on the product page
  4. Select the value "5" in a product
  5. Browse to the PDP of the product

Expected result

  1. Value "5" is shown on the PDP

Actual result

  1. The value "200" is shown.

It seems like the array containing the translations has mixed string and numeric keys. When requesting the key "5", this is interpreted as the numeric index, causing the value "200" to be returned.

Debugged and detected this problem in magento/framework/Phrase/Renderer.

The following numeric entries were present in the $data array:

1386 = 0 -> $data0 = 123
1853 = 1 -> $data1 = 20
1854 = 2 -> $data2 = 30
1855 = 3 -> $data3 = 50
1856 = 4 -> $data4 = 100
1857 = 5 -> $data5 = 200
4431 = 6 -> $data6 = één (one)

Besides the technical issue, I'm wondering why the bundle CmsStaging contains numeric values.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions