@jarenjs/locales 0.34.0
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/LICENSE +21 -0
- package/README.md +119 -0
- package/dist/types/ar.d.ts +7 -0
- package/dist/types/de.d.ts +7 -0
- package/dist/types/es.d.ts +7 -0
- package/dist/types/fr.d.ts +7 -0
- package/dist/types/helpers.d.ts +41 -0
- package/dist/types/index.d.ts +23 -0
- package/dist/types/ja.d.ts +7 -0
- package/dist/types/ko.d.ts +7 -0
- package/dist/types/nl.d.ts +7 -0
- package/dist/types/pt.d.ts +7 -0
- package/dist/types/ru.d.ts +7 -0
- package/dist/types/tr.d.ts +7 -0
- package/dist/types/zh-tw.d.ts +7 -0
- package/package.json +95 -0
- package/src/ar.js +159 -0
- package/src/de.js +131 -0
- package/src/es.js +131 -0
- package/src/fr.js +131 -0
- package/src/helpers.js +59 -0
- package/src/index.js +26 -0
- package/src/ja.js +126 -0
- package/src/ko.js +129 -0
- package/src/nl.js +130 -0
- package/src/pt.js +131 -0
- package/src/ru.js +141 -0
- package/src/tr.js +128 -0
- package/src/zh-tw.js +129 -0
package/src/zh-tw.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
//@ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Traditional Chinese, Taiwan (zh-TW) message catalog for
|
|
5
|
+
* @jarenjs/validate and @jarenjs/forms.
|
|
6
|
+
*
|
|
7
|
+
* A catalog is a plain flat object `{ [key]: closure | template string }`;
|
|
8
|
+
* compile it with `compileMessageCatalog` from either consumer package
|
|
9
|
+
* and hand it to `localizeErrors` (validate) or the `catalog` parameters
|
|
10
|
+
* of `validateField` / `evaluateFormRules` (forms). A pack imports only
|
|
11
|
+
* the shared rendering helpers; key parity with the built-in English
|
|
12
|
+
* catalogs is enforced by tests in the repo, not by imports.
|
|
13
|
+
*
|
|
14
|
+
* Globalization mechanics (the pack-authoring pattern - see
|
|
15
|
+
* packages/validate/docs/ERROR-MESSAGES.md):
|
|
16
|
+
* - Chinese has no grammatical plural, so there is no plural helper
|
|
17
|
+
* here; counts read through measure words ("2 個字元", "3 個項目"),
|
|
18
|
+
* and the vocabulary is Taiwan's (字串/陣列/物件/欄位, not the
|
|
19
|
+
* mainland variants),
|
|
20
|
+
* - `Intl.NumberFormat` renders numeric limits the zh-TW way,
|
|
21
|
+
* - `Intl.ListFormat` renders enum alternatives ("a、b或c"),
|
|
22
|
+
* all held as module-level singletons (allocation discipline).
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import {
|
|
26
|
+
formatMessageValue,
|
|
27
|
+
makeNumberRenderer,
|
|
28
|
+
makeTypeNamer,
|
|
29
|
+
} from './helpers.js';
|
|
30
|
+
|
|
31
|
+
//#region Intl singletons
|
|
32
|
+
|
|
33
|
+
const numberFormat = new Intl.NumberFormat('zh-TW');
|
|
34
|
+
const listFormat = new Intl.ListFormat('zh-TW', { style: 'long', type: 'disjunction' });
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Render a numeric limit through the zh-TW number format; non-numbers
|
|
38
|
+
* (e.g. an unresolved $data pointer) render as-is.
|
|
39
|
+
*/
|
|
40
|
+
const num = makeNumberRenderer(numberFormat);
|
|
41
|
+
|
|
42
|
+
/** Taiwan names for the JSON Schema type keyword values. */
|
|
43
|
+
const TYPE_NAMES = {
|
|
44
|
+
string: '字串 (string)',
|
|
45
|
+
number: '數字',
|
|
46
|
+
integer: '整數',
|
|
47
|
+
boolean: '布林值',
|
|
48
|
+
array: '陣列 (array)',
|
|
49
|
+
object: '物件',
|
|
50
|
+
null: 'null',
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** Type keyword values under their zh-TW display name. */
|
|
54
|
+
const typeName = makeTypeNamer(TYPE_NAMES);
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The zh-TW catalog. Covers every key of validate's `messagesEn`,
|
|
60
|
+
* every `form/*` key of forms' `formsMessagesEn`, `x-form/assert`, and
|
|
61
|
+
* the `JQ2xxx` codes reachable through `$query`.
|
|
62
|
+
* @type {Record<string, string | ((params: any, error?: object) => string)>}
|
|
63
|
+
*/
|
|
64
|
+
export const zhTW = {
|
|
65
|
+
//#region @jarenjs/validate (document voice)
|
|
66
|
+
type: (p) => p.types
|
|
67
|
+
? `必須是下列型別之一: ${p.types.join(', ')}`
|
|
68
|
+
: `必須是${typeName(p.type)}`,
|
|
69
|
+
required: (p) => p.missingProperty
|
|
70
|
+
? `必須包含必要屬性 '${p.missingProperty}'`
|
|
71
|
+
: '必須包含必要屬性',
|
|
72
|
+
minimum: (p) => `必須 ${p.comparison} ${num(p.limit)}`,
|
|
73
|
+
maximum: (p) => `必須 ${p.comparison} ${num(p.limit)}`,
|
|
74
|
+
exclusiveMinimum: (p) => `必須 ${p.comparison} ${num(p.limit)}`,
|
|
75
|
+
exclusiveMaximum: (p) => `必須 ${p.comparison} ${num(p.limit)}`,
|
|
76
|
+
multipleOf: (p) => `必須是 ${num(p.multipleOf)} 的倍數`,
|
|
77
|
+
minLength: (p) => `不得少於 ${num(p.limit)} 個字元`,
|
|
78
|
+
maxLength: (p) => `不得多於 ${num(p.limit)} 個字元`,
|
|
79
|
+
pattern: '必須符合模式 "{pattern}"',
|
|
80
|
+
additionalProperties: (p) => p.additionalProperty
|
|
81
|
+
? `不得包含額外屬性 '${p.additionalProperty}'`
|
|
82
|
+
: '不得包含額外屬性',
|
|
83
|
+
minProperties: (p) => `屬性不得少於 ${num(p.limit)} 個`,
|
|
84
|
+
maxProperties: (p) => `屬性不得多於 ${num(p.limit)} 個`,
|
|
85
|
+
minItems: (p) => `項目不得少於 ${num(p.limit)} 個`,
|
|
86
|
+
maxItems: (p) => `項目不得多於 ${num(p.limit)} 個`,
|
|
87
|
+
uniqueItems: '不得包含重複的項目',
|
|
88
|
+
contains: '必須至少包含一個有效項目',
|
|
89
|
+
items: '陣列的項目無效',
|
|
90
|
+
allOf: '必須符合所有子綱要',
|
|
91
|
+
anyOf: '必須符合 anyOf 中的一個子綱要',
|
|
92
|
+
oneOf: '必須恰好符合 oneOf 中的一個子綱要',
|
|
93
|
+
not: '不得符合子綱要',
|
|
94
|
+
format: '必須符合格式 "{format}"',
|
|
95
|
+
if: '必須符合 "if" 綱要',
|
|
96
|
+
then: '必須符合 "then" 綱要',
|
|
97
|
+
else: '必須符合 "else" 綱要',
|
|
98
|
+
'false schema': '布林綱要 false 永遠無效',
|
|
99
|
+
$query: (p) => p.code
|
|
100
|
+
? `'$query' 斷言在 '${p.docPath}' 產生了 ${p.code}`
|
|
101
|
+
: "必須滿足 '$query' 斷言",
|
|
102
|
+
JQ2001: (p) => `'$query' 斷言無法求值(${p.code},位於 '${p.docPath}')`,
|
|
103
|
+
JQ2003: (p) => `'$query' 斷言傳回了多個結果(${p.code},位於 '${p.docPath}')`,
|
|
104
|
+
//#endregion
|
|
105
|
+
|
|
106
|
+
//#region @jarenjs/forms (second-person field voice)
|
|
107
|
+
'form/required': '此欄位為必填',
|
|
108
|
+
'form/type': (p) => `必須是${typeName(p.type)}`,
|
|
109
|
+
'form/const': (p) => `必須是 ${formatMessageValue(p.constValue)}`,
|
|
110
|
+
'form/enum': (p) => `必須是 ${Array.isArray(p.enumValues) ? listFormat.format(p.enumValues.map(formatMessageValue)) : formatMessageValue(p.enumValues)} 其中之一`,
|
|
111
|
+
'form/minLength': (p) => `至少需要 ${num(p.limit)} 個字元(目前 ${num(p.len)} 個)`,
|
|
112
|
+
'form/maxLength': (p) => `最多 ${num(p.limit)} 個字元(目前 ${num(p.len)} 個)`,
|
|
113
|
+
'form/pattern': '必須符合模式 {pattern}',
|
|
114
|
+
'form/format': (p) => `必須是有效的 ${p.format} 格式`,
|
|
115
|
+
'form/minimum': (p) => `必須至少為 ${num(p.limit)}`,
|
|
116
|
+
'form/maximum': (p) => `不得超過 ${num(p.limit)}`,
|
|
117
|
+
'form/exclusiveMinimum': (p) => `必須大於 ${num(p.limit)}`,
|
|
118
|
+
'form/exclusiveMaximum': (p) => `必須小於 ${num(p.limit)}`,
|
|
119
|
+
'form/multipleOf': (p) => `必須是 ${num(p.multipleOf)} 的倍數`,
|
|
120
|
+
'form/minItems': (p) => `至少需要 ${num(p.limit)} 個項目`,
|
|
121
|
+
'form/maxItems': (p) => `最多 ${num(p.limit)} 個項目`,
|
|
122
|
+
'form/uniqueItems': '項目不得重複',
|
|
123
|
+
'form/minProperties': (p) => `至少需要 ${num(p.limit)} 個屬性`,
|
|
124
|
+
'form/maxProperties': (p) => `最多 ${num(p.limit)} 個屬性`,
|
|
125
|
+
'x-form/assert': '無效的值',
|
|
126
|
+
'form/addItem': '新增項目',
|
|
127
|
+
'form/removeItem': '移除項目',
|
|
128
|
+
//#endregion
|
|
129
|
+
};
|