@sheet-i18n/react 1.6.4 → 1.6.5

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.js CHANGED
@@ -225,6 +225,25 @@ var TranslationService = class {
225
225
  return targetTranslation;
226
226
  }
227
227
  /** helpers */
228
+ interpolatePlaceholders(translationText, values) {
229
+ if (!translationText.includes("{")) {
230
+ return translationText;
231
+ }
232
+ if (!values || Object.keys(values).length === 0) {
233
+ return translationText;
234
+ }
235
+ return translationText.replace(/\{([^{}]+)\}/g, (match, rawKey) => {
236
+ const key = String(rawKey).trim();
237
+ const value = values[key];
238
+ if (value === null || value === void 0) {
239
+ return match;
240
+ }
241
+ if (typeof value === "object" || typeof value === "function" || typeof value === "symbol") {
242
+ return match;
243
+ }
244
+ return String(value);
245
+ });
246
+ }
228
247
  createDescriptor(id, _descriptor) {
229
248
  var _a;
230
249
  return __spreadProps(__spreadValues({}, _descriptor != null ? _descriptor : {}), {
@@ -274,7 +293,9 @@ function useTranslation({
274
293
  const ruleFn = rules == null ? void 0 : rules[ruleKey];
275
294
  if (!ruleFn) return ruleKey;
276
295
  const messageId = ruleFn(values, {});
277
- return translationService.translate(messageId, values);
296
+ const translationValue = translationService.translate(messageId, values);
297
+ const interpolatedTranslationValue = translationService.interpolatePlaceholders(translationValue, values);
298
+ return interpolatedTranslationValue;
278
299
  };
279
300
  return { t };
280
301
  }
@@ -563,8 +584,10 @@ var RuleService = class {
563
584
  constructor(i18nStore) {
564
585
  this.i18nStore = i18nStore;
565
586
  this.createRule = (ruleFn) => {
566
- const currentLocaleSet = this.i18nStore.getCurrentLocaleSet();
567
- return (values) => ruleFn(values, currentLocaleSet);
587
+ return (values) => {
588
+ const currentLocaleSet = this.i18nStore.getCurrentLocaleSet();
589
+ return ruleFn(values, currentLocaleSet);
590
+ };
568
591
  };
569
592
  }
570
593
  };
package/dist/index.mjs CHANGED
@@ -201,6 +201,25 @@ var TranslationService = class {
201
201
  return targetTranslation;
202
202
  }
203
203
  /** helpers */
204
+ interpolatePlaceholders(translationText, values) {
205
+ if (!translationText.includes("{")) {
206
+ return translationText;
207
+ }
208
+ if (!values || Object.keys(values).length === 0) {
209
+ return translationText;
210
+ }
211
+ return translationText.replace(/\{([^{}]+)\}/g, (match, rawKey) => {
212
+ const key = String(rawKey).trim();
213
+ const value = values[key];
214
+ if (value === null || value === void 0) {
215
+ return match;
216
+ }
217
+ if (typeof value === "object" || typeof value === "function" || typeof value === "symbol") {
218
+ return match;
219
+ }
220
+ return String(value);
221
+ });
222
+ }
204
223
  createDescriptor(id, _descriptor) {
205
224
  var _a;
206
225
  return __spreadProps(__spreadValues({}, _descriptor != null ? _descriptor : {}), {
@@ -250,7 +269,9 @@ function useTranslation({
250
269
  const ruleFn = rules == null ? void 0 : rules[ruleKey];
251
270
  if (!ruleFn) return ruleKey;
252
271
  const messageId = ruleFn(values, {});
253
- return translationService.translate(messageId, values);
272
+ const translationValue = translationService.translate(messageId, values);
273
+ const interpolatedTranslationValue = translationService.interpolatePlaceholders(translationValue, values);
274
+ return interpolatedTranslationValue;
254
275
  };
255
276
  return { t };
256
277
  }
@@ -539,8 +560,10 @@ var RuleService = class {
539
560
  constructor(i18nStore) {
540
561
  this.i18nStore = i18nStore;
541
562
  this.createRule = (ruleFn) => {
542
- const currentLocaleSet = this.i18nStore.getCurrentLocaleSet();
543
- return (values) => ruleFn(values, currentLocaleSet);
563
+ return (values) => {
564
+ const currentLocaleSet = this.i18nStore.getCurrentLocaleSet();
565
+ return ruleFn(values, currentLocaleSet);
566
+ };
544
567
  };
545
568
  }
546
569
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheet-i18n/react",
3
- "version": "1.6.4",
3
+ "version": "1.6.5",
4
4
  "description": "i18n client logic based on react",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -36,8 +36,8 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "react-intl": "^7.0.4",
39
- "@sheet-i18n/core": "1.6.3",
40
39
  "@sheet-i18n/errors": "1.8.2",
40
+ "@sheet-i18n/core": "1.6.3",
41
41
  "@sheet-i18n/shared-utils": "1.8.3"
42
42
  },
43
43
  "peerDependencies": {