@salesforce/vscode-i18n 65.15.2 → 65.17.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/vscode-i18n",
3
- "version": "65.15.2",
3
+ "version": "65.17.3",
4
4
  "description": "Internationalization (i18n) library for Salesforce VS Code extensions",
5
5
  "author": "Salesforce",
6
6
  "license": "BSD-3-Clause",
@@ -36,7 +36,8 @@
36
36
  "src/**/*.ts",
37
37
  "test/**/*.ts",
38
38
  "tsconfig.json",
39
- "../../tsconfig.common.json"
39
+ "../../tsconfig.common.json",
40
+ "package.json"
40
41
  ],
41
42
  "output": [
42
43
  "out/**",
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=advancedLocalization.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"advancedLocalization.test.d.ts","sourceRoot":"","sources":["../../../../test/jest/i18n/advancedLocalization.test.ts"],"names":[],"mappings":""}
@@ -1,340 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2024, salesforce.com, inc.
4
- * All rights reserved.
5
- * Licensed under the BSD 3-Clause license.
6
- * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- const constants_1 = require("../../../src/constants");
10
- const advancedLocalization_1 = require("../../../src/i18n/advancedLocalization");
11
- describe('Advanced Localization Unit Tests', () => {
12
- let consoleWarnSpy;
13
- let consoleErrorSpy;
14
- beforeEach(() => {
15
- // Clear all singletons before each test
16
- advancedLocalization_1.LocalizationService.instances.clear();
17
- advancedLocalization_1.MessageBundleManager.instances.clear();
18
- advancedLocalization_1.LocalizationConfig.instance = undefined;
19
- // Mock console methods to avoid noise in tests
20
- jest.spyOn(console, 'log').mockImplementation();
21
- consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation();
22
- consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
23
- });
24
- afterEach(() => {
25
- jest.restoreAllMocks();
26
- });
27
- describe('LocalizationConfig', () => {
28
- it('should create a singleton instance', () => {
29
- const config1 = advancedLocalization_1.LocalizationConfig.getInstance();
30
- const config2 = advancedLocalization_1.LocalizationConfig.getInstance();
31
- expect(config1).toBe(config2);
32
- });
33
- it('should recognize supported locales', () => {
34
- const config = advancedLocalization_1.LocalizationConfig.getInstance();
35
- expect(config.isLocaleSupported('en')).toBe(true);
36
- expect(config.isLocaleSupported('ja')).toBe(true);
37
- expect(config.isLocaleSupported('fr')).toBe(false);
38
- expect(config.isLocaleSupported('es')).toBe(false);
39
- });
40
- it('should handle non-string locale values', () => {
41
- const config = advancedLocalization_1.LocalizationConfig.getInstance();
42
- expect(config.isLocaleSupported(null)).toBe(false);
43
- expect(config.isLocaleSupported(undefined)).toBe(false);
44
- expect(config.isLocaleSupported(123)).toBe(false);
45
- expect(config.isLocaleSupported({})).toBe(false);
46
- });
47
- it('should return the default locale', () => {
48
- const config = advancedLocalization_1.LocalizationConfig.getInstance();
49
- expect(config.getDefaultLocale()).toBe(constants_1.DEFAULT_LOCALE);
50
- });
51
- });
52
- describe('MessageBundleManager', () => {
53
- it('should create separate instances for different instance names', () => {
54
- const manager1 = advancedLocalization_1.MessageBundleManager.getInstance('test1');
55
- const manager2 = advancedLocalization_1.MessageBundleManager.getInstance('test2');
56
- expect(manager1).not.toBe(manager2);
57
- });
58
- it('should return the same instance for the same instance name', () => {
59
- const manager1 = advancedLocalization_1.MessageBundleManager.getInstance('test');
60
- const manager2 = advancedLocalization_1.MessageBundleManager.getInstance('test');
61
- expect(manager1).toBe(manager2);
62
- });
63
- it('should register and load base message bundles', () => {
64
- const manager = advancedLocalization_1.MessageBundleManager.getInstance('test');
65
- const baseBundle = {
66
- type: 'base',
67
- messages: {
68
- hello: 'Hello',
69
- goodbye: 'Goodbye'
70
- }
71
- };
72
- manager.registerMessageBundle('test', baseBundle);
73
- const message = manager.loadMessageBundle();
74
- expect(message.localize('hello')).toBe('Hello');
75
- expect(message.localize('goodbye')).toBe('Goodbye');
76
- });
77
- it('should handle locale-specific message bundles', () => {
78
- const manager = advancedLocalization_1.MessageBundleManager.getInstance('test');
79
- const baseBundle = {
80
- type: 'base',
81
- messages: {
82
- hello: 'Hello',
83
- goodbye: 'Goodbye'
84
- }
85
- };
86
- const jaBundle = {
87
- type: 'locale',
88
- locale: 'ja',
89
- messages: {
90
- _locale: 'ja',
91
- hello: 'こんにちは',
92
- goodbye: 'さようなら'
93
- }
94
- };
95
- manager.registerMessageBundle('test', baseBundle);
96
- manager.registerMessageBundle('test', jaBundle);
97
- const enMessage = manager.loadMessageBundle({ locale: 'en' });
98
- const jaMessage = manager.loadMessageBundle({ locale: 'ja' });
99
- expect(enMessage.localize('hello')).toBe('Hello');
100
- expect(jaMessage.localize('hello')).toBe('こんにちは');
101
- });
102
- it('should fall back to base messages for unsupported locales', () => {
103
- const manager = advancedLocalization_1.MessageBundleManager.getInstance('test');
104
- const baseBundle = {
105
- type: 'base',
106
- messages: {
107
- hello: 'Hello'
108
- }
109
- };
110
- manager.registerMessageBundle('test', baseBundle);
111
- // @ts-expect-error - test invalid locale
112
- const message = manager.loadMessageBundle({ locale: 'fr' });
113
- expect(message.localize('hello')).toBe('Hello');
114
- expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining('Cannot find fr, defaulting to en'));
115
- });
116
- it('should fall back to locale from _locale key when locale property is not provided', () => {
117
- const manager = advancedLocalization_1.MessageBundleManager.getInstance('test');
118
- const baseBundle = {
119
- type: 'base',
120
- messages: {
121
- hello: 'Hello'
122
- }
123
- };
124
- const jaBundle = {
125
- type: 'locale',
126
- messages: {
127
- _locale: 'ja',
128
- hello: 'こんにちは'
129
- }
130
- };
131
- manager.registerMessageBundle('test', baseBundle);
132
- manager.registerMessageBundle('test', jaBundle);
133
- const jaMessage = manager.loadMessageBundle({ locale: 'ja' });
134
- expect(jaMessage.localize('hello')).toBe('こんにちは');
135
- });
136
- it('should throw error when no base messages are registered', () => {
137
- const manager = advancedLocalization_1.MessageBundleManager.getInstance('test');
138
- expect(() => manager.loadMessageBundle()).toThrow('No base messages registered');
139
- });
140
- it('should handle multiple locale bundles', () => {
141
- const manager = advancedLocalization_1.MessageBundleManager.getInstance('test');
142
- const baseBundle = {
143
- type: 'base',
144
- messages: {
145
- hello: 'Hello',
146
- world: 'World'
147
- }
148
- };
149
- const jaBundle = {
150
- type: 'locale',
151
- locale: 'ja',
152
- messages: {
153
- _locale: 'ja',
154
- hello: 'こんにちは'
155
- }
156
- };
157
- manager.registerMessageBundle('test', baseBundle);
158
- manager.registerMessageBundle('test', jaBundle);
159
- const jaMessage = manager.loadMessageBundle({ locale: 'ja' });
160
- // Should get Japanese for 'hello' and fall back to English for 'world'
161
- expect(jaMessage.localize('hello')).toBe('こんにちは');
162
- expect(jaMessage.localize('world')).toBe('World');
163
- });
164
- });
165
- describe('LocalizationService', () => {
166
- it('should create separate instances for different instance names', () => {
167
- const service1 = advancedLocalization_1.LocalizationService.getInstance('test1');
168
- const service2 = advancedLocalization_1.LocalizationService.getInstance('test2');
169
- expect(service1).not.toBe(service2);
170
- });
171
- it('should return the same instance for the same instance name', () => {
172
- const service1 = advancedLocalization_1.LocalizationService.getInstance('test');
173
- const service2 = advancedLocalization_1.LocalizationService.getInstance('test');
174
- expect(service1).toBe(service2);
175
- });
176
- it('should provide access to message bundle manager', () => {
177
- const service = advancedLocalization_1.LocalizationService.getInstance('test');
178
- expect(service.messageBundleManager).toBeInstanceOf(advancedLocalization_1.MessageBundleManager);
179
- });
180
- it('should localize messages after registering bundles', () => {
181
- const service = advancedLocalization_1.LocalizationService.getInstance('test');
182
- const baseBundle = {
183
- type: 'base',
184
- messages: {
185
- greeting: 'Hello %s',
186
- farewell: 'Goodbye %s'
187
- }
188
- };
189
- service.messageBundleManager.registerMessageBundle('test', baseBundle);
190
- expect(service.localize('greeting', 'World')).toBe('Hello World');
191
- expect(service.localize('farewell', 'Friend')).toBe('Goodbye Friend');
192
- });
193
- it('should handle fallback localization when no messages are registered', () => {
194
- const service = advancedLocalization_1.LocalizationService.getInstance('test');
195
- const result = service.localize('nonexistent');
196
- expect(consoleWarnSpy).toHaveBeenCalledWith(expect.stringContaining("No messages registered for instance 'test'"));
197
- expect(result).toContain('!!! MISSING LABEL !!!');
198
- });
199
- it('should refresh localization when bundles are updated', () => {
200
- const service = advancedLocalization_1.LocalizationService.getInstance('test');
201
- const baseBundle1 = {
202
- type: 'base',
203
- messages: {
204
- message: 'Original Message'
205
- }
206
- };
207
- service.messageBundleManager.registerMessageBundle('test', baseBundle1);
208
- expect(service.localize('message')).toBe('Original Message');
209
- // Add a locale bundle to test refresh functionality
210
- const localeBundle = {
211
- type: 'locale',
212
- locale: 'ja',
213
- messages: {
214
- _locale: 'ja',
215
- message: 'Japanese Message'
216
- }
217
- };
218
- service.messageBundleManager.registerMessageBundle('test', localeBundle);
219
- // The service should still use the base message since it uses default locale
220
- expect(service.localize('message')).toBe('Original Message');
221
- // But we can verify the Japanese message is available through the bundle manager
222
- const jaMessage = service.messageBundleManager.loadMessageBundle({ locale: 'ja' });
223
- expect(jaMessage.localize('message')).toBe('Japanese Message');
224
- });
225
- it('should handle locale-specific localization', () => {
226
- const service = advancedLocalization_1.LocalizationService.getInstance('test');
227
- const baseBundle = {
228
- type: 'base',
229
- messages: {
230
- welcome: 'Welcome'
231
- }
232
- };
233
- const jaBundle = {
234
- type: 'locale',
235
- locale: 'ja',
236
- messages: {
237
- _locale: 'ja',
238
- welcome: 'いらっしゃいませ'
239
- }
240
- };
241
- service.messageBundleManager.registerMessageBundle('test', baseBundle);
242
- service.messageBundleManager.registerMessageBundle('test', jaBundle);
243
- // The service uses the default locale, but we can test through the bundle manager
244
- const jaMessage = service.messageBundleManager.loadMessageBundle({ locale: 'ja' });
245
- expect(jaMessage.localize('welcome')).toBe('いらっしゃいませ');
246
- });
247
- it('should access nls property lazily', () => {
248
- const service = advancedLocalization_1.LocalizationService.getInstance('test');
249
- // First access should trigger lazy initialization
250
- const nls1 = service.nls;
251
- const nls2 = service.nls;
252
- expect(nls1).toBe(nls2); // Should be the same instance
253
- });
254
- it('should refresh localization and reinitialize nls', () => {
255
- const service = advancedLocalization_1.LocalizationService.getInstance('test');
256
- const baseBundle = {
257
- type: 'base',
258
- messages: {
259
- test: 'Test Message'
260
- }
261
- };
262
- service.messageBundleManager.registerMessageBundle('test', baseBundle);
263
- const nls1 = service.nls;
264
- service.refreshLocalization();
265
- const nls2 = service.nls;
266
- // Should be different instances after refresh
267
- expect(nls1).not.toBe(nls2);
268
- });
269
- });
270
- describe('Integration Tests', () => {
271
- it('should handle complete localization workflow', () => {
272
- const service = advancedLocalization_1.LocalizationService.getInstance('integration-test');
273
- // Register base messages
274
- const baseBundle = {
275
- type: 'base',
276
- messages: {
277
- 'app.title': 'Salesforce Extensions',
278
- 'error.generic': 'An error occurred: %s',
279
- 'success.operation': 'Operation completed successfully'
280
- }
281
- };
282
- // Register Japanese messages
283
- const jaBundle = {
284
- type: 'locale',
285
- locale: 'ja',
286
- messages: {
287
- _locale: 'ja',
288
- 'app.title': 'Salesforceエクステンション',
289
- 'error.generic': 'エラーが発生しました: %s'
290
- // Note: 'success.operation' is not translated, should fall back to base
291
- }
292
- };
293
- service.messageBundleManager.registerMessageBundle('integration-test', baseBundle);
294
- service.messageBundleManager.registerMessageBundle('integration-test', jaBundle);
295
- // Test English localization
296
- const enMessage = service.messageBundleManager.loadMessageBundle({ locale: 'en' });
297
- expect(enMessage.localize('app.title')).toBe('Salesforce Extensions');
298
- expect(enMessage.localize('error.generic', 'Connection failed')).toBe('An error occurred: Connection failed');
299
- // Test Japanese localization
300
- const jaMessage = service.messageBundleManager.loadMessageBundle({ locale: 'ja' });
301
- expect(jaMessage.localize('app.title')).toBe('Salesforceエクステンション');
302
- expect(jaMessage.localize('error.generic', 'Connection failed')).toBe('エラーが発生しました: Connection failed');
303
- expect(jaMessage.localize('success.operation')).toBe('Operation completed successfully'); // Falls back to base
304
- });
305
- it('should handle message bundle manager and service interaction', () => {
306
- const service = advancedLocalization_1.LocalizationService.getInstance('interaction-test');
307
- const baseBundle = {
308
- type: 'base',
309
- messages: {
310
- message: 'Hello World'
311
- }
312
- };
313
- // Register bundle through service's message bundle manager
314
- service.messageBundleManager.registerMessageBundle('interaction-test', baseBundle);
315
- // Should automatically refresh the service's localization
316
- expect(service.localize('message')).toBe('Hello World');
317
- });
318
- it('should handle multiple services with different bundles', () => {
319
- const service1 = advancedLocalization_1.LocalizationService.getInstance('service1');
320
- const service2 = advancedLocalization_1.LocalizationService.getInstance('service2');
321
- const bundle1 = {
322
- type: 'base',
323
- messages: {
324
- service: 'Service 1'
325
- }
326
- };
327
- const bundle2 = {
328
- type: 'base',
329
- messages: {
330
- service: 'Service 2'
331
- }
332
- };
333
- service1.messageBundleManager.registerMessageBundle('service1', bundle1);
334
- service2.messageBundleManager.registerMessageBundle('service2', bundle2);
335
- expect(service1.localize('service')).toBe('Service 1');
336
- expect(service2.localize('service')).toBe('Service 2');
337
- });
338
- });
339
- });
340
- //# sourceMappingURL=advancedLocalization.test.js.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=localization.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"localization.test.d.ts","sourceRoot":"","sources":["../../../../test/jest/i18n/localization.test.ts"],"names":[],"mappings":""}
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /*
4
- * Copyright (c) 2022, salesforce.com, inc.
5
- * All rights reserved.
6
- * Licensed under the BSD 3-Clause license.
7
- * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
8
- */
9
- const localization_1 = require("../../../src/i18n/localization");
10
- const message_1 = require("../../../src/i18n/message");
11
- describe('Localization Unit Tests.', () => {
12
- const fakeMessages = { a: 'a', b: 'b', c: 'c' };
13
- const localizaedValue = 'hooray';
14
- let delegateLocalizeSpy;
15
- beforeEach(() => {
16
- delegateLocalizeSpy = jest.spyOn(message_1.Message.prototype, 'localize').mockReturnValue(localizaedValue);
17
- });
18
- it('Should be able to create an instance.', () => {
19
- const fakeMessage = new message_1.Message(fakeMessages, undefined);
20
- const localization = new localization_1.Localization(fakeMessage);
21
- expect(localization).toBeInstanceOf(localization_1.Localization);
22
- expect(localization.delegate).toEqual(fakeMessage);
23
- });
24
- it('Should call though localize calls to delegate.', () => {
25
- const fakeMessage = new message_1.Message(fakeMessages, undefined);
26
- const localization = new localization_1.Localization(fakeMessage);
27
- const result = localization.localize('fakeLabel', 1, true, 'fake');
28
- expect(result).toEqual(localizaedValue);
29
- expect(delegateLocalizeSpy).toHaveBeenCalledWith('fakeLabel', 1, true, 'fake');
30
- });
31
- });
32
- //# sourceMappingURL=localization.test.js.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=message.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message.test.d.ts","sourceRoot":"","sources":["../../../../test/jest/i18n/message.test.ts"],"names":[],"mappings":""}
@@ -1,153 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /*
4
- * Copyright (c) 2022, salesforce.com, inc.
5
- * All rights reserved.
6
- * Licensed under the BSD 3-Clause license.
7
- * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
8
- */
9
- const constants_1 = require("../../../src/constants");
10
- const message_1 = require("../../../src/i18n/message");
11
- describe('Message Unit Tests.', () => {
12
- const messageBundle = {
13
- a: 'a',
14
- b: 'b',
15
- c: 'c',
16
- e: '%s:%s',
17
- f: '1 %s 2 %s 3 %s',
18
- integerFormat: 'Value: %i',
19
- decimalFormat: 'Price: %d',
20
- floatFormat: 'Temperature: %f degrees',
21
- jsonFormat: 'Data: %j',
22
- mixedFormat: 'User %s has %d points and data %j',
23
- percentLiteralFormat: 'Progress: 100%% complete',
24
- multiTypeFormat: 'String: %s, Integer: %i, Float: %f, JSON: %j'
25
- };
26
- const backupMessageBundle = { a: '1', b: '2', c: '3', d: '4' };
27
- let delegate;
28
- beforeEach(() => {
29
- delegate = new message_1.Message(backupMessageBundle);
30
- // Avoid printing warnings in tests.
31
- jest.spyOn(console, 'warn');
32
- jest.spyOn(console, 'log');
33
- });
34
- it('Should be able to create an instance.', () => {
35
- const message = new message_1.Message(messageBundle, delegate);
36
- expect(message).toBeInstanceOf(message_1.Message);
37
- });
38
- it('Should find the label in the primary messageBundle.', () => {
39
- const message = new message_1.Message(messageBundle, delegate);
40
- const label = message.localize('a');
41
- expect(label).toEqual(messageBundle.a);
42
- });
43
- it('Should find the label in the delegate messageBundle.', () => {
44
- const message = new message_1.Message(messageBundle, delegate);
45
- const label = message.localize('d');
46
- expect(label).toEqual(backupMessageBundle.d);
47
- });
48
- describe('label not found', () => {
49
- it('Should return error label if not found in either bundle.', () => {
50
- const message = new message_1.Message(messageBundle, delegate);
51
- const labelKey = 'notAKey';
52
- const label = message.localize(labelKey);
53
- const expected = `${constants_1.MISSING_LABEL_MSG} ${labelKey}`;
54
- expect(label).toEqual(expected);
55
- });
56
- it('Should return error label with args if not found in either bundle.', () => {
57
- const message = new message_1.Message(messageBundle, delegate);
58
- const labelKey = 'notAKey';
59
- const arg1 = 'arg1';
60
- const arg2 = 'arg2';
61
- const label = message.localize(labelKey, arg1, arg2);
62
- const expected = `${constants_1.MISSING_LABEL_MSG} ${labelKey} (${arg1}) (${arg2})`;
63
- expect(label).toEqual(expected);
64
- });
65
- it('Should return error label if no delegate and no lable found.', () => {
66
- const message = new message_1.Message(messageBundle);
67
- const labelKey = 'notAKey';
68
- const label = message.localize(labelKey);
69
- const expected = `${constants_1.MISSING_LABEL_MSG} ${labelKey}`;
70
- expect(label).toEqual(expected);
71
- });
72
- });
73
- describe('passing arguments', () => {
74
- it('Should correctly populate args.', () => {
75
- const message = new message_1.Message(messageBundle, delegate);
76
- const arg1 = 'arg1';
77
- const arg2 = 'arg2';
78
- const label = message.localize('e', arg1, arg2);
79
- const expected = `${arg1}:${arg2}`;
80
- expect(label).toEqual(expected);
81
- });
82
- it('Should ignore extra args.', () => {
83
- const message = new message_1.Message(messageBundle, delegate);
84
- const arg1 = 'arg1';
85
- const arg2 = 'arg2';
86
- const label = message.localize('e', arg1, arg2, 'arg3', 'arg4', 'arg5');
87
- const expected = `${arg1}:${arg2}`;
88
- expect(label).toEqual(expected);
89
- });
90
- it('Should only partially populate if too few args are passed.', () => {
91
- const message = new message_1.Message(messageBundle, delegate);
92
- const arg1 = 'arg1';
93
- const label = message.localize('e', arg1);
94
- const expected = `${arg1}:%s`;
95
- expect(label).toEqual(expected);
96
- });
97
- describe('format specifiers', () => {
98
- it('Should handle %i (integer) format specifier.', () => {
99
- const message = new message_1.Message(messageBundle, delegate);
100
- const label = message.localize('integerFormat', 42);
101
- expect(label).toEqual('Value: 42');
102
- });
103
- it('Should handle %d (decimal) format specifier.', () => {
104
- const message = new message_1.Message(messageBundle, delegate);
105
- const label = message.localize('decimalFormat', 99);
106
- expect(label).toEqual('Price: 99');
107
- });
108
- it('Should handle %f (float) format specifier.', () => {
109
- const message = new message_1.Message(messageBundle, delegate);
110
- const label = message.localize('floatFormat', 23.5);
111
- expect(label).toEqual('Temperature: 23.5 degrees');
112
- });
113
- it('Should handle %j (JSON) format specifier.', () => {
114
- const message = new message_1.Message(messageBundle, delegate);
115
- const testObj = { name: 'test', value: 123 };
116
- const label = message.localize('jsonFormat', testObj);
117
- expect(label).toEqual('Data: {"name":"test","value":123}');
118
- });
119
- it('Should handle mixed format specifiers.', () => {
120
- const message = new message_1.Message(messageBundle, delegate);
121
- const testData = { role: 'admin', permissions: ['read', 'write'] };
122
- const label = message.localize('mixedFormat', 'John', 150, testData);
123
- expect(label).toEqual('User John has 150 points and data {"role":"admin","permissions":["read","write"]}');
124
- });
125
- it('Should handle %% (literal percent) without consuming arguments.', () => {
126
- const message = new message_1.Message(messageBundle, delegate);
127
- const label = message.localize('percentLiteralFormat');
128
- // Node.js util.format() only converts %% to % when there are arguments
129
- expect(label).toEqual('Progress: 100%% complete');
130
- });
131
- it('Should handle all format specifiers together.', () => {
132
- const message = new message_1.Message(messageBundle, delegate);
133
- const testObj = { status: 'active' };
134
- const label = message.localize('multiTypeFormat', 'example', 42, 3.14, testObj);
135
- expect(label).toEqual('String: example, Integer: 42, Float: 3.14, JSON: {"status":"active"}');
136
- });
137
- it('Should count format specifiers correctly and ignore %%.', () => {
138
- const message = new message_1.Message(messageBundle, delegate);
139
- // This should not consume any arguments since %% is a literal
140
- const label = message.localize('percentLiteralFormat', 'extraArg');
141
- // The localize method correctly removes extra args, so %% stays as %%
142
- expect(label).toEqual('Progress: 100%% complete');
143
- });
144
- it('Should handle partial population with mixed format specifiers.', () => {
145
- const message = new message_1.Message(messageBundle, delegate);
146
- const label = message.localize('multiTypeFormat', 'test', 10);
147
- // Should populate first two and leave the rest as-is
148
- expect(label).toEqual('String: test, Integer: 10, Float: %f, JSON: %j');
149
- });
150
- });
151
- });
152
- });
153
- //# sourceMappingURL=message.test.js.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=localization.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"localization.test.d.ts","sourceRoot":"","sources":["../../../../test/jest/types/localization.test.ts"],"names":[],"mappings":""}
@@ -1,132 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2024, salesforce.com, inc.
4
- * All rights reserved.
5
- * Licensed under the BSD 3-Clause license.
6
- * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- describe('Localization Types Unit Tests', () => {
10
- describe('Locale Type', () => {
11
- it('should accept valid locale values', () => {
12
- const enLocale = 'en';
13
- const jaLocale = 'ja';
14
- expect(enLocale).toBe('en');
15
- expect(jaLocale).toBe('ja');
16
- });
17
- });
18
- describe('Config Type', () => {
19
- it('should create valid config objects', () => {
20
- const enConfig = { locale: 'en' };
21
- const jaConfig = { locale: 'ja' };
22
- expect(enConfig.locale).toBe('en');
23
- expect(jaConfig.locale).toBe('ja');
24
- });
25
- });
26
- describe('MessageBundle Type', () => {
27
- it('should create valid message bundle objects', () => {
28
- const messageBundle = {
29
- hello: 'Hello',
30
- goodbye: 'Goodbye',
31
- greeting: 'Hello %s'
32
- };
33
- expect(messageBundle.hello).toBe('Hello');
34
- expect(messageBundle.goodbye).toBe('Goodbye');
35
- expect(messageBundle.greeting).toBe('Hello %s');
36
- });
37
- it('should allow empty message bundles', () => {
38
- const emptyBundle = {};
39
- expect(Object.keys(emptyBundle)).toHaveLength(0);
40
- });
41
- });
42
- describe('AdvancedMessageBundle Type', () => {
43
- it('should create valid base message bundles', () => {
44
- const baseBundle = {
45
- type: 'base',
46
- messages: {
47
- 'app.title': 'My Application',
48
- 'error.generic': 'An error occurred'
49
- }
50
- };
51
- expect(baseBundle.type).toBe('base');
52
- expect(baseBundle.messages['app.title']).toBe('My Application');
53
- expect(baseBundle.locale).toBeUndefined();
54
- });
55
- it('should create valid locale message bundles with explicit locale', () => {
56
- const localeBundle = {
57
- type: 'locale',
58
- locale: 'ja',
59
- messages: {
60
- _locale: 'ja',
61
- 'app.title': 'マイアプリケーション',
62
- 'error.generic': 'エラーが発生しました'
63
- }
64
- };
65
- expect(localeBundle.type).toBe('locale');
66
- expect(localeBundle.locale).toBe('ja');
67
- expect(localeBundle.messages['_locale']).toBe('ja');
68
- expect(localeBundle.messages['app.title']).toBe('マイアプリケーション');
69
- });
70
- it('should create valid locale message bundles without explicit locale', () => {
71
- const localeBundle = {
72
- type: 'locale',
73
- messages: {
74
- _locale: 'ja',
75
- 'app.title': 'マイアプリケーション'
76
- }
77
- };
78
- expect(localeBundle.type).toBe('locale');
79
- expect(localeBundle.locale).toBeUndefined();
80
- expect(localeBundle.messages['_locale']).toBe('ja');
81
- });
82
- it('should handle empty message bundles', () => {
83
- const emptyBaseBundle = {
84
- type: 'base',
85
- messages: {}
86
- };
87
- const emptyLocaleBundle = {
88
- type: 'locale',
89
- locale: 'en',
90
- messages: {}
91
- };
92
- expect(emptyBaseBundle.type).toBe('base');
93
- expect(Object.keys(emptyBaseBundle.messages)).toHaveLength(0);
94
- expect(emptyLocaleBundle.type).toBe('locale');
95
- expect(Object.keys(emptyLocaleBundle.messages)).toHaveLength(0);
96
- });
97
- });
98
- describe('Type Compatibility', () => {
99
- it('should allow MessageBundle to be used in AdvancedMessageBundle', () => {
100
- const simpleBundle = {
101
- key1: 'value1',
102
- key2: 'value2'
103
- };
104
- const advancedBundle = {
105
- type: 'base',
106
- messages: simpleBundle
107
- };
108
- expect(advancedBundle.messages).toBe(simpleBundle);
109
- });
110
- it('should handle complex message structures', () => {
111
- const complexBundle = {
112
- type: 'locale',
113
- locale: 'ja',
114
- messages: {
115
- _locale: 'ja',
116
- 'nested.key.deep': 'Deep nested value',
117
- 'format.string': 'Hello %s, you have %d messages',
118
- 'boolean.key': 'true',
119
- 'number.key': '42',
120
- 'special.chars': 'Special chars: !@#$%^&*()',
121
- 'unicode.chars': '日本語のテキスト',
122
- 'empty.value': ''
123
- }
124
- };
125
- expect(complexBundle.messages['nested.key.deep']).toBe('Deep nested value');
126
- expect(complexBundle.messages['format.string']).toBe('Hello %s, you have %d messages');
127
- expect(complexBundle.messages['unicode.chars']).toBe('日本語のテキスト');
128
- expect(complexBundle.messages['empty.value']).toBe('');
129
- });
130
- });
131
- });
132
- //# sourceMappingURL=localization.test.js.map