@xxanderwp/translate-module 1.0.3 → 1.0.4

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
@@ -75,9 +75,9 @@ export declare class LanguageCore<T extends Record<string, Record<string, string
75
75
  /**
76
76
  * Returns the key of the currently active language.
77
77
  *
78
- * @returns The active language key, or `null` if no language has been set.
78
+ * @returns The active language key.
79
79
  */
80
- get currentLanguage(): LangKey | null;
80
+ get currentLanguage(): LangKey;
81
81
  /**
82
82
  * Sets the active language used for subsequent `translate()` calls.
83
83
  *
@@ -96,10 +96,9 @@ export declare class LanguageCore<T extends Record<string, Record<string, string
96
96
  /**
97
97
  * Returns the translation map for the currently active language.
98
98
  *
99
- * @returns The `Record<string, string>` of the active language,
100
- * or `null` if no language is currently set.
99
+ * @returns The `Record<string, string>` of the active language.
101
100
  */
102
- get currentLanguageData(): T[LangKey] | null;
101
+ get currentLanguageData(): T[LangKey];
103
102
  /**
104
103
  * Looks up a translation key in the active language and optionally
105
104
  * interpolates positional placeholders (`{0}`, `{1}`, …) with the
@@ -115,8 +114,7 @@ export declare class LanguageCore<T extends Record<string, Record<string, string
115
114
  * @param args - Zero or more values to interpolate into the translated string.
116
115
  * Each value is coerced to a string and replaces the matching `{n}` token.
117
116
  *
118
- * @returns The translated (and interpolated) string, or `null` if no language
119
- * is active or if the resolved translation is an empty string.
117
+ * @returns The translated (and interpolated) string, or `null` if the resolved translation is an empty string.
120
118
  *
121
119
  * @example
122
120
  * lc.translate("greeting", "Alice"); // "Hello, Alice!"
package/dist/index.js CHANGED
@@ -41,14 +41,6 @@ class LanguageCore {
41
41
  * @throws {Error} If the supplied `defaultLanguage` is not a key of `data`.
42
42
  */
43
43
  constructor(data, defaultLanguage) {
44
- /**
45
- * The currently active language key.
46
- * Defaults to the first key of the provided data object unless overridden
47
- * via the `defaultLanguage` constructor parameter.
48
- * `null` only while the class has not yet been fully initialised
49
- * (should not occur under normal usage).
50
- */
51
- this._currentLanguage = null;
52
44
  this.validateLanguageData(data);
53
45
  this._languages_data = data;
54
46
  if (defaultLanguage) {
@@ -107,7 +99,7 @@ class LanguageCore {
107
99
  /**
108
100
  * Returns the key of the currently active language.
109
101
  *
110
- * @returns The active language key, or `null` if no language has been set.
102
+ * @returns The active language key.
111
103
  */
112
104
  get currentLanguage() {
113
105
  return this._currentLanguage;
@@ -137,12 +129,9 @@ class LanguageCore {
137
129
  /**
138
130
  * Returns the translation map for the currently active language.
139
131
  *
140
- * @returns The `Record<string, string>` of the active language,
141
- * or `null` if no language is currently set.
132
+ * @returns The `Record<string, string>` of the active language.
142
133
  */
143
134
  get currentLanguageData() {
144
- if (!this._currentLanguage)
145
- return null;
146
135
  return this._languages_data[this._currentLanguage];
147
136
  }
148
137
  /**
@@ -160,16 +149,13 @@ class LanguageCore {
160
149
  * @param args - Zero or more values to interpolate into the translated string.
161
150
  * Each value is coerced to a string and replaces the matching `{n}` token.
162
151
  *
163
- * @returns The translated (and interpolated) string, or `null` if no language
164
- * is active or if the resolved translation is an empty string.
152
+ * @returns The translated (and interpolated) string, or `null` if the resolved translation is an empty string.
165
153
  *
166
154
  * @example
167
155
  * lc.translate("greeting", "Alice"); // "Hello, Alice!"
168
156
  * lc.translate("score", "Alice", 42); // "Alice scored 42 points."
169
157
  */
170
158
  translate(key, ...args) {
171
- if (!this._currentLanguage)
172
- return null;
173
159
  const langData = this._languages_data[this._currentLanguage];
174
160
  let res = langData[key];
175
161
  args.forEach((arg, index) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xxanderwp/translate-module",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "directories": {