Skip to content

Instantly share code, notes, and snippets.

@rajibahmed
Created August 1, 2021 17:19
Show Gist options
  • Select an option

  • Save rajibahmed/aea146cf82d86e15c19cfd7ca8e3c3a7 to your computer and use it in GitHub Desktop.

Select an option

Save rajibahmed/aea146cf82d86e15c19cfd7ca8e3c3a7 to your computer and use it in GitHub Desktop.

Revisions

  1. rajibahmed created this gist Aug 1, 2021.
    26 changes: 26 additions & 0 deletions i18n.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    const translations = {
    en: {
    searchLable: 'Add to',
    addProduct: 'Add product',
    menuHeader: 'MENU',
    searchHeader: 'SEARCH',
    },
    sv: {
    searchLable: 'Lägg till vara',
    addProduct: 'Lägg till',
    menuHeader: 'MENY',
    searchHeader: 'LÄGG TILL',
    },
    };

    type TranslationType = typeof translations;
    type LanguageKeys = keyof TranslationType;
    type TranslationKeys = keyof TranslationType['en'];

    const translate = (translations: TranslationType) => (lang: LanguageKeys) => (
    key: TranslationKeys
    ) => {
    return translations[lang][key];
    };

    export const t = translate(translations)('sv');