question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Translations containing backslashes

See original GitHub issue
  • I am on the latest ember-intl version
  • I have searched the issues of this repo and believe that this is not a duplicate

Environment

  • Ember Version: 3.1.0
  • Ember CLI Version: 3.1.0
  • Ember Intl Version: 3.2.6
  • Browser(s): Chrome latest
  • Node Version: 8.9.4

Steps to Reproduce

  1. Add a translation that contains backslashes e.g.,
email:
    formats:
      default: '^.+@.+\.\w+$'

The reason we return a regex in translations it to ensure consistency in UI and API validations i.e., both the UI and API use this regex.

  1. Try to load the translation in your app with intl.t('email.formats.default')

View the peg$SyntaxError error in the console:

{
  "message": "Expected \"\\\\#\", \"\\\\\\\\\", \"\\\\u\", \"\\\\{\", \"\\\\}\", \"{\", [^{}\\\\\\0-\\x1F\\x7f \\t\\n\\r], end of input or whitespace but \"\\\\\" found.",
  "expected": [
    {
      "type": "literal",
      "value": "\\#",
      "description": "\"\\\\#\""
    },
    {
      "type": "literal",
      "value": "\\\\",
      "description": "\"\\\\\\\\\""
    },
    {
      "type": "literal",
      "value": "\\u",
      "description": "\"\\\\u\""
    },
    {
      "type": "literal",
      "value": "\\{",
      "description": "\"\\\\{\""
    },
    {
      "type": "literal",
      "value": "\\}",
      "description": "\"\\\\}\""
    },
    {
      "type": "literal",
      "value": "{",
      "description": "\"{\""
    },
    {
      "type": "class",
      "value": "[^{}\\\\\\0-\\x1F\\x7f \\t\\n\\r]",
      "description": "[^{}\\\\\\0-\\x1F\\x7f \\t\\n\\r]"
    },
    {
      "type": "end",
      "description": "end of input"
    },
    {
      "type": "other",
      "description": "whitespace"
    }
  ],
  "found": "\\",
  "location": {
    "start": {
      "offset": 6,
      "line": 1,
      "column": 7
    },
    "end": {
      "offset": 7,
      "line": 1,
      "column": 8
    }
  },
  "name": "SyntaxError"
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
jasonmitcommented, Feb 10, 2019

The original parser messageformat-parser which intl-messageformat-parser was derived from has quote escaping and allows backslashes now. I’ve begun to port the logic over to the intl-messageformat-parser.

This will end up being a breaking change as it removes backslash as a special character for escaping in favor of the ICU spec quote escaping. I’ll version accordingly once this is ready for me to merge.

1reaction
jasonmitcommented, Mar 25, 2020

After updating the translation parser and compiler, this should now be resolved on master. Single quotes now properly escapes characters within the ICU syntax.

There are many breaking changes so will be releasing a 5.0.0-unstable shortly while I document all the breaking changes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Backslashes removed in translation - WPML
I am trying to: Translate a post from language1 to language2. So I klick on the plus-symbol and the Translation Editor opens.
Read more >
Spanish Translation of “backslash” - Collins Dictionary
Spanish Translation of “backslash” | The official Collins English-Spanish Dictionary online. Over 100000 Spanish translations of English words and phrases.
Read more >
Backslash - Wikipedia
The backslash \ is a typographical mark used mainly in computing and mathematics. It is the mirror image of the common slash /....
Read more >
Backslash Escapes (Guile Reference Manual) - GNU.org
For example, if Guile encounters the character sequence ' \n ' in the middle of a string while processing Scheme code, it replaces...
Read more >
IV75603: BACKSLASH \ INCORRECTLY TRANSLATED ON ...
The backslash is translated to 0x5C in UTF-8 and then in error to 0x7F. Example: <cache file> (with Log File Agent v6.3 GA)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found