Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable inside html isn't replaced #225

Open
Zerotask opened this issue Aug 10, 2023 · 3 comments
Open

Variable inside html isn't replaced #225

Zerotask opened this issue Aug 10, 2023 · 3 comments

Comments

@Zerotask
Copy link

Zerotask commented Aug 10, 2023

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:

  • svelte-i18n version: 3.7.0

  • Whether your project uses Webpack or Rollup: Vite (latest SvelteKit version)

@brunnerh
Copy link

brunnerh commented Sep 3, 2023

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
Copy link

IzKuipers commented Jul 26, 2024

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants