Move to TypeScript
This commit is contained in:
@ -1,12 +1,8 @@
|
||||
import { writable, derived } from "svelte/store";
|
||||
import { writable, derived, type Writable } from "svelte/store";
|
||||
|
||||
/** @type {import('svelte/store').Writable<TranslationKey>} */
|
||||
export const language = writable('de');
|
||||
export const language: Writable<TranslationKey> = writable('de');
|
||||
|
||||
/**
|
||||
* @type {Record<TranslationKey, Record<String, String>>}
|
||||
*/
|
||||
const translations = {
|
||||
const translations: Record<TranslationKey, Record<string, string>> = {
|
||||
de: {
|
||||
'gallery': 'Galerie',
|
||||
'album': 'Album',
|
||||
@ -42,11 +38,7 @@ const translations = {
|
||||
};
|
||||
|
||||
export const str = derived(language, $language => {
|
||||
/**
|
||||
* @param {string} key
|
||||
* @param {...any} args
|
||||
*/
|
||||
function translate(key, ...args) {
|
||||
function translate(key: string, ...args: any[]) {
|
||||
const str = translations[$language][key];
|
||||
if (str === undefined) return key;
|
||||
return str.replace(/\{(\d+)\}/g, (_, i) => args[i]);
|
||||
@ -55,11 +47,7 @@ export const str = derived(language, $language => {
|
||||
});
|
||||
|
||||
export const strf = derived(language, $language => {
|
||||
/**
|
||||
* @param {Translation | string} translations
|
||||
* @param {...any} args
|
||||
*/
|
||||
function translate(translations, ...args) {
|
||||
function translate(translations: Translation | string, ...args: any[]) {
|
||||
if (translations === undefined) return undefined;
|
||||
if (typeof translations === 'string') return translations;
|
||||
const str = translations[$language];
|
||||
Reference in New Issue
Block a user