kaisermann / svelte-i18n

Internationalization library for Svelte
MIT License
1.23k stars 79 forks source link

Variable inside html isn't replaced #225

Open Zerotask opened 1 year ago

Zerotask commented 1 year ago

Describe the bug

{
    "registerHere": "Or <a href='{url}'>register here</a>"
}
<p>{@html $_('registerHere', { values: { url: '/register'}})}</p>

Will produce:

<p>Or <a href="{url}">register here</a></p>

Without the @html it's the same. If I place the {url} variable outside the html code, it will be replaced correctly.

Expected behavior

<p>Or <a href="/register">register here</a></p>

Information about your project:

brunnerh commented 1 year ago

The dependency intl-messageformat parses tags, see this section of the docs.

You have to use a very strict format so it does not just throw SyntaxError: INVALID_TAG, i.e. double quotes for attribute values: 'Or <a href="{url}">register here</a>'

IzKuipers commented 1 month ago

This issue appears to still be present? I have this in my en.json file:

{
  "topbar": {
    "search": {
      "status": {
        "text": "Searching for '{query}'"
      }
    }
  }
}

Yet using this Svelte syntax doesn't work:

<span>
  {$_("topbar.search.status.text", { values: { query: $SearchQuery } })}
</span>

It returns: Searching for '{query}' instead of e.g. Searching for 'foo bar'

Hopefully there's an easy fix because I'm not looking to have to spend hours switching to another lib

johannchopin commented 1 month ago

Would be nice to document the usage of variables in the doc I had to find this issue to find the syntax 😄 I can help updating it.