import { STORAGE } from '@/core/constants/storage-keys'

const DEFAULT_LOCALE = 'zh-Hant'

export function bootstrapLocale(i18n, isAndroid) {
	const saved = uni.getStorageSync(STORAGE.language)
	if (!saved) {
		uni.setStorageSync(STORAGE.language, DEFAULT_LOCALE)
		uni.setLocale(DEFAULT_LOCALE)
		if (!isAndroid && i18n) i18n.locale = DEFAULT_LOCALE
		return DEFAULT_LOCALE
	}
	uni.setLocale(saved)
	if (!isAndroid && i18n) i18n.locale = saved
	return saved
}
