vue-i18n datetime format fallback locale missing error
Covers the vue-i18n datetime format fallback warning: define the same format keys for fallback locales. Use it when the console warns about an undefined fallback format. Not for wrong format patterns.
Fix vue-i18n datetime format fallback locale missing error
TL;DR
You defined datetime formats for the main locale but not the fallback, so add matching datetimeFormats for the fallback locale. When the active locale has no format for a key, vue-i18n falls back to the fallback locale, and if that has no format either it warns. Define the same format keys for every fallback locale you configure.
The error
[vue-i18n] Fall back to datetime format "short" of "en" but it is not defined
d(new Date(), 'short') with locale fr, fallbackLocale enFix it
Step 1: List the datetime formats you defined per locale
grep -n "datetimeFormats" -A 12 src/i18n.js | head -20Expected: You see which locales have formats and which are missing.
Step 2: Add the missing format keys to the fallback locale
node -e "console.log('add to datetimeFormats.en: short, long, whatever keys fr uses')"Expected: Every format key used exists under the fallback locale too.
Step 3: Reload and format a date in the secondary locale
node -e "console.log('call d(new Date(), \"short\") with locale fr, no warning appears')"Expected: The fallback warning is gone and the date formats.
Step 4: Audit all format keys across locales
node -e "console.log('script: collect format keys per locale, report any key missing from a fallback locale')"Expected: No key is missing from any fallback locale.
When to use this
- vue-i18n warns about falling back to a datetime format that is not defined
- Dates render in the wrong format for secondary locales
When NOT to use this
- The format exists but the date is wrong, check the format pattern itself
- Number formats warn the same way, apply the same fix to numberFormats
Tool and version compatibility
- vue-i18n v9 (Vue 3), datetimeFormats option
- Fallback chains with fallbackLocale set
Variant phrasings
same warning for number formats
Identical fix under numberFormats. Keep datetime and number format keys in sync across locales.
fallback locale itself falls back further
Chains like fr to en to root need the format at the end of the chain. Define it on the final fallback.
Why it happens
vue-i18n resolves formats per locale, then walks the fallback chain. The warning fires when the walk reaches a locale that also lacks the format key. Defining formats only for the primary locale leaves every fallback lookup empty.
Edge cases
- Format keys are case sensitive, Short and short are different keys
- Lazy-loaded locales need their formats registered when the locale loads, not at init
- Custom format functions receive the fallback context, make them locale-agnostic
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_GEcXrjs4aQ6fvbE2YBknsg
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.