Skip to content

Unescape single quotes when writing language files #220

Open
@daniel-jann

Description

@daniel-jann

vue-i18n allows using texts as keys in translation files (eg "This is my text": "This is my text"). It does however mean that we sometimes need escape characters:

$t("A text with \"double quotes\" characters")
<span :title="$t('Here\'s a text that will generate an issue.')">

The vue-i18n-extract will add these strings like so in the translation files (JSON for instance, using noEmptyTranslation and a pipe as separator to avoid nesting keys on dots):

{
  "A text with \"double quotes\" characters": "A text with \"double quotes\" characters",
  "Here\\'s a text that will generate an issue.": "Here\\'s a text that will generate an issue."
}

The first one with double quotes is escaped correctly, but the second one with single quotes is not, and is (rightly so) not picked up by vue-i18n to match the text used in the $t function. Instead it should be extracted to:

{
  "A text with \"double quotes\" characters": "A text with \"double quotes\" characters",
  "Here's a text that will generate an issue.": "Here's a text that will generate an issue."
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions