Skip to content

mergeLocaleMessage in petite 18n broken after 9.6.0 - converts to nested object by itself #1717

@chojnicki

Description

@chojnicki

Reporting a bug?

After upgrading petite-vue-i18n from 9.5.0 translations on app broke (messages not found).

I'm using simple key, not nested objects (by default in petite).

Screenshot from 2024-01-29 19-40-26

Translations are lazy loaded from .json files and merged.

const messages = await import(`./locales/${category}/${locale}.json`)
i18n.global.mergeLocaleMessage(locale, messages.default)

I debugged it via i18n.global.getLocaleMessage('pl') and noticed that my translations are nested, WTF :D

Screenshot from 2024-01-29 19-36-28

By downgrading version after version I discovered that issue is with 9.6.0, and noticed noticed this commit in changelog:
edaf498

Using flatConfig in i18n config does not help, and I guess should not be used in petite anyway.

I've commented this line in petite-vue-i18n dist source:

handleFlatJson(_message[key]);

and it works.

Then I noticed that in setLocaleMessage there is condition

if (flatJson) {

for that handleFlatJson, but it's missing in mergeLocaleMessage. Why? After adding this, again everything works. Was this on purpose? I case this is a typo, I will provide pull request. If not - @kazupon please provide other solution :(

Expected behavior

Keys like 'a.b.c' should be treated like strings, not transformed into object.

Reproduction

Described above.

System Info

Described above.

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