Merge remote-tracking branch 'origin/master'

This commit is contained in:
M_Kececi
2026-04-16 15:18:44 +03:00
parent 1831c45a0c
commit 2d369e7d7d
40 changed files with 3477 additions and 97 deletions

View File

@@ -0,0 +1,42 @@
import { computed } from 'vue'
import { messages } from 'src/i18n/messages'
import { DEFAULT_LOCALE } from 'src/i18n/languages'
import { useLocaleStore } from 'src/stores/localeStore'
function lookup(obj, path) {
return String(path || '')
.split('.')
.filter(Boolean)
.reduce((acc, key) => (acc && acc[key] != null ? acc[key] : undefined), obj)
}
export function useI18n() {
const localeStore = useLocaleStore()
const currentLocale = computed(() => localeStore.locale)
function fallbackLocales(locale) {
const normalized = String(locale || '').toLowerCase()
if (normalized === 'tr') return ['tr']
if (normalized === 'en') return ['en', 'tr']
return [normalized, 'en', 'tr']
}
function t(key) {
for (const locale of fallbackLocales(currentLocale.value)) {
const val = lookup(messages[locale] || {}, key)
if (val != null) return val
}
const byDefault = lookup(messages[DEFAULT_LOCALE] || {}, key)
if (byDefault != null) return byDefault
return key
}
return {
locale: currentLocale,
t
}
}