claudetech / node-static-i18n

HTML static pages i18n tool
https://www.npmjs.com/package/static-i18n
MIT License
104 stars 21 forks source link

Translate text without wrapper #14

Closed alvarotrigo closed 6 years ago

alvarotrigo commented 6 years ago

Having something like:

<div class="demo">
    <div class="loading"></div>
    My text here 
</div>

There's no easy way to translate the text "My text here" unless wrapped in a some kind of element.

Something similar occurs when using other frameworks such as Knockout.js, but the solution they adopted was allowing the use of HTML comments for those cases, so it would end up like this:

<div class="demo">
    <div class="loading"></div>
    <!-- data-t-->My text here<!-- -->
</div>

A solution like this would be great for this module. As far as I know I didn't find an easy way of dealing with theses cases. Correct me if I'm wrong.

alvarotrigo commented 6 years ago

I thought about using interpolation but noticed it only works for attributes? Was thinking of doing something like this:

<div class="demo" data-t-interpolate>
    <div class="loading"></div>
    {{My text here}}
</div>

This would also get rid of other issues such as texts with internal links:

<div data-t>My text is here <a href="whatever">and this is a link</a></div>

Which won't work properly at the moment as it will replace the whole text for the translation getting rid of the link.

This could be a possible solution?

<div data-t>{{My text is here}} <a href="whatever">{{and this is a link}}</a></div>

I know you could use the HTML option, but I don't see it as a good solution when there's plenty of links or html code inside an element containing text.

danhper commented 6 years ago

I think this should be fixed by your PR too, thanks.

cmdesign85 commented 6 years ago

You can also put a : <span data-t>your text</span> around your text. I use it a lot, it works perfectly.