question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Translation of HTML context (e.g. paragraph with links inside)

See original GitHub issue

Hi,

by default all HTML in a translation key is rendered as string and no possibility is given to render also translated HTML within a translation key. Right? How is it possible to capacitate the package and having something like the component interpolation of <i18n> in vue-i18n? So the code would look like:

<i18n path="term" tag="label" for="tos">
  <a :href="url" target="_blank">{{ $t('tos') }}</a>
</i18n>

… that renders to something like this:

<label for="tos">
  I accept xxx <a href="/term" target="_blank">Term of Service</a>.
</label>

Or more advanced to put HTML to named target-“places” in the parent translation context:

en: {
  info: 'You can {action} until {limit} minutes from departure.',
  change: 'change your flight'
}

… coded as:

<i18n path="info" tag="p">
  <span place="limit">{{ changeLimit }}</span>
  <a place="action" :href="changeUrl">{{ $t('change') }}</a>
</i18n>

… renders to:

<p>
  You can <a href="/change">change your flight</a> until <span>15</span> minutes from departure.
</p>

What can I code to get this functionality? Or how can one implement this?

Or is there another work around to come to this?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:7
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

7reactions
dcshimancommented, Apr 3, 2019

You can use v-html to html elements as follows

<span v-html="$t('term', {
    'link': `<a href='/link.html'>${$t('link')}</a>`
  })" 
/>
2reactions
Gvadecommented, Sep 18, 2019

I’ve made a quick solution to this problem. It’s forked here. The example: doc. It assumes that you’re using { and } as the identifiers (I didn’t manage to access plugin config value from the external file in order to pick the actual ones).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using HTML's translate attribute - W3C
This is how articles such as the one you are reading handle links to translated versions of a page – the title attribute...
Read more >
How to translate HTML with examples - Lokalise Blog
So, in this article, I will explain how to get started on translating HTML code into different languages using Lokalise: a simple yet...
Read more >
Dynamic or static links and HTML in translatable strings - Drupal
Breaking text out to paragraphs makes it possible for translators to work on smaller chunks, which makes it more likely that they will...
Read more >
HTML Links Hyperlinks - W3Schools
HTML Links · HTML Links - Syntax. The HTML <a> tag defines a hyperlink. · HTML Links - The target Attribute. By default,...
Read more >
rails i18n - translating text with links inside - Stack Overflow
en.yml log_in_message_html: "This is a text, with a %{href} inside." log_in_href: "link". login.html.erb <p> <%= t("log_in_message_html" ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found