boxwood 0.70.0 → 0.70.2
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/index.js +33 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -477,7 +477,21 @@ i18n.load = function () {
|
|
|
477
477
|
const path = join(...arguments)
|
|
478
478
|
const data = path.endsWith(".yaml") ? yaml.load(path) : json.load(path)
|
|
479
479
|
return function translate(language, key) {
|
|
480
|
-
|
|
480
|
+
if (!key) {
|
|
481
|
+
throw new Error(`TranslationError[${key}][${language}]: key is undefined`)
|
|
482
|
+
}
|
|
483
|
+
if (!language) {
|
|
484
|
+
throw new Error(
|
|
485
|
+
`TranslationError[${key}][${language}]: language is undefined`
|
|
486
|
+
)
|
|
487
|
+
}
|
|
488
|
+
const translation = data[key][language]
|
|
489
|
+
if (!translation) {
|
|
490
|
+
throw new Error(
|
|
491
|
+
`TranslationError[${key}][${language}]: translation is undefined`
|
|
492
|
+
)
|
|
493
|
+
}
|
|
494
|
+
return translation
|
|
481
495
|
}
|
|
482
496
|
}
|
|
483
497
|
|
|
@@ -487,8 +501,25 @@ function component(fn, { styles, i18n } = {}) {
|
|
|
487
501
|
return fn({}, a)
|
|
488
502
|
}
|
|
489
503
|
if (i18n) {
|
|
504
|
+
const { language } = a
|
|
490
505
|
function translate(key) {
|
|
491
|
-
|
|
506
|
+
if (!key) {
|
|
507
|
+
throw new Error(
|
|
508
|
+
`TranslationError[${key}][${language}]: key is undefined for component:\n${fn.toString()}`
|
|
509
|
+
)
|
|
510
|
+
}
|
|
511
|
+
if (!language) {
|
|
512
|
+
throw new Error(
|
|
513
|
+
`TranslationError[${key}][${language}]: language is undefined for component:\n${fn.toString()}`
|
|
514
|
+
)
|
|
515
|
+
}
|
|
516
|
+
const translation = i18n[key][language]
|
|
517
|
+
if (!translation) {
|
|
518
|
+
throw new Error(
|
|
519
|
+
`TranslationError[${key}][${language}]: translation is undefined for component:\n${fn.toString()}`
|
|
520
|
+
)
|
|
521
|
+
}
|
|
522
|
+
return translation
|
|
492
523
|
}
|
|
493
524
|
return fn({ ...a, translate }, b || [])
|
|
494
525
|
}
|