@r2digisolutions/ui 0.5.1 → 0.6.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.
@@ -1,5 +1,6 @@
1
1
  export class StoreI18n {
2
2
  #language = $state("en");
3
+ #defaultLanguage = "en";
3
4
  #translations = $state({});
4
5
  constructor(currentLanguage, translations = {}) {
5
6
  this.#language = currentLanguage;
@@ -9,9 +10,9 @@ export class StoreI18n {
9
10
  this.#language;
10
11
  this.#translations;
11
12
  return (key, params = {}) => {
12
- const translations = this.#translations[this.#language];
13
- const translation = translations[key];
14
- if (!translation) {
13
+ const translations = this.#translations?.[this.#language || this.#defaultLanguage];
14
+ const translation = this.#getTranslationValue(translations, key);
15
+ if (!translation || typeof translation !== "string") {
15
16
  return `--${key}--`;
16
17
  }
17
18
  return Object.entries(params).reduce((acc, [key, value]) => {
@@ -23,6 +24,13 @@ export class StoreI18n {
23
24
  this.#language = language;
24
25
  this.#translations = translations;
25
26
  }
27
+ #getTranslationValue(translations, key) {
28
+ // Intentar primero como clave plana
29
+ if (translations?.[key])
30
+ return translations[key];
31
+ // Si no existe como clave plana, intentar lookup recursivo
32
+ return key.split('.').reduce((acc, part) => acc?.[part], translations);
33
+ }
26
34
  get language() {
27
35
  return this.#language;
28
36
  }
@@ -1 +1,4 @@
1
- export type I18nTranslationType = Record<string, Record<string, string>>;
1
+ export type NestedTranslations = string | {
2
+ [key: string]: NestedTranslations;
3
+ };
4
+ export type I18nTranslationType = Record<string, NestedTranslations>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r2digisolutions/ui",
3
- "version": "0.5.1",
3
+ "version": "0.6.1",
4
4
  "private": false,
5
5
  "packageManager": "bun@1.2.8",
6
6
  "publishConfig": {
@@ -70,6 +70,7 @@
70
70
  "eslint-plugin-svelte": "^3.8.0",
71
71
  "globals": "^16.1.0",
72
72
  "jsdom": "^26.1.0",
73
+ "lucide-svelte": "^0.511.0",
73
74
  "prettier": "^3.5.3",
74
75
  "prettier-plugin-svelte": "^3.4.0",
75
76
  "prettier-plugin-tailwindcss": "^0.6.11",