From 21764214c257949844d87e445f1a9f2736a20561 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Fri, 10 Jun 2022 00:35:22 +0200 Subject: feat: Add translations to stopwatch.svelte This commit also demonstrates how to do i18n across apps. --- apps/projects/src/app/lib/i18n/i18n-types.ts | 16 ++++++++++++++++ apps/projects/src/app/lib/i18n/nb/index.ts | 8 ++++---- apps/projects/src/app/lib/stores/locale.ts | 21 --------------------- 3 files changed, 20 insertions(+), 25 deletions(-) delete mode 100644 apps/projects/src/app/lib/stores/locale.ts (limited to 'apps/projects/src/app/lib') diff --git a/apps/projects/src/app/lib/i18n/i18n-types.ts b/apps/projects/src/app/lib/i18n/i18n-types.ts index f9fd9cc..b0031f6 100644 --- a/apps/projects/src/app/lib/i18n/i18n-types.ts +++ b/apps/projects/src/app/lib/i18n/i18n-types.ts @@ -117,6 +117,10 @@ type RootTranslation = { * No categories */ noCategories: string + /** + * Categories + */ + categories: string } settingsLabelsTile: { /** @@ -152,6 +156,10 @@ type RootTranslation = { * No labels */ noLabels: string + /** + * Labels + */ + labels: string } entryForm: { /** @@ -516,6 +524,10 @@ export type TranslationFunctions = { * No categories */ noCategories: () => LocalizedString + /** + * Categories + */ + categories: () => LocalizedString } settingsLabelsTile: { /** @@ -551,6 +563,10 @@ export type TranslationFunctions = { * No labels */ noLabels: () => LocalizedString + /** + * Labels + */ + labels: () => LocalizedString } entryForm: { /** diff --git a/apps/projects/src/app/lib/i18n/nb/index.ts b/apps/projects/src/app/lib/i18n/nb/index.ts index af3a487..28e4bc1 100644 --- a/apps/projects/src/app/lib/i18n/nb/index.ts +++ b/apps/projects/src/app/lib/i18n/nb/index.ts @@ -104,16 +104,16 @@ const nb: Translation = { hourSingleChar: "t", minSingleChar: "m", confirmDeleteEntry: "Er du sikker på at du vil slette denne raden?", - newEntry: "Ny rad", + newEntry: "Ny tidsoppføring", editEntry: "Rediger rad", deleteEntry: "Slett rad", loggedTimeToday: "Registrert tid hittil idag", currentTime: "Klokken", loading: "Laster", stopwatch: "Stoppeklokke", - todayEntries: "Dagens rader", - noEntriesToday: "Ingen rader i dag", - refreshTodayEntries: "Last inn dagens rader på nytt", + todayEntries: "Dagens tidsoppføringer", + noEntriesToday: "Ingen oppføringer i dag", + refreshTodayEntries: "Last inn dagens tidsoppføringer på nytt", category: "Kategori", timespan: "Tidsrom", }, diff --git a/apps/projects/src/app/lib/stores/locale.ts b/apps/projects/src/app/lib/stores/locale.ts deleted file mode 100644 index 1215c20..0000000 --- a/apps/projects/src/app/lib/stores/locale.ts +++ /dev/null @@ -1,21 +0,0 @@ -import {base_domain, CookieNames} from "$shared/lib/configuration"; -import {get_cookie, set_cookie} from "$shared/lib/helpers"; -import {writable} from "svelte/store"; -import type {Locales} from "$app/lib/i18n/i18n-types"; - -export function preffered_or_default(): Locales { - if (/^en\b/i.test(navigator.language)) { - return "en"; - } - if (/^nb\b/i.test(navigator.language) || /^nn\b/i.test(navigator.language)) { - return "nb"; - } - return "en"; -} - -export const currentLocale = writable((get_cookie(CookieNames.locale) ?? preffered_or_default()) as Locales); -currentLocale.subscribe(locale => { - //@ts-ignore - if (locale === "preffered") set_cookie(CookieNames.locale, preffered_or_default(), base_domain()); - set_cookie(CookieNames.locale, locale, base_domain()); -}); -- cgit v1.3