Loading files
54d761463This file is pinned to the selected release. Download the original to open it in your design tool.
Files from this revision, including CAD and LFS contents. Git history is not included.
Or in GitHub Desktop, choose File → Clone repository → URL and paste this address.
Public repositories can be cloned without signing in. For pushing, use your ThingAtlas username and a Git access token as the password.
git lfs install git clone https://thingatlas.com/git/-unclaimed/stack-chan-374381865.git
Includes Git history, branches, and Git LFS files. Clones the repository’s default branch, regardless of the version shown here.
54d761463This file is pinned to the selected release. Download the original to open it in your design tool.
import { type Locale } from './catalogs'
export const LOCALE_STORAGE_KEY = 'stackchan.locale'
export const DEFAULT_LOCALE: Locale = 'ja'
export const normalizeLocale = (locale: unknown): Locale | null => {
if (typeof locale !== 'string') return null
const normalized = locale.trim().replaceAll('_', '-').toLowerCase()
if (normalized === 'ja' || normalized.startsWith('ja-')) return 'ja'
if (normalized === 'en' || normalized.startsWith('en-')) return 'en'
if (normalized === 'zh' || normalized.startsWith('zh-')) return 'zh-CN'
return null
}
const storedLocale = () => {
try {
return globalThis.localStorage?.getItem(LOCALE_STORAGE_KEY) ?? null
} catch {
return null
}
}
export const resolveLocale = ({
stored = storedLocale(),
browser = globalThis.navigator?.languages ?? [],
}: {
stored?: string | null
browser?: readonly string[]
} = {}): Locale => {
const explicit = normalizeLocale(stored)
if (explicit) return explicit
for (const candidate of browser) {
const matched = normalizeLocale(candidate)
if (matched) return matched
}
return DEFAULT_LOCALE
}