1

Hi I have a webpage that contains multi-languages

I created a JSON file that has a key for each word on the page

but I want to but an empty language ( don't ask me why ) that's like this:

the original word Hi there ==>

so I created a thing like this in JSON

"langCode": "  ",
    "langName": "       ",

    "services": "        ",
    "clients": "       ",
    "features": "        ",
    "about": "     ",
    "contact": "       ",
    "letsBuildTheWwweb": "                     ",
    "teamOfDevelopersUiuxDesignersAndLogoDesigners": "                                                       ",
    "hireUs": "          ",

    "webDeveloping": "              ",
    "cryptoSystem": "             ",
    "logoDesinging": "              ",
    "seoOptimazation": "              ",
    "webHosting": "           ",
    "adsOptimazation": "                ",
    "webDesigning": "              ",
    "uiUxDesinging": "                 ",
    "ecommerce": "          ",
    "domainRegistration": "                   ",

I insert json into HTML this way :

$.getJSON(dir, (lang) => {
    document.querySelector('.langCode').innerText = lang.langCode;
    });

when I open the page I see     everywhere not

Dear moderators, I'm noob in StackOverflow so if I have wrongs in my questions don't delete it cuz I got banned 4 times

11
  • How are you inserting this json data in HTML? More details required. Commented May 23, 2021 at 12:17
  • Read my comment again. Commented May 23, 2021 at 12:19
  • my reply still the same :) Commented May 23, 2021 at 12:24
  • Try innerHTML instead of innerText Commented May 23, 2021 at 12:24
  • @Omkar76 you can see in the question Commented May 23, 2021 at 12:25

1 Answer 1

3

Change each   your JSON to \u00a0:

{
  "langCode": "\u00a0\u00a0",
  "langName": "\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0",
  "services": "\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0",
  "clients": "\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0",
  "features": "\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0"
}

  is the HTML escape sequence for the non-breaking space. JSON is not HTML, the proper escape sequence in JSON is \u00a0 (Unicode Character 'NO-BREAK SPACE' (U+00A0)).

Sign up to request clarification or add additional context in comments.

5 Comments

in JSON file a bug says Invalid escape character in string.json(261)
@Eymen My bad, I meant \u00a0.
The problem is use of innerText instead of innerHTML
@SagarV No, that's not the problem. That's a possible solution to the problem, and a bad one at that, because for one thing, the OP very likely uses some framework to bring in the translations, and changing that might be difficult. And for another thing, switching to .innerHTML opens the door for XSS attacks or rendering bugs and therefore causes more harm than good. The problem is that the OP wants non-breaking spaces in their JSON, and   is not the way to do that.
@SagarV it both worked, thank you all guys

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.