intlify / vue-i18n

Vue I18n for Vue 3
https://vue-i18n.intlify.dev/
MIT License
2.2k stars 337 forks source link

`petite-vue-i18n`: `flatJson` bug (update: actually confusion, not bug) #2011

Open NamesMT opened 2 weeks ago

NamesMT commented 2 weeks ago

Reporting a bug?

petite-vue-i18n cannot work with flatJson enabled, but when disabled, it works fine. See #2010

TL;DR: petite-vue-i18n by default only works with a key:value (flat) json messages format, flatJson will recursively transforms a flat json key into a nested key, which will broke petite-vue-i18n when resolving messages, this is a problem of flatJson description rather than petite-vue-i18n's bug.

Expected behavior

.

Reproduction

import { createI18n } from 'petite-vue-i18n'

// Initialize i18n  
const i18n = createI18n({
  legacy: false,
  flatJson: true,
  locale: 'en',
  fallbackLocale: 'en',
  fallbackWarn: false,
  missingWarn: false,
  messages: {
    en: { 'word.hello': 'Hello' },
  },
})

const test = i18n.global.t('word.hello')

console.log({ test })

Swapping to vue-i18n works fine.

System Info

.

Screenshot

No response

Additional context

No response

Validations