zavadil-ts-common 1.1.94 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,26 @@
1
+ export type TranslateParams = {
2
+ tags?: Array<string>;
3
+ };
4
+ export interface Dictionary {
5
+ translate: (key: string, p?: TranslateParams) => string | undefined;
6
+ }
7
+ export interface DictionaryMemoryData {
8
+ [key: string]: string;
9
+ }
10
+ export declare class MemoryDictionary implements Dictionary {
11
+ private data;
12
+ constructor(data: DictionaryMemoryData);
13
+ translate(key: string, p?: TranslateParams): string;
14
+ }
15
+ export declare class CzechBasicDictionary extends MemoryDictionary {
16
+ constructor();
17
+ }
18
+ export declare class EnglishBasicDictionary extends MemoryDictionary {
19
+ constructor();
20
+ }
21
+ export declare class DictionaryWithFallback implements Dictionary {
22
+ private primary;
23
+ private fallback;
24
+ constructor(primary: Dictionary, fallback: Dictionary);
25
+ translate(key: string, p?: TranslateParams): string | undefined;
26
+ }
@@ -0,0 +1,13 @@
1
+ import { Dictionary, TranslateParams } from "./Dictionary";
2
+ export declare class Localization implements Dictionary {
3
+ private language;
4
+ private dictionaries;
5
+ constructor(language?: string);
6
+ addDictionary(language: string, dictionary: Dictionary): void;
7
+ hasDictionary(language?: string): boolean;
8
+ setLanguage(language?: string): void;
9
+ translate(key: string, p?: TranslateParams): string | undefined;
10
+ }
11
+ export declare class BasicLocalization extends Localization {
12
+ constructor();
13
+ }
@@ -0,0 +1,2 @@
1
+ export * from './Dictionary';
2
+ export * from './Localization';
@@ -0,0 +1,3 @@
1
+ import { DictionaryMemoryData } from "../Dictionary";
2
+ export declare const CzechBasicData: DictionaryMemoryData;
3
+ export declare const EnglishBasicData: DictionaryMemoryData;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zavadil-ts-common",
3
- "version": "1.1.94",
3
+ "version": "1.2.1",
4
4
  "description": "Common types and components for Typescript UI apps.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
@@ -16,6 +16,7 @@
16
16
  "@rollup/plugin-node-resolve": "15.2.3",
17
17
  "@rollup/plugin-terser": "0.4.4",
18
18
  "@rollup/plugin-typescript": "12.1.0",
19
+ "@rollup/plugin-json": "^6.1.0",
19
20
  "@types/jest": "^29.5.14",
20
21
  "jest": "^29.7.0",
21
22
  "rollup": "4.30.1",
package/rollup.config.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import resolve from "@rollup/plugin-node-resolve";
2
2
  import commonjs from "@rollup/plugin-commonjs";
3
3
  import typescript from "@rollup/plugin-typescript";
4
+ import json from "@rollup/plugin-json";
4
5
  import dts from "rollup-plugin-dts";
5
6
  import terser from "@rollup/plugin-terser";
6
7
 
