Skip to content

Commit

Permalink
Merge pull request #110 from dungsil/fix/default-value-notworking
Browse files Browse the repository at this point in the history
fix: `$has` always returns `true`
  • Loading branch information
s00d authored Jan 20, 2025
2 parents 2ea2029 + 2af97f1 commit 31badd7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/runtime/plugins/01.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
const selectedRoute = route ?? routeService.getCurrentRoute()
return routeService.getRouteName(selectedRoute, selectedLocale)
},
t: (key: string, params?: Params, defaultValue?: string): Translation => {
t: (key: string, params?: Params, defaultValue?: string | null): Translation => {
if (!key) return ''
const route = routeService.getCurrentRoute()
const locale = routeService.getCurrentLocale()
Expand All @@ -157,7 +157,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
if (isDev && import.meta.client) {
console.warn(`Not found '${key}' key in '${locale}' locale messages.`)
}
value = defaultValue || key
value = defaultValue === undefined ? key : defaultValue
}

return typeof value === 'string' && params ? interpolate(value, params) : value
Expand Down Expand Up @@ -185,7 +185,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
return translationService.formatRelativeTime(value, currentLocale, options)
},
has: (key: string): boolean => {
return !!provideData.t(key)
return !!provideData.t(key, {}, null)
},
mergeTranslations: (newTranslations: Translations) => {
const route = routeService.getCurrentRoute()
Expand Down

0 comments on commit 31badd7

Please sign in to comment.