Implemented email verification
This commit is contained in:
29
lib/translate.ts
Normal file
29
lib/translate.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { type loc, locales, fallbackLocale } from '@/config/locales'
|
||||
|
||||
export const __c = async (key: string | null | undefined, locale?: loc) => {
|
||||
key = (key ?? '').trim()
|
||||
if (key.length === 0) return key
|
||||
|
||||
if (!locales.includes(locale ??= fallbackLocale)) {
|
||||
locale = fallbackLocale
|
||||
}
|
||||
|
||||
let data: any = await import(`@/locales/custom.${locale}`).then(({ default: data }) => data).catch(() => false)
|
||||
if (data === false) return key
|
||||
|
||||
const x = key.split('.')
|
||||
let c: number = x.length
|
||||
|
||||
if (c === 1) {
|
||||
return data.hasOwn(x[0]) && typeof data[x[0]] === 'string' ? data[x[0]] : key
|
||||
}
|
||||
|
||||
for (let i in x) {
|
||||
if (data.hasOwn(x[i])) {
|
||||
data = data[x[i]]
|
||||
c--
|
||||
}
|
||||
}
|
||||
|
||||
return c === 0 ? data : key
|
||||
}
|
||||
Reference in New Issue
Block a user