samuelstroschein / inlang-plugin-json

inlang plugin to parse and serialize json resources
MIT License
9 stars 3 forks source link

ordering of messages seems to be ignored with numbers #21

Closed samuelstroschein closed 1 year ago

samuelstroschein commented 1 year ago

Problem

The following errors occurred during the setup of plugins:

None ✅

# The following errors occurred during the validation of the config:

A roundtrip test of the readResources and writeResources functions failed:

The message with id "globals.months.10" does not match for the resource
with languageTag.name "ca".

Received:
{
  "type": "Message",
  "id": {
    "type": "Identifier",
    "name": "globals.months.2"
  },
  "pattern": {
    "type": "Pattern",
    "elements": [
      {
        "type": "Text",
        "value": "febr."
      }
    ]
  }
}

Expected:
{
  "type": "Message",
  "id": {
    "type": "Identifier",
    "name": "globals.months.10"
  },
  "pattern": {
    "type": "Pattern",
    "elements": [
      {
        "type": "Text",
        "value": "oct."
      }
    ]
  }
}

Reproduction

  1. Open https://inlang.com/editor/github.com/allinurl/goaccess

Additional information

The ordering of message ids does not seem to be obeyed, leading to this bug. If that is the case, this bug should be fixed and a better error message should also be provided.

NilsJacobsen commented 1 year ago

Seems like the setSafe Function is sorting keys with numbers, which is not what we like. https://github.com/angus-c/just/issues/559

NilsJacobsen commented 1 year ago

This plain js function works as expected.

obj = {...obj, ...{[key]: value}}
samuelstroschein commented 1 year ago

@NilsJacobsen perfect lets get rid of safeSet