vidply 1.0.4 → 1.0.6

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/src/i18n/i18n.js CHANGED
@@ -1,66 +1,66 @@
1
- /**
2
- * Internationalization system
3
- */
4
-
5
- import { translations } from './translations.js';
6
-
7
- class I18n {
8
- constructor() {
9
- this.currentLanguage = 'en';
10
- this.translations = translations;
11
- }
12
-
13
- setLanguage(lang) {
14
- if (this.translations[lang]) {
15
- this.currentLanguage = lang;
16
- } else {
17
- console.warn(`Language "${lang}" not found, falling back to English`);
18
- this.currentLanguage = 'en';
19
- }
20
- }
21
-
22
- getLanguage() {
23
- return this.currentLanguage;
24
- }
25
-
26
- t(key, replacements = {}) {
27
- const keys = key.split('.');
28
- let value = this.translations[this.currentLanguage];
29
-
30
- for (const k of keys) {
31
- if (value && typeof value === 'object' && k in value) {
32
- value = value[k];
33
- } else {
34
- // Fallback to English
35
- value = this.translations.en;
36
- for (const fallbackKey of keys) {
37
- if (value && typeof value === 'object' && fallbackKey in value) {
38
- value = value[fallbackKey];
39
- } else {
40
- return key; // Return key if not found
41
- }
42
- }
43
- break;
44
- }
45
- }
46
-
47
- // Replace placeholders
48
- if (typeof value === 'string') {
49
- Object.entries(replacements).forEach(([placeholder, replacement]) => {
50
- value = value.replace(new RegExp(`{${placeholder}}`, 'g'), replacement);
51
- });
52
- }
53
-
54
- return value;
55
- }
56
-
57
- addTranslation(lang, translations) {
58
- if (!this.translations[lang]) {
59
- this.translations[lang] = {};
60
- }
61
- Object.assign(this.translations[lang], translations);
62
- }
63
- }
64
-
65
- export const i18n = new I18n();
66
-
1
+ /**
2
+ * Internationalization system
3
+ */
4
+
5
+ import { translations } from './translations.js';
6
+
7
+ class I18n {
8
+ constructor() {
9
+ this.currentLanguage = 'en';
10
+ this.translations = translations;
11
+ }
12
+
13
+ setLanguage(lang) {
14
+ if (this.translations[lang]) {
15
+ this.currentLanguage = lang;
16
+ } else {
17
+ console.warn(`Language "${lang}" not found, falling back to English`);
18
+ this.currentLanguage = 'en';
19
+ }
20
+ }
21
+
22
+ getLanguage() {
23
+ return this.currentLanguage;
24
+ }
25
+
26
+ t(key, replacements = {}) {
27
+ const keys = key.split('.');
28
+ let value = this.translations[this.currentLanguage];
29
+
30
+ for (const k of keys) {
31
+ if (value && typeof value === 'object' && k in value) {
32
+ value = value[k];
33
+ } else {
34
+ // Fallback to English
35
+ value = this.translations.en;
36
+ for (const fallbackKey of keys) {
37
+ if (value && typeof value === 'object' && fallbackKey in value) {
38
+ value = value[fallbackKey];
39
+ } else {
40
+ return key; // Return key if not found
41
+ }
42
+ }
43
+ break;
44
+ }
45
+ }
46
+
47
+ // Replace placeholders
48
+ if (typeof value === 'string') {
49
+ Object.entries(replacements).forEach(([placeholder, replacement]) => {
50
+ value = value.replace(new RegExp(`{${placeholder}}`, 'g'), replacement);
51
+ });
52
+ }
53
+
54
+ return value;
55
+ }
56
+
57
+ addTranslation(lang, translations) {
58
+ if (!this.translations[lang]) {
59
+ this.translations[lang] = {};
60
+ }
61
+ Object.assign(this.translations[lang], translations);
62
+ }
63
+ }
64
+
65
+ export const i18n = new I18n();
66
+