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.

v-t directive if not path, support translate the innerText?

See original GitHub issue

https://github.com/kazupon/vue-i18n/blob/adb5269e90ff945fda04c35652f826b82dd9cf8d/src/directive.js#L70

demo:

<h5 class="h3" v-t>Pages</h5>

if support that it can improve the code speed.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
HendrikJancommented, Jul 15, 2021

This looks like a feature that angular-translate supports for a long time: angular-translate directive I’ve used this a lot in Angularjs projects and really like it.

Writing {{ $(' and ') }} adds quite some cognitive load. The same goes for v-t="' and '".

Instead of writing

<span>{{ $('Accept') }}</span>

you can write

<span v-t>Accept</span>
  • This syntax makes it look much more like plain html.
  • It’s much shorter.
  • Code-highlighting usually works better (easier readable) this way.
  • For complex situations you can always use $t.

I like this proposal.

0reactions
crazyndscommented, May 22, 2021

I’m pretty sure this is not feasible. The following would be extremely confusing and complicated to parse correctly.

<h5 v-t>
  Text to translate
  <span>Some more markup</span>
</h5>

The way @masongzhi proposed is correct and works. What’s the use case for supporting a different way of marking translatable content?

I also believe that this syntax must be accepted. And the example given is invalidated by the following fact that:

 <h5 v-t='text.translated'>
   <span>Some more markup</span>
</h5>

Does not work perfectly and deletes the span tag internally. But it can be circumvented using another tag:

 <h5>
   <span v-t='text.translated'></span>
   <span>Some more markup</span>
</h5>

I believe that the same thing can be done in the use that was mentioned above

What @icai talked about is that it would be interesting to add the syntax that by adding the empty v-t suffix within an element, it will take its content and translate it as if it were the way. Example below:

 <h5 v-t> 
    title.page.in.path
 </h5>

This code will have the same result as:

  <h5 v-t="'title.page.in.path'"> 
 </h5>

I believe that in the way that is being proposed in this issue it would be much more pleasant to read the code than to see the element tags that are often full of information.

Read more comments on GitHub >

github_iconTop Results From Across the Web

vt directive if not path, support translate the innerText ... - Issuehunt
What you want is when v-t directive was empty, it should translate the keypath Pages like v-t="'Pages'". You should change the following code:...
Read more >
Custom Directive | Vue I18n
You can translate not only with $t , but also with the v-t custom directive. String syntax #. You can pass the keypath...
Read more >
Custom directive localization | Vue I18n
Custom directive localization. Support Version. 7.3+. You can translate not only with v-t custom directive, but also with the $t method.
Read more >
angular.translate not working in the context of <br> in HTML
If you put translation inside an html element, all the child elements will be overwritten by the translation value. Instead you can try...
Read more >
Performance optimization of vue-i18n - Medium
Translation performance is `compiler module > custom directive v-t > $t ... In this way, vue-i18n reduce the translation cost so as not...
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