Skip to content

Unable to pass default value using $t() #644

@kkyryl

Description

@kkyryl

Reporting a bug?

There's a very high probability of me simply misunderstanding how it's supposed to work but after some debugging I was not able to find a way to do that.

Based on the documentation we should be able to call:

$t("translation.key", "default value")

However the "default value" is always interpreted as a locale key.
Next I tried:

$t("translation.key", null, {default: "default value")})

But options object is never taken into consideration.

After some debugging I was able to find what (I believe) is the culprit:
in t(...args) {:

                else if (isPlainObject(arg2)) {
                    named = arg2;
                }
                if (isArray(arg3)) {
                    list = arg3;
                }
                else if (isPlainObject(arg3)) {
                    named = arg3;
                }

Shouldn't it be:

                else if (isPlainObject(arg3)) {
                    assign(options, arg3);
                }

Since named interpolation object is expected as arg2?

This is sort of further confirmed by looking at $rt which passes options object as the third argument further down and after calling $rt with the options object as the third argument i can confirm that options are passed down the line.

Expected behavior

I expect to be able to pass options object or default value when using $t function

Reproduction

To reproduce try passing default value to the $t function

System Info

Using vue-i18n v9.1.6 with vue 3 in the browser context

Screenshot

No response

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions