Skip to content

Commit

Permalink
add basic node example
Browse files Browse the repository at this point in the history
  • Loading branch information
m10rten committed Aug 18, 2024
1 parent 61529fc commit 576b981
Show file tree
Hide file tree
Showing 3 changed files with 412 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/i4n-node/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { I4n } from "i4n";

interface LanguageData {
hello: string;
key?: string;
}
type Language = "en" | "nl";
type TranslationSet = {
[lang in Language]?: LanguageData;
};

export const translations = {
en: {
hello: "Hello World!",
key: "Somehow we do",
},
nl: {
hello: "Hallo Wereld!",
},
} satisfies TranslationSet;

const i4n = new I4n({ translations, language: "en", fallbackLanguage: "en" });

console.log(i4n.t("hello")); // "Hello"

console.log("Swapping", i4n.switch("nl"));

console.log(i4n.t("hello"));

console.log(i4n.t("key"));
20 changes: 20 additions & 0 deletions examples/i4n-node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "i4n-node",
"version": "1.0.0",
"description": "",
"main": "main.ts",
"scripts": {
"start": "tsx main.ts"
},
"keywords": [],
"author": "",
"license": "",
"devDependencies": {
"@types/node": "^22.4.0",
"tsx": "^4.17.0",
"typescript": "^5.5.4"
},
"dependencies": {
"i4n": "^0.3.2"
}
}
Loading

0 comments on commit 576b981

Please sign in to comment.