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

Unescape single quotes when writing language files #220

Open
daniel-jann opened this issue Oct 17, 2024 · 1 comment
Open

Unescape single quotes when writing language files #220

daniel-jann opened this issue Oct 17, 2024 · 1 comment

Comments

@daniel-jann
Copy link

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."
}
@daniel-jann
Copy link
Author

BTW, a workaround would be to use template literals like so:

<span :title="$t(`Here's a text that won't generate an issue.`)">

It'll work until you need to do something like

<span :title="$t(`Template literals use the ${variable} notation to include a variable`)">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant