@abtnode/auth 1.16.21-beta-2e75c75c → 1.16.21-beta-725f6059

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/lib/auth.js CHANGED
@@ -26,6 +26,7 @@ const { LOGIN_PROVIDER } = require('@blocklet/constant');
26
26
 
27
27
  const logger = require('./logger');
28
28
  const verifySignature = require('./util/verify-signature');
29
+ const { getLocaleMap } = require('../locales');
29
30
  const {
30
31
  createPassport,
31
32
  createPassportVC,
@@ -37,274 +38,142 @@ const {
37
38
  const createPassportSvg = require('./util/create-passport-svg');
38
39
 
39
40
  const messages = {
40
- description: {
41
- en: 'Connect your DID Wallet',
42
- zh: '连接 DID 钱包',
43
- },
44
- requestProfile: {
45
- en: 'Please provide following information to continue',
46
- zh: '请提供如下信息以继续',
47
- },
48
- requestNFT: {
49
- en: 'Please present NFT to exchange for passport',
50
- zh: '请提供 NFT 以换取通行证',
51
- },
52
- requestCredential: {
53
- en: 'Please provide credential',
54
- zh: '请提供凭证',
55
- },
56
- requestPassport: {
57
- en: 'Please provide passport',
58
- zh: '请提供通行证',
59
- },
60
- requestOwnerPassport: {
61
- en: 'Please provide owner passport',
62
- zh: '请提供节点的所有者通行证',
63
- },
64
- requestBlockletNft: {
65
- en: 'Please provide Blocklet Purchase NFT',
66
- zh: '请提供 Blocklet Purchase NFT',
67
- },
68
- receivePassport: {
69
- en: 'Please sign the text to get passport',
70
- ah: '请对文本签名以获取通行证',
71
- },
41
+ description: getLocaleMap('description'),
42
+ requestProfile: getLocaleMap('requestProfile'),
43
+ requestNFT: getLocaleMap('requestNFT'),
44
+ requestCredential: getLocaleMap('requestCredential'),
45
+ requestPassport: getLocaleMap('requestPassport'),
46
+ requestOwnerPassport: getLocaleMap('requestOwnerPassport'),
47
+ requestBlockletNft: getLocaleMap('requestBlockletNft'),
48
+ receivePassport: getLocaleMap('receivePassport'),
72
49
 
73
50
  // error
74
- actionForbidden: {
75
- en: 'You are not allowed perform this action',
76
- zh: '你没有权限执行此操作',
77
- },
51
+ actionForbidden: getLocaleMap('actionForbidden'),
52
+
53
+ notInitialized: getLocaleMap('notInitialized'),
54
+ appNotInitialized: getLocaleMap('appNotInitialized'),
55
+ alreadyInitiated: getLocaleMap('alreadyInitiated'),
56
+ notAllowed: getLocaleMap('notAllowed'),
57
+ notAppOwner: getLocaleMap('notAppOwner'),
58
+ notSupported: getLocaleMap('notSupported'),
59
+ missingCredentialClaim: getLocaleMap('missingCredentialClaim'),
60
+ missingBlockletCredentialClaim: getLocaleMap('missingBlockletCredentialClaim'),
61
+ missingChallenge: getLocaleMap('missingChallenge'),
62
+ invalidCredentialHolder: getLocaleMap('invalidCredentialHolder'),
63
+ invalidCredentialProof: getLocaleMap('invalidCredentialProof'),
64
+ notOwner: getLocaleMap('notOwner'),
65
+ userMismatch: getLocaleMap('userMismatch'),
66
+ lowVersion: getLocaleMap('lowVersion'),
67
+
68
+ unKnownStatus: getLocaleMap('unKnownStatus'),
69
+ statusNotFound: getLocaleMap('statusNotFound'),
70
+ statusLabel: getLocaleMap('statusLabel'),
71
+ passportNotFound: getLocaleMap('passportNotFound'),
72
+ userNotFound: getLocaleMap('userNotFound'),
73
+ notAuthorized: getLocaleMap('notAuthorized'),
74
+ invalidParams: getLocaleMap('invalidParams'),
75
+ missingKeyPair: getLocaleMap('missingKeyPair'),
76
+ missingBlockletUrl: getLocaleMap('missingBlockletUrl'),
77
+ missingBlockletDid: getLocaleMap('missingBlockletDid'),
78
+ missingChainHost: getLocaleMap('missingChainHost'),
79
+ missingLauncherSession: getLocaleMap('missingLauncherSession'),
80
+ invalidBlocklet: getLocaleMap('invalidBlocklet'),
81
+ blockletExists: getLocaleMap('blockletExists'),
82
+ invalidBlockletVc: getLocaleMap('invalidBlockletVc'),
83
+ invalidAppVersion: getLocaleMap('invalidAppVersion'),
78
84
 
79
- notInitialized: {
80
- en: 'This node is not initialized, login is disabled',
81
- zh: '节点初始化未完成,禁止任何 DID 登录',
82
- },
83
- appNotInitialized: {
84
- en: 'This application is not initialized',
85
- zh: '应用未初始化未完成',
86
- },
87
- alreadyInitiated: {
88
- en: 'This Node already have an owner verified',
89
- zh: '该节点已经绑定所有者',
90
- },
91
- notAllowed: {
92
- en: 'You are not allowed to login to this node',
93
- zh: '你没有权限登录该节点',
94
- },
95
- notAppOwner: {
96
- en: 'You are not the owner of this application',
97
- zh: '你不是该应用的所有者',
98
- },
99
- notSupported: {
100
- en: 'This application is not supported on this server',
101
- zh: '此应用不支持在当前节点安装',
102
- },
103
- missingCredentialClaim: {
104
- en: 'Credential is not provided',
105
- zh: '请提供凭证',
106
- },
107
- missingBlockletCredentialClaim: {
108
- en: 'Blocklet credential is not provided',
109
- zh: '请提供 Blocklet 凭证',
110
- },
111
- missingChallenge: {
112
- en: 'Credential presentation does not include valid challenge',
113
- zh: '凭证中缺少正确的随机因子',
114
- },
85
+ // NFT related
86
+ missingProfileClaim: getLocaleMap('missingProfileClaim'),
87
+ invalidNftClaim: getLocaleMap('invalidNftClaim'),
88
+ invalidNft: getLocaleMap('invalidNft'),
89
+ invalidNftHolder: getLocaleMap('invalidNftHolder'),
90
+ invalidNftProof: getLocaleMap('invalidNftProof'),
91
+ invalidNftIssuer: getLocaleMap('invalidNftIssuer'),
92
+ invalidNftParent: getLocaleMap('invalidNftParent'),
93
+ tagNotMatch: getLocaleMap('tagNotMatch'),
94
+ requestBlockletSpaceNFT: getLocaleMap('requestBlockletSpaceNFT'),
95
+ blockletSpaceNftIdRequired: getLocaleMap('blockletSpaceNftIdRequired'),
96
+ nftAlreadyConsumed: getLocaleMap('nftAlreadyConsumed'),
97
+ sessionAlreadyConsumed: getLocaleMap('sessionAlreadyConsumed'),
98
+ nftAlreadyExpired: getLocaleMap('nftAlreadyExpired'),
99
+ nftAlreadyUsed: getLocaleMap('nftAlreadyUsed'),
100
+ missingNftClaim: getLocaleMap('missingNftClaim'),
101
+ noNft: getLocaleMap('noNft'),
102
+ noTag: getLocaleMap('noTag'),
103
+ noChainHost: getLocaleMap('noChainHost'),
104
+ alreadyTransferred: getLocaleMap('alreadyTransferred'),
105
+ delegateTransferOwnerNFT: getLocaleMap('delegateTransferOwnerNFT'),
106
+ notAllowedTransferToSelf: getLocaleMap('notAllowedTransferToSelf'),
107
+ tagRequired: getLocaleMap('tagRequired'),
108
+ appIsInProgress: getLocaleMap('appIsInProgress'),
109
+ // 以后新增的文本尽量使用 `hello {name}` 的模版方式, 而不是函数
115
110
  invalidCredentialType: {
111
+ ar: (types) => `نوع الاعتماد غير صالح ، يتوقع ${types.join(' أو ')}`,
112
+ de: (types) => `Ungültiger Anmeldeinformationstyp, erwarte ${types.join(' oder ')}`,
113
+ es: (types) => `Tipo de credencial no válido, espera ${types.join(' o ')}`,
116
114
  en: (types) => `Invalid credential type, expect ${types.join(' or ')}`,
115
+ fr: (types) => `Type de justificatif invalide, attendre ${types.join(' ou ')}`,
116
+ hi: (types) => `अमान्य प्रमाणीकरण प्रकार, ${types.join(' या ')}`,
117
+ id: (types) => `Jenis kredensial tidak valid, harap ${types.join(' atau ')}`,
118
+ ja: (types) => `無効な資格情報タイプ、${types.join(' または ')}`,
119
+ ko: (types) => `잘못된 자격 증명 유형, ${types.join(' 또는 ')}`,
120
+ pt: (types) => `Tipo de credencial inválido, espera ${types.join(' ou ')}`,
121
+ ru: (types) => `Неверный тип учетных данных, ожидается ${types.join(' или ')}`,
122
+ th: (types) => `ประเภทข้อมูลประจำตัวไม่ถูกต้อง ต้องการ ${types.join(' หรือ ')}`,
123
+ vi: (types) => `Loại chứng chỉ không hợp lệ, mong đợi ${types.join(' hoặc ')}`,
117
124
  zh: (types) => `无效的凭证类型,必须是 ${types.join(' 或 ')}`,
125
+ 'zh-TW': (types) => `無效的憑證類型,必須是 ${types.join(' 或 ')}`,
118
126
  },
119
127
  invalidCredentialId: {
128
+ ar: (ids) => `المعرف غير صالح: ${[].concat(ids).join(' أو ')}`,
129
+ de: (ids) => `Ungültige ID: ${[].concat(ids).join(' oder ')}`,
120
130
  en: (ids) => `Invalid credential type, expect ${[].concat(ids).join(' or ')}`,
131
+ es: (ids) => `ID no válida: ${[].concat(ids).join(' o ')}`,
132
+ fr: (ids) => `ID non valide: ${[].concat(ids).join(' ou ')}`,
133
+ hi: (ids) => `अमान्य परिचय: ${[].concat(ids).join(' या ')}`,
134
+ id: (ids) => `ID tidak valid: ${[].concat(ids).join(' atau ')}`,
135
+ ja: (ids) => `無効なID:${[].concat(ids).join('または')}`,
136
+ ko: (ids) => `잘못된 ID: ${[].concat(ids).join(' 또는 ')}`,
137
+ pt: (ids) => `ID inválido: ${[].concat(ids).join(' ou ')}`,
138
+ ru: (ids) => `Неверный идентификатор: ${[].concat(ids).join(' или ')}`,
139
+ th: (ids) => `รหัสไม่ถูกต้อง: ${[].concat(ids).join(' หรือ ')}`,
140
+ vi: (ids) => `ID không hợp lệ: ${[].concat(ids).join(' hoặc ')}`,
121
141
  zh: (ids) => `无效的凭证,ID 必须是 ${[].concat(ids).join(' 或 ')}`,
122
- },
123
- invalidCredentialHolder: {
124
- en: 'Invalid credential holder',
125
- zh: '无效的凭证持有者',
126
- },
127
- invalidCredentialProof: {
128
- en: 'Invalid credential signature proof',
129
- zh: '无效的凭证签名',
142
+ 'zh-TW': (ids) => `無效的憑證,ID 必須是 ${[].concat(ids).join(' 或 ')}`,
130
143
  },
131
144
  passportRevoked: {
145
+ ar: (title, issuer) => `تم إلغاء جواز السفر ${title} من قبل ${issuer ? ' ' : ''}${issuer || ''}`,
146
+ de: (title, issuer) => `Pass ${title} wurde von ${issuer ? ' ' : ''}${issuer || ''} widerrufen`,
147
+ es: (title, issuer) => `Pasaporte ${title} ha sido revocado por ${issuer ? ' ' : ''}${issuer || ''}`,
132
148
  en: (title, issuer) => `Passport ${title} has been revoked${issuer ? ' by ' : ''}${issuer || ''}`,
149
+ fr: (title, issuer) => `Le passeport ${title} a été révoqué par ${issuer ? ' ' : ''}${issuer || ''}`,
150
+ hi: (title, issuer) => `पासपोर्ट ${title} को ${issuer ? ' ' : ''}${issuer || ''} द्वारा रद्द कर दिया गया है`,
151
+ id: (title, issuer) => `Paspor ${title} telah dicabut oleh ${issuer ? ' ' : ''}${issuer || ''}`,
152
+ ja: (title, issuer) => `パスポート ${title} は ${issuer ? ' ' : ''}${issuer || ''} によって取り消されました`,
153
+ ko: (title, issuer) => `여권 ${title} 은 ${issuer ? ' ' : ''}${issuer || ''} 에 의해 취소되었습니다`,
154
+ pt: (title, issuer) => `O passaporte ${title} foi revogado por ${issuer ? ' ' : ''}${issuer || ''}`,
155
+ ru: (title, issuer) => `Паспорт ${title} был отозван ${issuer ? ' ' : ''}${issuer || ''}`,
156
+ th: (title, issuer) => `หนังสือเดินทาง ${title} ถูกยกเลิกโดย ${issuer ? ' ' : ''}${issuer || ''}`,
157
+ vi: (title, issuer) => `Hộ chiếu ${title} đã bị thu hồi bởi ${issuer ? ' ' : ''}${issuer || ''}`,
133
158
  zh: (title, issuer) => `通行证 ${title} 已被${issuer ? ' ' : ''}${issuer || ''}${issuer ? ' ' : ''}吊销`,
134
- },
135
- notOwner: {
136
- en: 'The account does not match the owner account of this passport, please use the DID wallet that contains the owner account of this passport to receive.',
137
- zh: '该账号与此通行证的所有者账号不匹配,请使用包含此通行证所有者账号的 DID 钱包领取。',
138
- },
139
- userMismatch: {
140
- en: 'User mismatch, please use connected DID wallet to continue.',
141
- zh: '用户不匹配,请使用当前会话连接的钱包操作',
142
- },
143
- lowVersion: {
144
- en: 'Your DID wallet version is too low, please upgrade to the latest version',
145
- zh: '你的 DID 钱包版本过低,请升级至最新版本',
159
+ 'zh-TW': (title, issuer) => `通行證 ${title} 已被${issuer ? ' ' : ''}${issuer || ''}${issuer ? ' ' : ''}吊銷`,
146
160
  },
147
161
  passportStatusCheckFailed: {
162
+ ar: (message) => `فشلت عملية التحقق من حالة جواز السفر: ${message}`,
163
+ de: (message) => `Passport-Statusprüfung fehlgeschlagen: ${message}`,
164
+ es: (message) => `Error al verificar el estado del pasaporte: ${message}`,
148
165
  en: (message) => `Passport status check failed: ${message}`,
166
+ fr: (message) => `Échec de la vérification du statut du passeport: ${message}`,
167
+ hi: (message) => `पासपोर्ट स्थिति जांच विफल: ${message}`,
168
+ id: (message) => `Pemeriksaan status paspor gagal: ${message}`,
169
+ ja: (message) => `パスポートのステータスチェックに失敗しました:${message}`,
170
+ ko: (message) => `여권 상태 확인 실패 : ${message}`,
171
+ pt: (message) => `Falha na verificação do status do passaporte: ${message}`,
172
+ ru: (message) => `Ошибка проверки статуса паспорта: ${message}`,
173
+ th: (message) => `การตรวจสอบสถานะหนังสือเดินทางล้มเหลว: ${message}`,
174
+ vi: (message) => `Kiểm tra trạng thái hộ chiếu không thành công: ${message}`,
149
175
  zh: (message) => `通行证状态检测失败:${message}`,
150
- },
151
- unKnownStatus: {
152
- en: 'unknown status',
153
- zh: '未知的状态',
154
- },
155
- statusNotFound: {
156
- en: 'status not found',
157
- zh: '未找到状态',
158
- },
159
- statusLabel: {
160
- en: 'Status',
161
- zh: '状态',
162
- },
163
- passportNotFound: {
164
- en: 'Passport not found',
165
- zh: '未找到通行证',
166
- },
167
- userNotFound: {
168
- en: 'User not found',
169
- zh: '用户不存在',
170
- },
171
- notAuthorized: {
172
- en: '没有执行此操作的权限',
173
- zh: 'No permission to perform this operation',
174
- },
175
- invalidParams: {
176
- en: 'Invalid Params',
177
- zh: '无效的参数',
178
- },
179
- missingKeyPair: {
180
- en: 'Missing app key pair',
181
- zh: '缺少应用钥匙对',
182
- },
183
- missingBlockletUrl: {
184
- en: 'Missing blocklet url',
185
- zh: '缺少应用下载地址',
186
- },
187
- missingBlockletDid: {
188
- en: 'Missing blocklet did',
189
- zh: '缺少应用 DID',
190
- },
191
- missingChainHost: {
192
- en: 'Missing chain host',
193
- zh: '缺少链的端点地址',
194
- },
195
- missingLauncherSession: {
196
- en: 'Missing launcherUrl and launcherSessionId',
197
- zh: '缺少启动器会话参数',
198
- },
199
- invalidBlocklet: {
200
- en: 'Invalid Blocklet',
201
- zh: '无效的 Blocklet',
202
- },
203
- blockletExists: {
204
- en: 'The blocklet already exists',
205
- zh: '应用已安装',
206
- },
207
- invalidBlockletVc: {
208
- en: 'Invalid Blocklet VC',
209
- zh: '无效的 Blocklet VC',
210
- },
211
- invalidAppVersion: {
212
- en: 'App key-pair rotating can only be performed on the latest version',
213
- zh: '只有最新版应用可以变更钥匙对',
214
- },
215
-
216
- // NFT related
217
- missingProfileClaim: {
218
- en: 'Owner profile not provided',
219
- zh: '节点所有者信息必须提供',
220
- },
221
- invalidNftClaim: {
222
- en: 'Invalid Asset Claim: ownerPk, ownerDid and ownerProof are required',
223
- zh: '无效的 NFT Claim:ownerPk、ownerDid、ownerProof 是必填的',
224
- },
225
- invalidNft: {
226
- en: 'Invalid server ownership NFT state',
227
- zh: '无效的节点所有权 NFT',
228
- },
229
- invalidNftHolder: {
230
- en: 'Invalid server ownership NFT holder',
231
- zh: '无效的节点所有权 NFT 持有者',
232
- },
233
- invalidNftProof: {
234
- en: 'Invalid server ownership NFT signature proof',
235
- zh: '无效的节点所有权 NFT 签名',
236
- },
237
- invalidNftIssuer: {
238
- en: 'Invalid server ownership NFT issuer',
239
- zh: '无效的节点所有权 NFT 颁发者',
240
- },
241
- invalidNftParent: {
242
- en: 'Unexpected NFT Collection',
243
- zh: '无效的 NFT 集合',
244
- },
245
- tagNotMatch: {
246
- en: 'This NFT is for another blocklet server',
247
- zh: '您所提供的所有权 NFT 不属于当前节点',
248
- },
249
- requestBlockletSpaceNFT: {
250
- en: 'Please provide Blocklet Space NFT',
251
- zh: '请提供应用空间 NFT',
252
- },
253
- blockletSpaceNftIdRequired: {
254
- en: 'Blocklet Space NFT ID is required',
255
- zh: '应用空间 NFT ID 是必须的',
256
- },
257
- nftAlreadyConsumed: {
258
- en: 'This NFT has already been used',
259
- zh: '该 NFT 已经被使用过了',
260
- },
261
- sessionAlreadyConsumed: {
262
- en: 'This session has already been used',
263
- zh: '该会话已经被使用过了',
264
- },
265
- nftAlreadyExpired: {
266
- en: 'This NFT has expired',
267
- zh: '该 NFT 已经过期',
268
- },
269
- nftAlreadyUsed: {
270
- en: 'This NFT has already been connected to another user',
271
- zh: '该 NFT 已经被起它用户使用过',
272
- },
273
- missingNftClaim: {
274
- en: 'Ownership NFT not provided',
275
- zh: '节点所有权 NFT 必须提供',
276
- },
277
- noNft: {
278
- en: 'This server is not initialized to accept ownership NFT',
279
- zh: '该节点不能用这种方式成为管理员',
280
- },
281
- noTag: {
282
- en: 'Tag not found from server launcher info',
283
- zh: '节点初始化信息异常:缺少标签',
284
- },
285
- noChainHost: {
286
- en: 'chainHost not found from server launcher info',
287
- zh: '节点初始化信息异常:缺少链地址',
288
- },
289
- alreadyTransferred: {
290
- en: 'The Blocklet Server already belongs to {owner}',
291
- zh: '该节点已经属于 {owner}',
292
- },
293
- delegateTransferOwnerNFT: {
294
- en: 'Sign the delegation transaction to authorize blocklet server to transfer your ownership NFT to new owner when he/she claims the transfer.',
295
- zh: '签名下面的交易以授权节点转移所有权以及代表所有权的 NFT。',
296
- },
297
- notAllowedTransferToSelf: {
298
- en: 'Not allowed to transfer the Server to yourself',
299
- zh: '不能将节点转移给自己',
300
- },
301
- tagRequired: {
302
- en: 'tag is required',
303
- zh: 'tag 不能为空',
304
- },
305
- appIsInProgress: {
306
- en: 'The application is in progress, please wait for it to finish',
307
- zh: '应用正在进行中,请等待完成',
176
+ 'zh-TW': (message) => `通行證狀態檢測失敗:${message}`,
308
177
  },
309
178
  };
310
179
 
@@ -0,0 +1,27 @@
1
+ const { messages } = require('./auth');
2
+
3
+ const funcKeys = {
4
+ invalidCredentialType: 1,
5
+ invalidCredentialId: 1,
6
+ passportRevoked: 1,
7
+ passportStatusCheckFailed: 1,
8
+ };
9
+
10
+ describe('auth messages has key', () => {
11
+ const keys = Object.keys(messages);
12
+ // ensure all keys have values
13
+ test('auth messages has key', () => {
14
+ keys.forEach((key) => {
15
+ const localMap = messages[key];
16
+ expect(localMap).toBeDefined();
17
+ ['en', 'zh', 'ja'].forEach((language) => {
18
+ if (funcKeys[key]) {
19
+ expect(typeof localMap[language]).toEqual('function');
20
+ } else {
21
+ expect(typeof localMap[language]).toEqual('string');
22
+ expect(localMap[language].length > 0).toBeTruthy();
23
+ }
24
+ });
25
+ });
26
+ });
27
+ });
package/locales/ar.js ADDED
@@ -0,0 +1,67 @@
1
+ /* eslint-disable prettier/prettier */
2
+ module.exports = {
3
+ description: 'قم بتوصيل محفظة العملة الرقمية الموزعة الخاصة بك',
4
+ requestProfile: 'يرجى تقديم المعلومات التالية للمتابعة',
5
+ requestNFT: 'يرجى تقديم NFT للتبادل بجواز السفر',
6
+ requestCredential: 'يرجى تقديم بيانات الاعتماد',
7
+ requestPassport: 'يرجى تقديم جواز السفر',
8
+ requestOwnerPassport: 'يرجى تقديم جواز سفر المالك',
9
+ requestBlockletNft: 'يرجى توفير Blocklet Purchase NFT',
10
+ receivePassport: 'يرجى توقيع النص للحصول على جواز السفر',
11
+ actionForbidden: 'غير مسموح لك بتنفيذ هذا الإجراء',
12
+ notInitialized: 'هذا العقدة غير مهيأة ، تم تعطيل تسجيل الدخول',
13
+ appNotInitialized: 'هذا التطبيق غير مهيأ',
14
+ alreadyInitiated: 'هذا العقدة لديها بالفعل مالك موثوق به',
15
+ notAllowed: 'لا يُسمَح لك بتسجيل الدخول إلى هذا العُقدة',
16
+ notAppOwner: 'أنت لست مالك هذا التطبيق',
17
+ notSupported: 'هذا التطبيق غير مدعوم على هذا الخادم',
18
+ missingCredentialClaim: 'لم يتم توفير أوراق الاعتماد',
19
+ missingBlockletCredentialClaim: 'لم يتم توفير بيانات اعتماد Blocklet',
20
+ missingChallenge: 'عرض الاعتماد لا يتضمن تحدي صالح.',
21
+ invalidCredentialHolder: 'حامل بيانات اعتماد غير صحيحة',
22
+ invalidCredentialProof: 'بيان توقيع بيانات الاعتماد غير صالح',
23
+ notOwner:
24
+ 'الحساب لا يتطابق مع حساب صاحب جواز السفر هذا ، يرجى استخدام محفظة DID التي تحتوي على حساب صاحب جواز السفر هذا لاستلامه.',
25
+ userMismatch: 'عدم تطابق المستخدم ، يرجى استخدام محفظة DID المتصلة للمتابعة.',
26
+ lowVersion: 'نسخة محفظة DID الخاصة بك منخفضة جدًا، يرجى الترقية إلى أحدث نسخة.',
27
+ unKnownStatus: 'حالة غير معروفة',
28
+ statusNotFound: 'لم يتم العثور على الحالة',
29
+ statusLabel: 'الحالة',
30
+ passportNotFound: 'جواز السفر غير موجود',
31
+ userNotFound: 'المستخدم غير موجود',
32
+ notAuthorized: 'لا يوجد إذن لأداء هذه العملية',
33
+ invalidParams: 'معاملات غير صالحة',
34
+ missingKeyPair: 'مفتاح التطبيق الناقص',
35
+ missingBlockletUrl: 'عنوان موقع البلوكليت المفقود',
36
+ missingBlockletDid: 'قطعة مفقودة',
37
+ missingChainHost: 'مضيف سلسلة مفقود',
38
+ missingLauncherSession: 'مفقودة رابط ومعرف جلسة المشغل',
39
+ invalidBlocklet: 'البلوكليت غير صالح',
40
+ blockletExists: 'البلوكلت موجود بالفعل',
41
+ invalidBlockletVc: 'مكعب الكتروني غير صالح',
42
+ invalidAppVersion: 'لا يمكن تنفيذ تدوير مفتاح التطبيق إلا على النسخة الأحدث',
43
+ missingProfileClaim: 'صاحب الملف الشخصي غير متوفر',
44
+ invalidNftClaim: 'مطالبة الأصول غير صالحة: ownerPk و ownerDid و ownerProof مطلوبة',
45
+ invalidNft: 'حالة ملكية الخادم غير صالحة NFT',
46
+ invalidNftHolder: 'حامل رخصة مالك الخادم غير صالحة',
47
+ invalidNftProof: 'توقيع غير صالح لبرهان ملكية خادم NFT',
48
+ invalidNftIssuer: 'مالك الخادم غير صالح إصدار NFT',
49
+ invalidNftParent: 'مجموعة عملات NFT غير متوقعة',
50
+ tagNotMatch: 'هذا NFT مخصص لخادم Blocklet آخر',
51
+ requestBlockletSpaceNFT: 'يرجى تقديم Blocklet Space NFT',
52
+ blockletSpaceNftIdRequired: 'مطلوب معرف Blocklet Space NFT',
53
+ nftAlreadyConsumed: 'تم استخدام هذا NFT بالفعل',
54
+ sessionAlreadyConsumed: 'تم استخدام هذه الدورة بالفعل',
55
+ nftAlreadyExpired: 'هذا الـ NFT منتهي الصلاحية',
56
+ nftAlreadyUsed: 'تم ربط هذا NFT بالفعل بمستخدم آخر',
57
+ missingNftClaim: 'ملكية NFT غير متوفرة',
58
+ noNft: 'هذا الخادم غير مهيأ لقبول ملكية NFT',
59
+ noTag: 'لم يتم العثور على العلامة في معلومات بدء تشغيل الخادم',
60
+ noChainHost: 'لم يتم العثور على chainHost من معلومات المشغل الخادم',
61
+ alreadyTransferred: 'تنتمي خادم بلوكليت بالفعل لـ {owner}',
62
+ delegateTransferOwnerNFT:
63
+ 'قم بتوقيع عملية الوفد لتفويض خادم Blocklet بنقل ملكية NFT الخاص بك إلى المالك الجديد عند ادعائه/اكتسابه لعملية النقل.',
64
+ notAllowedTransferToSelf: 'غير مسموح بنقل الخادم إلى نفسك',
65
+ tagRequired: 'العلامة مطلوبة',
66
+ appIsInProgress: 'التطبيق قيد التقدم، يرجى الانتظار حتى الانتهاء.',
67
+ };
@@ -0,0 +1,154 @@
1
+ const flat = require('flat');
2
+
3
+ /**
4
+ * Represents the language code.
5
+ * @typedef {'ai'|'de'|'en'|'es'|'fr'|'hi'|'id'|'ja'|'ko'|'pt'|'ru'|'th'|'vi'|'zh'|'zh-TW'} LanguageCode
6
+ */
7
+
8
+ /**
9
+ * @typedef {Object} LocaleMap
10
+ * @property {string} ai
11
+ * @property {string} de
12
+ * @property {string} en
13
+ * @property {string} es
14
+ * @property {string} fr
15
+ * @property {string} hi
16
+ * @property {string} id
17
+ * @property {string} ja
18
+ * @property {string} ko
19
+ * @property {string} pt
20
+ * @property {string} ru
21
+ * @property {string} th
22
+ * @property {string} vi
23
+ * @property {string} zh
24
+ */
25
+
26
+ /**
27
+ * @typedef {Object} LocaleLanguages
28
+ * @property {Record<string, string>} ai
29
+ * @property {Record<string, string>} de
30
+ * @property {Record<string, string>} en
31
+ * @property {Record<string, string>} es
32
+ * @property {Record<string, string>} fr
33
+ * @property {Record<string, string>} hi
34
+ * @property {Record<string, string>} id
35
+ * @property {Record<string, string>} ja
36
+ * @property {Record<string, string>} ko
37
+ * @property {Record<string, string>} pt
38
+ * @property {Record<string, string>} ru
39
+ * @property {Record<string, string>} th
40
+ * @property {Record<string, string>} vi
41
+ * @property {Record<string, string>} zh
42
+ */
43
+
44
+ /**
45
+ * @typedef {Object} CreateLocaleMethodProps
46
+ * @property {LocaleLanguages} localesMap
47
+ * @property {boolean} [flatten]
48
+ */
49
+
50
+ /**
51
+ * @callback GetLocale
52
+ * 获取某个语言的某个key的值
53
+ * @param {string} key
54
+ * @param {LanguageCode} code
55
+ * @param {Record<string, string>} [data]
56
+ * @returns {string}
57
+ */
58
+
59
+ /**
60
+ * @callback GetLocaleMap
61
+ * 获取某个key的所有语言的 value
62
+ * @param {string} key
63
+ * @param {Record<string, string>} [data]
64
+ * @param {string} [fallbackLocale]
65
+ * @returns {LocaleMap}
66
+ */
67
+
68
+ function flattenObject(obj) {
69
+ const keys = Object.keys(obj);
70
+ return keys.reduce((map, key) => {
71
+ map[key] = flat(obj[key]);
72
+ return map;
73
+ }, {});
74
+ }
75
+
76
+ const createEmptyMap = (languageKeys) => {
77
+ return languageKeys.reduce((map, key) => {
78
+ map[key] = '';
79
+ return map;
80
+ }, {});
81
+ };
82
+
83
+ const extractSubObjectWithKey = ({ keys, data, key, defaultKey }) => {
84
+ return keys.reduce((map, subKey) => {
85
+ map[subKey] = data[subKey] ? data[subKey][key] : data[defaultKey][key];
86
+ return map;
87
+ }, {});
88
+ };
89
+
90
+ const mapSubKeysToExtractedData = ({ topKeys, sucbKeys, data }) => {
91
+ return sucbKeys.reduce((map, key) => {
92
+ map[key] = extractSubObjectWithKey({
93
+ keys: topKeys,
94
+ data,
95
+ key,
96
+ });
97
+ return map;
98
+ }, {});
99
+ };
100
+
101
+ /* eslint-disable no-prototype-builtins */
102
+ const replaceTemplate = (template, data) => {
103
+ if (typeof template !== 'string' && !data) {
104
+ return template;
105
+ }
106
+
107
+ return template.replace(/{(\w*)}/g, (_, key) => (data.hasOwnProperty(key) ? data[key] : `{${key}}`));
108
+ };
109
+
110
+ /**
111
+ * @param {CreateLocaleMethodProps} props
112
+ * @returns {{getLocaleMap: GetLocaleMap, getLocale: GetLocale}}
113
+ */
114
+ function createLocaleMethod({ localesMap, flatten = false }) {
115
+ const locales = flatten ? flattenObject(localesMap) : localesMap;
116
+ const languageKeys = Object.keys(locales);
117
+ const localesKeys = Object.keys(locales.en);
118
+
119
+ const allLocalesMap = mapSubKeysToExtractedData({
120
+ topKeys: languageKeys,
121
+ sucbKeys: localesKeys,
122
+ data: locales,
123
+ defaultKey: 'en',
124
+ });
125
+ const emptyMap = createEmptyMap(languageKeys);
126
+
127
+ const getLocaleMap = (key, data, fallbackLocale = 'en') => {
128
+ if (data) {
129
+ return languageKeys.reduce(
130
+ (obj, languageKey) => {
131
+ obj[languageKey] = replaceTemplate(
132
+ allLocalesMap[key][languageKey] || allLocalesMap[key][fallbackLocale],
133
+ data
134
+ );
135
+ return obj;
136
+ },
137
+ { ...emptyMap }
138
+ );
139
+ }
140
+ return allLocalesMap[key] || { ...emptyMap };
141
+ };
142
+
143
+ const getLocale = (key, code, data, fallbackLocale = 'en') => {
144
+ const local = locales[code] || locales[fallbackLocale];
145
+ if (local[key] === undefined) {
146
+ return '';
147
+ }
148
+ return data ? replaceTemplate(local[key], data) : local[key];
149
+ };
150
+
151
+ return { getLocaleMap, getLocale };
152
+ }
153
+
154
+ module.exports = createLocaleMethod;