Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 1x 2x 2x 2x 2x 2x 2x 2x 1x 6x 6x 5x 1x 6x 6x 5x 5x 6x 6x 1x 1x | import type { Composer } from 'vue-i18n'
export function translateOrFallback(
t: Composer['t'],
key: string,
fallback: string
): string {
const translated = t(key)
return translated === key ? fallback : translated
}
export const getBrowserLocale = (fallback = 'ja'): string => {
if (typeof navigator === 'undefined') return fallback
const candidates = navigator.languages?.length
? navigator.languages
: [navigator.language]
for (const candidate of candidates) {
if (!candidate) continue
const normalized = candidate.replace('_', '-').trim()
if (!normalized) continue
return normalized.split('-')[0] || fallback
}
return fallback
}
|