@@ -22,6 +23,7 @@ export default [
22
23
  plugins: [
23
24
  resolve({ extensions: ['.js', '.ts'] }),
24
25
  commonjs(),
26
+ json(),
25
27
  typescript({
26
28
  tsconfig: "./tsconfig.json",
27
29
  exclude: [
@@ -0,0 +1,58 @@
1
+ import {CzechBasicData, EnglishBasicData} from './lang';
2
+
3
+ export type TranslateParams = {
4
+ tags?: Array<string>;
5
+ }
6
+
7
+ export interface Dictionary {
8
+ translate: (key: string, p?: TranslateParams) => string | undefined;
9
+ }
10
+
11
+ export interface DictionaryMemoryData {
12
+ [key: string]: string;
13
+ }
14
+
15
+ export class MemoryDictionary implements Dictionary {
16
+
17
+ private data: DictionaryMemoryData;
18
+
19
+ constructor(data: DictionaryMemoryData) {
20
+ this.data = data;
21
+
22
+ }
23
+
24
+ translate(key: string, p?: TranslateParams) {
25
+ return this.data[key];
26
+ };
27
+
28
+ }
29
+
30
+ export class CzechBasicDictionary extends MemoryDictionary {
31
+ constructor() {
32
+ super(CzechBasicData);
33
+ }
34
+ }
35
+
36
+ export class EnglishBasicDictionary extends MemoryDictionary {
37
+ constructor() {
38
+ super(EnglishBasicData);
39
+ }
40
+ }
41
+
42
+ export class DictionaryWithFallback implements Dictionary {
43
+
44
+ private primary: Dictionary;
45
+
46
+ private fallback: Dictionary;
47
+
48
+ constructor(primary: Dictionary, fallback: Dictionary) {
49
+ this.primary = primary;
50
+ this.fallback = fallback;
51
+ }
52
+
53
+ translate(key: string, p?: TranslateParams) {
54
+ const pt = this.primary.translate(key, p);
55
+ if (pt === undefined) return this.fallback.translate(key, p);
56
+ return pt;
57
+ };
58
+ }
@@ -0,0 +1,43 @@
1
+ import {CzechBasicDictionary, Dictionary, EnglishBasicDictionary, TranslateParams} from "./Dictionary";
2
+
3
+ export class Localization implements Dictionary {
4
+
5
+ private language: string | undefined;
6
+
7
+ private dictionaries = new Map<string, Dictionary>;
8
+
9
+ constructor(language?: string) {
10
+ this.setLanguage(language);
11
+ }
12
+
13
+ addDictionary(language: string, dictionary: Dictionary) {
14
+ this.dictionaries.set(language, dictionary);
15
+ this.setLanguage();
16
+ }
17
+
18
+ hasDictionary(language?: string) {
19
+ if (!language) return false;
20
+ return this.dictionaries.has(language);
21
+ }
22
+
23
+ setLanguage(language?: string) {
24
+ this.language = language && this.hasDictionary(language)
25
+ ? language
26
+ : this.hasDictionary(navigator.language) ? navigator.language : undefined
27
+ }
28
+
29
+ translate(key: string, p?: TranslateParams) {
30
+ if (!this.language) return key;
31
+ const d = this.dictionaries.get(this.language);
32
+ if (!d) return key;
33
+ return d.translate(key, p);
34
+ }
35
+ }
36
+
37
+ export class BasicLocalization extends Localization {
38
+ constructor() {
39
+ super();
40
+ this.addDictionary("cs", new CzechBasicDictionary());
41
+ this.addDictionary("en", new EnglishBasicDictionary());
42
+ }
43
+ }
@@ -0,0 +1,3 @@
1
+ export * from './Dictionary';
2
+ export * from './Localization';
3
+
@@ -0,0 +1,14 @@
1
+ {
2
+ "Anonymous": "Anonym",
3
+ "Administrator": "Administrátor",
4
+ "Validate": "Validovat",
5
+ "Back": "Zpět",
6
+ "Started": "Začátek",
7
+ "Finished": "Konec",
8
+ "Duration": "Trvání",
9
+ "Processing Time": "Doba zpracování",
10
+ "Status": "Stav",
11
+ "Page": "Stránka",
12
+ "Page size" : "Velikost stránky",
13
+ "Total items": "Celkem záznamů"
14
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "--welcome-1": "This assistant will help you identify problems and suggest solutions about integration into Incomaker.",
3
+ "--welcome-2": "Are you just starting the integration process? You will find step-by-step instructions in our <a target=\"_blank\" href=\"https://docs.google.com/document/d/1ogmxMWez5p0T8Y29eljKuOT8wqZMsdGpeFjltChOGe4/edit#heading=h.3h0ab7s9db51\">integration manual</a>.",
4
+ "--welcome-3": "Are you implementing the XML feed on your own? For detailed information about our standard schema check <a target=\"_blank\" href=\"https://github.com/incomaker/xml-feed-standards\">XML feed documentation</a>.",
5
+ "--api-key-hint": "To obtain an API key, you must log into your account on <a target=\"_blank\" href=\"https://my.incomaker.com/admin/plugin_profile.xhtml\">my.incomaker.com</a> and go to <strong>E&#8209;shop Info</strong> tab."
6
+ }
@@ -0,0 +1,5 @@
1
+ import { readFileSync } from 'fs';
2
+ import {DictionaryMemoryData} from "../Dictionary";
3
+
4
+ export const CzechBasicData : DictionaryMemoryData = JSON.parse(readFileSync(new URL('./dictionary.cs.json', import.meta.url), 'utf8'));
5
+ export const EnglishBasicData : DictionaryMemoryData = JSON.parse(readFileSync(new URL('./dictionary.en.json', import.meta.url), 'utf8'));