vue-i18n icon indicating copy to clipboard operation
vue-i18n copied to clipboard

Vue-i18n Parameter Replacement Issue: $t Function Not Replacing Parameters in Message String

Open manjindersinghsarkaria opened this issue 9 months ago • 1 comments

Reporting a bug?

const messages = { en: { message: { hello: "Hello {0} world" } } };

$t("message.hello", {'0': "my" })

The expected output needs to be "Hello my world" But I am getting a string "Hello world" The same example works fine if I do it like this

const messages = { en: { message: { hello: "Hello {item} world" } } };

$t("message.hello", {'item': "my" })

The version I am on is 9.6.4 Am I doing anything wrong? I tried the same with the version 8.22.3 and it is working fine.

Expected behavior

The code below const messages = { en: { message: { hello: "Hello {0} world" } } };

$t("message.hello", {'0': "my" })

should return Hello my world not Hello world

Reproduction

Create a message string with parameter name {0} and then try to replace the parameter with the value something like {'0': "my" }

System Info

{
  "name": "i18n-test",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview"
  },
  "dependencies": {
    "vue": "^3.3.4",
    "vue-i18n": "^9.6.4"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^4.4.0",
    "vite": "^4.4.11"
  }
}

Screenshot

Screenshot_20 Screenshot_22 Screenshot_23 Screenshot_24

Additional context

No response

Validations

manjindersinghsarkaria avatar Nov 02 '23 19:11 manjindersinghsarkaria