vue-i18n: Non-breaking space ( ) and other special chars
Both v-t and $t doesn’t support special chars like and so on. Using $t with v-html works well, but frequently it is needed as a “plain text” (without rendering HTML). By the way another localization plugins (e.g. vue-multilanguage) support this feature.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 4
- Comments: 16 (1 by maintainers)
is an HTML entity and it isn’t supposed to work outside ofv-html. If you want a non-breaking space, use a JavaScript escape code and not an HTML entity. The one for a non-breaking space is\xa0For most characters just paste the character in the text - all modern tools support Unicode fine. For things like non-breaking spaces the escape codes are useful because otherwise they’re kind of hard to see as they look just like normal spaces most of the time.
If we can avoid to ask translators to add such entities or special characters, I think we all agree that it is better. I’ve just found out that there is a
posTranslationconstructor option so the following work really well:@Xowap If your translators are OK with typing
do you think they could manage\xa0or\u202f? I guess those are a bit harder to remember. A filter would be pretty simple to implement yourself if you can come up with the logic, everything is just objects so you could loop through them and process every string.@kazupon how I can use this feature? I didn’t find it in the docs
The thing is that in French,
is required before?,!and a handful of others. Well, to be precise it’s officiallyU+202Fand not , but this doesn’t change the problem.To demonstrate the issue, in French you’d expect to see this:
However, if this reaches the end of a line, the
?might end up alone on the next line.That’s why there is a (narrow) non-breaking space instead of a regular space, this way the word will come along.
However, using
v-htmlfor all translations seems a bit hazardous but so is expecting translators to type “invisible” characters. Other solutions could be found I guess? Like language-wide filter to rectify punctuation?Here is a solution. You need to use the windows ascii input. ALT + 255 =
Exemple : ’ ’https://theasciicode.com.ar/extended-ascii-code/non-breaking-space-no-break-space-ascii-code-255.html
*On the other hand, I don’t know if the ALT code is different depending on the keyboard type/language.
Here’s a small utility to handle common french punctuation:
The characters list is not exhaustive.
@Xowap it’s easy to enter the unicode character for non-breaking space:
Personally, I have a french BÉPO keyboard and writing non-breaking spaces is as easy as pressing shift + space.