tolgee / tolgee-js

Tolgee JavaScript libraries monorepo
https://tolgee.io
MIT License
236 stars 28 forks source link

Invisible chars added to string loaded with `t` function #3302

Closed baptisteArno closed 10 months ago

baptisteArno commented 10 months ago

My en.json file contains this key:

"templates.modal.marketing.leadGeneration.name": "Lead Generation",

I actually found out that invisible caracters are added to the string:

const { t } = useTranslate()
console.log(
    t('templates.modal.marketing.leadGeneration.name'),
    Object.entries(t('templates.modal.marketing.leadGeneration.name')),
    t('templates.modal.marketing.leadGeneration.name') === "Lead Generation" // output: false
)

It prints 24 entries instead of 15.

CleanShot 2024-01-23 at 19 27 03@2x

Do you manage to reproduce that? 🤔

stepan662 commented 10 months ago

Hey, this seems like a correct behavior. If you use DevTools, we add invisible characters to each rendered translation, so it can be detected in the dom and registered for in-context translating. You can opt-out from this by doing

t('key', { noWrap: true })
baptisteArno commented 10 months ago

Alright, it makes sense now, thank you for the info! :)