Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-breaking space ( ) and other special chars #318

Closed
artemtam opened this issue Mar 29, 2018 · 16 comments
Closed

Non-breaking space ( ) and other special chars #318

artemtam opened this issue Mar 29, 2018 · 16 comments
Labels
Type: Improvement Includes backwards-compatible fixes

Comments

@artemtam
Copy link

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.

@amosbatista
Copy link

Hello.
I don't know why, I have to replace this char before set 'v-html' content. I wonder what is this problem...

@avenla-mvirkkunen
Copy link

avenla-mvirkkunen commented Apr 10, 2018

  is an HTML entity and it isn't supposed to work outside of v-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 \xa0

For 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.

@Xowap
Copy link

Xowap commented Apr 12, 2018

The thing is that in French,   is required before ?, ! and a handful of others. Well, to be precise it's officially U+202F and not  , but this doesn't change the problem.

To demonstrate the issue, in French you'd expect to see this:

Parlez-vous le français ?

However, if this reaches the end of a line, the ? might end up alone on the next line.

Parlez-vous le français
?

That's why there is a (narrow) non-breaking space instead of a regular space, this way the word will come along.

Parlez-vous le
français ?

However, using v-html for 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?

@avenla-mvirkkunen
Copy link

@Xowap If your translators are OK with typing   do you think they could manage \xa0 or \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.

@laurentpayot
Copy link

laurentpayot commented Apr 13, 2018

@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.

@Xowap
Copy link

Xowap commented Apr 13, 2018

In my experience, translators forget to insert any form of (N)NBSP.

I agree that the actual unicode characters are easier to safely move around.

@laurentpayot I think we can agree that moving everybody to BEPO is not an easy fix for this

@avenla-mvirkkunen sure I can (and do) code things myself but the problem is at least affecting every application translated to French and I guess that other languages are affected too. Some standard way of dealing with this oft-ignored problem would be pretty nice.

@jp-sauve
Copy link

jp-sauve commented Jan 10, 2019

I'm looking at a similar problem, but I am trying to insert &laquo and &raquo in french translations. Is there a way of doing this that I haven't figured out? I tried putting in javascript escape sequences, but those are rendered as text as well.

@mvirkkunen
Copy link

@jp-sauve

HTML escapes just represent Unicode characters so all you need to do is use the characters as-is. Non-breaking spaces and such are a bit of a special case because most editors don't make it easy to tell apart from normal spaces, but « and » are just normal characters so there's no need to use an escape sequence at all.

@jp-sauve
Copy link

Thanks! I don't know why I didn't think of that, but it worked perfectly of course.

@spassignat
Copy link

spassignat commented Feb 19, 2019

Hi,

It would be great to have non encoded/decoded messages, as it was in 8.1.0 version (if my tests are corrects).
Sometime, using external composite components, translated texts are provided as attributes (ex: bootstrap vuejs) which makes the usage of v-html not applicable without a complete review of the application to use slots.

I understand the idea of decode/encode and use of v-html, it's probably great, but changing the default behavior of $t function has some drawbacks (doesn't ensure backward compatibility with previous versions).

Are there any solution to "hack" the behavior of $t function and return to the 8.1.0 behavior ?

thanks.

pcraig3 added a commit to cds-snc/cra-claim-tax-benefits that referenced this issue Oct 7, 2019
Up to this point, we've been using non-breaking spaces that
are visually identical to normal spaces. But we should have some
kind of space that is visually distinct.

Adding the unicode character sequence is a better solution.

Note: there is a mention in the discussion that we should be using
half-spaces but we haven't been doing that so far.

Source:
- kazupon/vue-i18n#318
- http://www.fileformat.info/info/unicode/char/00a0/index.htm
@kazupon kazupon added Type: Improvement Includes backwards-compatible fixes and removed Type:MsgKey labels Feb 25, 2020
@imagoiq
Copy link

imagoiq commented Apr 28, 2020

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 posTranslation constructor option so the following work really well:

postTranslation: (str) => str.replace(' ?', '\xa0?').replace(' !', '\xa0!')

@nicooprat
Copy link

Here's a small utility to handle common french punctuation:

// Replaces white spaces before or after some punctuations by non breaking spaces
// Eg. replaces " ?" by " ?" or "« " by "« " to avoid unwanted line breaks
const addNbspAroundPunctuation = (str) =>
  str.replace(/\s+([:;»!?/])|([«])\s+/g, (match, left, right) => {
    if (left) {
      return `\xa0${left}`;
    }
    if (right) {
      return `${right}\xa0`;
    }
  });

The characters list is not exhaustive.

@kazupon
Copy link
Owner

kazupon commented Mar 5, 2021

we supported in Vue I18n v9.
please try it!

@aronsuarez
Copy link

@kazupon how I can use this feature? I didn't find it in the docs

@srochefortNmedia
Copy link

srochefortNmedia commented Aug 24, 2022

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.

@devonik
Copy link

devonik commented Jun 6, 2023

I had read the new documentation here https://vue-i18n.intlify.dev/guide/essentials/syntax.html#special-characters and for @ as example i just had to change it in the message to {'@'} and it works 👍
I'm using nuxt3 and "@nuxtjs/i18n": "8.0.0-beta.12" and had the issue [vite-node] [VITE_ERROR] /.nuxt/i18n.options.mjs If you also get this exception check if your i18n messages contains any special characters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Improvement Includes backwards-compatible fixes
Projects
None yet
Development

No branches or pull requests