ttag-org / ttag

:orange_book: simple approach for javascript localization
https://ttag.js.org/
MIT License
338 stars 41 forks source link

nggettext throws on case-sensitive keys #209

Closed mmso closed 7 months ago

mmso commented 3 years ago

A string such as

const result = c('Title').ngettext(msgid`Delete ${name}`, `Delete ${count} contacts`, count);

when translated will throw an error if translations exists with the same case-sensitive key

for example:

{
  "headers": {
    "plural-forms": "nplurals=2; plural=(n != 1);",
    "language": "de"
  },
  "contexts": {
    "Title": {
      "Delete ${ name }": [
        "${ name } löschen",
        "${ count } Kontakte löschen"
      ],
      "Delete ${ Name }": [
        "${ Name } löschen"
      ]
    }
  }
}
ttag-bug-example/node_modules/ttag/dist/ttag.js:151
    return r.replace(memReg(i), expr);
             ^

TypeError: Cannot read property 'replace' of undefined
    at ttag-bug-example/node_modules/ttag/dist/ttag.js:151:14
    at Array.reduce (<anonymous>)
    at msgid2Orig (ttag-bug-example/node_modules/ttag/dist/ttag.js:150:16)
    at Context.ngettext (ttag-bug-example/node_modules/ttag/dist/ttag.js:753:107)
    at error1 (ttag-bug-example/index.js:18:29)
    at Object.<anonymous> (ttag-bug-example/index.js:30:1)

I've created a reproducible example here: https://github.com/mmso/ttag-bug-example/commit/0dc5a0889d5c2be13996287fd34b0ce8fcd9705b

AlexMost commented 3 years ago

seems like a bug. Thanks for the report

AlexMost commented 7 months ago

done in 1.8.6 :heavy_check_mark: