aboutsummaryrefslogtreecommitdiffstats
path: root/src/i18n
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2023-02-11 23:37:12 +0100
committerivarlovlie <git@ivarlovlie.no>2023-02-11 23:37:12 +0100
commit9b2c63d92ff77ebce0f90a7be05437504422bf45 (patch)
tree682447cde9d3eed555973ff1aff369b4443da07f /src/i18n
parent23ab0a24ba82004fa449491b4e08698a1de9e6a0 (diff)
downloadauroraklinikken.no-9b2c63d92ff77ebce0f90a7be05437504422bf45.tar.xz
auroraklinikken.no-9b2c63d92ff77ebce0f90a7be05437504422bf45.zip
feat: Render localized content from sanity
Diffstat (limited to 'src/i18n')
-rw-r--r--src/i18n/en/index.ts13
-rw-r--r--src/i18n/formatters.ts11
-rw-r--r--src/i18n/i18n-svelte.ts12
-rw-r--r--src/i18n/i18n-types.ts66
-rw-r--r--src/i18n/i18n-util.async.ts27
-rw-r--r--src/i18n/i18n-util.sync.ts26
-rw-r--r--src/i18n/i18n-util.ts38
-rw-r--r--src/i18n/nb/index.ts13
8 files changed, 206 insertions, 0 deletions
diff --git a/src/i18n/en/index.ts b/src/i18n/en/index.ts
new file mode 100644
index 0000000..796f4a5
--- /dev/null
+++ b/src/i18n/en/index.ts
@@ -0,0 +1,13 @@
+import type { BaseTranslation } from '../i18n-types'
+
+const en = {
+ contact: {
+ title: "Contact us",
+ addressTitle: "Address",
+ emailTitle: "Email",
+ phoneTitle: "Phone"
+ },
+ homeTitle: "Home",
+} satisfies BaseTranslation
+
+export default en
diff --git a/src/i18n/formatters.ts b/src/i18n/formatters.ts
new file mode 100644
index 0000000..78734f9
--- /dev/null
+++ b/src/i18n/formatters.ts
@@ -0,0 +1,11 @@
+import type { FormattersInitializer } from 'typesafe-i18n'
+import type { Locales, Formatters } from './i18n-types'
+
+export const initFormatters: FormattersInitializer<Locales, Formatters> = (locale: Locales) => {
+
+ const formatters: Formatters = {
+ // add your formatter functions here
+ }
+
+ return formatters
+}
diff --git a/src/i18n/i18n-svelte.ts b/src/i18n/i18n-svelte.ts
new file mode 100644
index 0000000..6cdffb3
--- /dev/null
+++ b/src/i18n/i18n-svelte.ts
@@ -0,0 +1,12 @@
+// This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten.
+/* eslint-disable */
+
+import { initI18nSvelte } from 'typesafe-i18n/svelte'
+import type { Formatters, Locales, TranslationFunctions, Translations } from './i18n-types'
+import { loadedFormatters, loadedLocales } from './i18n-util'
+
+const { locale, LL, setLocale } = initI18nSvelte<Locales, Translations, TranslationFunctions, Formatters>(loadedLocales, loadedFormatters)
+
+export { locale, LL, setLocale }
+
+export default LL
diff --git a/src/i18n/i18n-types.ts b/src/i18n/i18n-types.ts
new file mode 100644
index 0000000..9a32b2f
--- /dev/null
+++ b/src/i18n/i18n-types.ts
@@ -0,0 +1,66 @@
+// This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten.
+/* eslint-disable */
+import type { BaseTranslation as BaseTranslationType, LocalizedString } from 'typesafe-i18n'
+
+export type BaseTranslation = BaseTranslationType
+export type BaseLocale = 'en'
+
+export type Locales =
+ | 'en'
+ | 'nb'
+
+export type Translation = RootTranslation
+
+export type Translations = RootTranslation
+
+type RootTranslation = {
+ contact: {
+ /**
+ * C​o​n​t​a​c​t​ ​u​s
+ */
+ title: string
+ /**
+ * A​d​d​r​e​s​s
+ */
+ addressTitle: string
+ /**
+ * E​m​a​i​l
+ */
+ emailTitle: string
+ /**
+ * P​h​o​n​e
+ */
+ phoneTitle: string
+ }
+ /**
+ * H​o​m​e
+ */
+ homeTitle: string
+}
+
+export type TranslationFunctions = {
+ contact: {
+ /**
+ * Contact us
+ */
+ title: () => LocalizedString
+ /**
+ * Address
+ */
+ addressTitle: () => LocalizedString
+ /**
+ * Email
+ */
+ emailTitle: () => LocalizedString
+ /**
+ * Phone
+ */
+ phoneTitle: () => LocalizedString
+ }
+ /**
+ * Home
+ */
+ homeTitle: () => LocalizedString
+}
+
+export type Formatters = {}
diff --git a/src/i18n/i18n-util.async.ts b/src/i18n/i18n-util.async.ts
new file mode 100644
index 0000000..3f38e3e
--- /dev/null
+++ b/src/i18n/i18n-util.async.ts
@@ -0,0 +1,27 @@
+// This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten.
+/* eslint-disable */
+
+import { initFormatters } from './formatters'
+import type { Locales, Translations } from './i18n-types'
+import { loadedFormatters, loadedLocales, locales } from './i18n-util'
+
+const localeTranslationLoaders = {
+ en: () => import('./en'),
+ nb: () => import('./nb'),
+}
+
+const updateDictionary = (locale: Locales, dictionary: Partial<Translations>): Translations =>
+ loadedLocales[locale] = { ...loadedLocales[locale], ...dictionary }
+
+export const importLocaleAsync = async (locale: Locales): Promise<Translations> =>
+ (await localeTranslationLoaders[locale]()).default as unknown as Translations
+
+export const loadLocaleAsync = async (locale: Locales): Promise<void> => {
+ updateDictionary(locale, await importLocaleAsync(locale))
+ loadFormatters(locale)
+}
+
+export const loadAllLocalesAsync = (): Promise<void[]> => Promise.all(locales.map(loadLocaleAsync))
+
+export const loadFormatters = (locale: Locales): void =>
+ void (loadedFormatters[locale] = initFormatters(locale))
diff --git a/src/i18n/i18n-util.sync.ts b/src/i18n/i18n-util.sync.ts
new file mode 100644
index 0000000..f1a8e9e
--- /dev/null
+++ b/src/i18n/i18n-util.sync.ts
@@ -0,0 +1,26 @@
+// This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten.
+/* eslint-disable */
+
+import { initFormatters } from './formatters'
+import type { Locales, Translations } from './i18n-types'
+import { loadedFormatters, loadedLocales, locales } from './i18n-util'
+
+import en from './en'
+import nb from './nb'
+
+const localeTranslations = {
+ en,
+ nb,
+}
+
+export const loadLocale = (locale: Locales): void => {
+ if (loadedLocales[locale]) return
+
+ loadedLocales[locale] = localeTranslations[locale] as unknown as Translations
+ loadFormatters(locale)
+}
+
+export const loadAllLocales = (): void => locales.forEach(loadLocale)
+
+export const loadFormatters = (locale: Locales): void =>
+ void (loadedFormatters[locale] = initFormatters(locale))
diff --git a/src/i18n/i18n-util.ts b/src/i18n/i18n-util.ts
new file mode 100644
index 0000000..0d1cef0
--- /dev/null
+++ b/src/i18n/i18n-util.ts
@@ -0,0 +1,38 @@
+// This file was auto-generated by 'typesafe-i18n'. Any manual changes will be overwritten.
+/* eslint-disable */
+
+import { i18n as initI18n, i18nObject as initI18nObject, i18nString as initI18nString } from 'typesafe-i18n'
+import type { LocaleDetector } from 'typesafe-i18n/detectors'
+import type { LocaleTranslationFunctions, TranslateByString } from 'typesafe-i18n'
+import { detectLocale as detectLocaleFn } from 'typesafe-i18n/detectors'
+import { initExtendDictionary } from 'typesafe-i18n/utils'
+import type { Formatters, Locales, Translations, TranslationFunctions } from './i18n-types'
+
+export const baseLocale: Locales = 'en'
+
+export const locales: Locales[] = [
+ 'en',
+ 'nb'
+]
+
+export const isLocale = (locale: string): locale is Locales => locales.includes(locale as Locales)
+
+export const loadedLocales: Record<Locales, Translations> = {} as Record<Locales, Translations>
+
+export const loadedFormatters: Record<Locales, Formatters> = {} as Record<Locales, Formatters>
+
+export const extendDictionary = initExtendDictionary<Translations>()
+
+export const i18nString = (locale: Locales): TranslateByString => initI18nString<Locales, Formatters>(locale, loadedFormatters[locale])
+
+export const i18nObject = (locale: Locales): TranslationFunctions =>
+ initI18nObject<Locales, Translations, TranslationFunctions, Formatters>(
+ locale,
+ loadedLocales[locale],
+ loadedFormatters[locale]
+ )
+
+export const i18n = (): LocaleTranslationFunctions<Locales, Translations, TranslationFunctions> =>
+ initI18n<Locales, Translations, TranslationFunctions, Formatters>(loadedLocales, loadedFormatters)
+
+export const detectLocale = (...detectors: LocaleDetector[]): Locales => detectLocaleFn<Locales>(baseLocale, locales, ...detectors)
diff --git a/src/i18n/nb/index.ts b/src/i18n/nb/index.ts
new file mode 100644
index 0000000..9e13fba
--- /dev/null
+++ b/src/i18n/nb/index.ts
@@ -0,0 +1,13 @@
+import type { Translation } from '../i18n-types'
+
+const nb = {
+ contact: {
+ title: "Kontakt oss",
+ addressTitle: "Adresse",
+ emailTitle: "E-postadresse",
+ phoneTitle: "Telefon"
+ },
+ homeTitle: "Hjem",
+} satisfies Translation
+
+export default nb