mthh/loc-i18next

Issue with prepend

Jorricks opened this issue · 5 comments

Hello,

First of all, awesome that you made this library :)! It works very well.
However, I found a little bug that was present a couple months ago in another library as well.
i18next/jquery-i18next#19
Is there a possible fix for this issue?

mthh commented

Thanks for reporting this issue!
I will try to look into it this week.

mthh commented

I'm not sure on what is the expected behavior in this case with append and prepend. Don't we already have the same behavior than jquery-i18next ? Maybe you can give me more details ?

Hello Mthh,

Amazing that you respond so fast.
The matter that it going on is I have my div like the following
<div data-i18n="[prepend]sys.text">20</div>.
After translating this to EN, it becomes
<div data-i18n="[prepend]sys.text">Count: 20</div>
Translating again but now to NL makes it
<div data-i18n="[prepend]sys.text">Hoeveelheid: Count: 20</div>
So the issue at hand is that the translated text in fact adds this text again.
If you could for example change the translation process to become
<div data-i18n="[prepend]sys.text"><span>Count: </span>20</div>
and then translate just the span when translating again, we would get
<div data-i18n="[prepend]sys.text"><span>Hoeveelheid: </span>20</div>
which would be the expected behavior (at least to my understanding)

I hope this clarifies my issue a bit more

mthh commented

I think this should now behave as desired.

The modified version was published on npm (0.1.3), feel free to give me feedback if necessary.

I chose to use a custom HTML tag to pack the text translated with append / prepend (especially since I think there is less chance that a custom tag introduces undesirable effects, especially for style rules , unlike an existing tag as span).
So the DOM should now look like :
<div data-i18n="[prepend]sys.text"><loc-i18n>Hoeveelheid: </loc-i18n>20</div>
... language change ...
<div data-i18n="[prepend]sys.text"><loc-i18n>Count: </loc-i18n>20</div>

(by the way, as someone pointed on a related jquery-i18next issue, I don't think either that further DOM modification is a task for a localization module)

Amazing :)! It works exactly as expected now.
Thank you!