@r2digisolutions/ui 0.0.1 → 0.2.0

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.
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
- export {};
1
+ export * from './stores/I18n.svelte.js';
2
+ export * from './settings/index.js';
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";
2
- // Reexport your entry components here
1
+ export * from './stores/I18n.svelte.js';
2
+ export * from './settings/index.js';
@@ -0,0 +1,2 @@
1
+ import { StoreI18n } from "../stores/I18n.svelte.js";
2
+ export declare const i18n: StoreI18n;
@@ -0,0 +1,2 @@
1
+ import { StoreI18n } from "../stores/I18n.svelte.js";
2
+ export const i18n = new StoreI18n("en", {});
@@ -0,0 +1,10 @@
1
+ export type I18nTranslationType = Record<string, Record<string, string>>;
2
+ export declare class StoreI18n {
3
+ #private;
4
+ constructor(currentLanguage: string, translations?: I18nTranslationType);
5
+ t: (key: string, params?: Record<string, string>) => string;
6
+ get language(): string;
7
+ set language(value: string);
8
+ get translations(): I18nTranslationType;
9
+ set translations(value: I18nTranslationType);
10
+ }
@@ -0,0 +1,34 @@
1
+ export class StoreI18n {
2
+ #language = $state("en");
3
+ #translations = $state({});
4
+ constructor(currentLanguage, translations = {}) {
5
+ this.#language = currentLanguage;
6
+ this.#translations = translations;
7
+ }
8
+ t = $derived.by(() => {
9
+ this.#language;
10
+ this.#translations;
11
+ return (key, params = {}) => {
12
+ const translations = this.#translations[this.#language];
13
+ const translation = translations[key];
14
+ if (!translation) {
15
+ return `--${key}--`;
16
+ }
17
+ return Object.entries(params).reduce((acc, [key, value]) => {
18
+ return acc.replace(`{${key}}`, value);
19
+ }, translation);
20
+ };
21
+ });
22
+ get language() {
23
+ return this.#language;
24
+ }
25
+ set language(value) {
26
+ this.#language = value;
27
+ }
28
+ get translations() {
29
+ return this.#translations;
30
+ }
31
+ set translations(value) {
32
+ this.#translations = value;
33
+ }
34
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r2digisolutions/ui",
3
- "version": "0.0.1",
3
+ "version": "0.2.0",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -16,7 +16,9 @@
16
16
  "test": "npm run test:unit -- --run && npm run test:e2e",
17
17
  "test:e2e": "playwright test",
18
18
  "storybook": "storybook dev -p 6006",
19
- "build-storybook": "storybook build"
19
+ "build-storybook": "storybook build",
20
+ "changeset": "changeset",
21
+ "changeset:deploy": "changeset version"
20
22
  },
21
23
  "files": [
22
24
  "dist",
@@ -54,7 +56,9 @@
54
56
  "@sveltejs/kit": "^2.15.1",
55
57
  "@sveltejs/package": "^2.3.7",
56
58
  "@sveltejs/vite-plugin-svelte": "^5.0.3",
59
+ "@vitest/browser": "^2.1.8",
57
60
  "autoprefixer": "^10.4.20",
61
+ "changeset": "^0.2.6",
58
62
  "eslint": "^9.17.0",
59
63
  "eslint-config-prettier": "^9.1.0",
60
64
  "eslint-plugin-svelte": "^2.46.1",