mirror of
https://github.com/cupcakearmy/svelte-i18n.git
synced 2024-06-30 18:54:49 +02:00
chore: 🤖 remove unused file
This commit is contained in:
parent
25f85c556f
commit
ff088f50e2
|
@ -1,59 +0,0 @@
|
||||||
import { GetClientLocaleOptions } from '../types'
|
|
||||||
|
|
||||||
const getFromQueryString = (queryString: string, key: string) => {
|
|
||||||
const keyVal = queryString.split('&').find(i => i.indexOf(`${key}=`) === 0)
|
|
||||||
|
|
||||||
if (keyVal) {
|
|
||||||
return keyVal.split('=').pop()
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
const getFirstMatch = (base: string, pattern: RegExp) => {
|
|
||||||
const match = pattern.exec(base)
|
|
||||||
// istanbul ignore if
|
|
||||||
if (!match) return null
|
|
||||||
// istanbul ignore else
|
|
||||||
return match[1] || null
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getClientLocale = ({
|
|
||||||
navigator,
|
|
||||||
hash,
|
|
||||||
search,
|
|
||||||
pathname,
|
|
||||||
hostname,
|
|
||||||
}: GetClientLocaleOptions) => {
|
|
||||||
let locale
|
|
||||||
|
|
||||||
// istanbul ignore next
|
|
||||||
if (typeof window === 'undefined') return null
|
|
||||||
|
|
||||||
if (hostname) {
|
|
||||||
locale = getFirstMatch(window.location.hostname, hostname)
|
|
||||||
if (locale) return locale
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pathname) {
|
|
||||||
locale = getFirstMatch(window.location.pathname, pathname)
|
|
||||||
if (locale) return locale
|
|
||||||
}
|
|
||||||
|
|
||||||
if (navigator) {
|
|
||||||
// istanbul ignore else
|
|
||||||
locale = window.navigator.language || window.navigator.languages[0]
|
|
||||||
if (locale) return locale
|
|
||||||
}
|
|
||||||
|
|
||||||
if (search) {
|
|
||||||
locale = getFromQueryString(window.location.search.substr(1), search)
|
|
||||||
if (locale) return locale
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hash) {
|
|
||||||
locale = getFromQueryString(window.location.hash.substr(1), hash)
|
|
||||||
if (locale) return locale
|
|
||||||
}
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user