Altinn / app-frontend-react

Altinn application React frontend
BSD 3-Clause "New" or "Revised" License
18 stars 31 forks source link

Add formatting to key-references in resource-files #2287

Open xmrsa opened 2 months ago

xmrsa commented 2 months ago

Description

We would like to be able to format values from a data field directly in the resource-files. This would give a simple way to get f.ex. thousand separator or comma when showing a numeric value, instead of having to concat several texts each time we need formatted text in the middle of a sentence. This would also make translation easier.

I imagine this could look something like this:

 {
      "id": "lang.info.fra.prefill",
      "value": "Ved forrige innrapportering oppga dere å ha dyrket totalt {0} kvadratmeter bambus.",
      "variables": [
        {
          "key": "Prefill.kvadratmeterbambus",
          "dataSource": "dataModel.A3_RA-0775_M",
          "formatting": {
               "number": {
                                 "decimalScale": 0,
                                 "thousandSeparator": " "
                                }
                             }
        }
      ]
}

Formatting f.ex. dates in a similar fashion would also be useful.

Additional Information

Related: https://github.com/Altinn/app-frontend-react/issues/1305

nkylstad commented 2 months ago

Transferring to app-frontend repo