@ui5/webcomponents-localization 1.22.0-rc.0 → 1.22.0-rc.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.
Files changed (128) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/generated/assets/cldr/ar.json +102 -62
  4. package/dist/generated/assets/cldr/ar_EG.json +102 -62
  5. package/dist/generated/assets/cldr/ar_SA.json +102 -62
  6. package/dist/generated/assets/cldr/bg.json +364 -325
  7. package/dist/generated/assets/cldr/ca.json +491 -453
  8. package/dist/generated/assets/cldr/cs.json +431 -324
  9. package/dist/generated/assets/cldr/cy.json +608 -340
  10. package/dist/generated/assets/cldr/da.json +290 -227
  11. package/dist/generated/assets/cldr/de.json +348 -241
  12. package/dist/generated/assets/cldr/de_AT.json +348 -241
  13. package/dist/generated/assets/cldr/de_CH.json +347 -240
  14. package/dist/generated/assets/cldr/el.json +128 -100
  15. package/dist/generated/assets/cldr/el_CY.json +128 -100
  16. package/dist/generated/assets/cldr/en.json +538 -512
  17. package/dist/generated/assets/cldr/en_AU.json +583 -520
  18. package/dist/generated/assets/cldr/en_GB.json +485 -441
  19. package/dist/generated/assets/cldr/en_HK.json +519 -474
  20. package/dist/generated/assets/cldr/en_IE.json +485 -440
  21. package/dist/generated/assets/cldr/en_IN.json +465 -420
  22. package/dist/generated/assets/cldr/en_NZ.json +505 -460
  23. package/dist/generated/assets/cldr/en_PG.json +505 -460
  24. package/dist/generated/assets/cldr/en_SG.json +505 -460
  25. package/dist/generated/assets/cldr/en_ZA.json +485 -440
  26. package/dist/generated/assets/cldr/es.json +709 -456
  27. package/dist/generated/assets/cldr/es_AR.json +687 -434
  28. package/dist/generated/assets/cldr/es_BO.json +721 -468
  29. package/dist/generated/assets/cldr/es_CL.json +567 -422
  30. package/dist/generated/assets/cldr/es_CO.json +485 -339
  31. package/dist/generated/assets/cldr/es_MX.json +734 -481
  32. package/dist/generated/assets/cldr/es_PE.json +409 -372
  33. package/dist/generated/assets/cldr/es_UY.json +433 -396
  34. package/dist/generated/assets/cldr/es_VE.json +453 -416
  35. package/dist/generated/assets/cldr/et.json +340 -307
  36. package/dist/generated/assets/cldr/fa.json +96 -34
  37. package/dist/generated/assets/cldr/fi.json +359 -308
  38. package/dist/generated/assets/cldr/fr.json +347 -321
  39. package/dist/generated/assets/cldr/fr_BE.json +347 -321
  40. package/dist/generated/assets/cldr/fr_CA.json +458 -432
  41. package/dist/generated/assets/cldr/fr_CH.json +290 -264
  42. package/dist/generated/assets/cldr/fr_LU.json +347 -321
  43. package/dist/generated/assets/cldr/he.json +241 -130
  44. package/dist/generated/assets/cldr/hi.json +103 -53
  45. package/dist/generated/assets/cldr/hr.json +467 -410
  46. package/dist/generated/assets/cldr/hu.json +246 -195
  47. package/dist/generated/assets/cldr/id.json +478 -406
  48. package/dist/generated/assets/cldr/it.json +418 -362
  49. package/dist/generated/assets/cldr/it_CH.json +418 -362
  50. package/dist/generated/assets/cldr/ja.json +58 -18
  51. package/dist/generated/assets/cldr/kk.json +562 -398
  52. package/dist/generated/assets/cldr/ko.json +36 -15
  53. package/dist/generated/assets/cldr/lt.json +320 -231
  54. package/dist/generated/assets/cldr/lv.json +184 -120
  55. package/dist/generated/assets/cldr/ms.json +460 -388
  56. package/dist/generated/assets/cldr/nb.json +160 -92
  57. package/dist/generated/assets/cldr/nl.json +621 -373
  58. package/dist/generated/assets/cldr/nl_BE.json +621 -373
  59. package/dist/generated/assets/cldr/pl.json +590 -279
  60. package/dist/generated/assets/cldr/pt.json +696 -334
  61. package/dist/generated/assets/cldr/pt_PT.json +730 -454
  62. package/dist/generated/assets/cldr/ro.json +409 -339
  63. package/dist/generated/assets/cldr/ru.json +317 -279
  64. package/dist/generated/assets/cldr/ru_UA.json +312 -274
  65. package/dist/generated/assets/cldr/sk.json +454 -413
  66. package/dist/generated/assets/cldr/sl.json +118 -80
  67. package/dist/generated/assets/cldr/sr.json +294 -142
  68. package/dist/generated/assets/cldr/sr_Latn.json +972 -824
  69. package/dist/generated/assets/cldr/sv.json +382 -338
  70. package/dist/generated/assets/cldr/th.json +56 -36
  71. package/dist/generated/assets/cldr/tr.json +371 -320
  72. package/dist/generated/assets/cldr/uk.json +340 -290
  73. package/dist/generated/assets/cldr/vi.json +352 -328
  74. package/dist/generated/assets/cldr/zh_CN.json +34 -10
  75. package/dist/generated/assets/cldr/zh_HK.json +33 -9
  76. package/dist/generated/assets/cldr/zh_SG.json +33 -9
  77. package/dist/generated/assets/cldr/zh_TW.json +32 -8
  78. package/dist/sap/base/Event.js +59 -0
  79. package/dist/sap/base/Eventing.js +146 -0
  80. package/dist/sap/base/Log.js +2 -239
  81. package/dist/sap/base/assert.js +28 -1
  82. package/dist/sap/base/config/MemoryConfigurationProvider.js +20 -0
  83. package/dist/sap/base/config.js +17 -0
  84. package/dist/sap/base/i18n/Formatting.js +1130 -0
  85. package/dist/sap/base/i18n/LanguageTag.js +168 -30
  86. package/dist/sap/base/i18n/date/CalendarType.js +36 -1
  87. package/dist/sap/base/i18n/date/CalendarWeekNumbering.js +76 -1
  88. package/dist/sap/base/i18n/date/TimezoneUtils.js +242 -12
  89. package/dist/sap/base/strings/camelize.js +30 -0
  90. package/dist/sap/base/strings/formatMessage.js +88 -15
  91. package/dist/sap/base/util/ObjectPath.js +95 -3
  92. package/dist/sap/base/util/Version.js +157 -0
  93. package/dist/sap/base/util/_merge.js +83 -26
  94. package/dist/sap/base/util/array/uniqueSort.js +37 -15
  95. package/dist/sap/base/util/deepClone.js +102 -0
  96. package/dist/sap/base/util/deepEqual.js +75 -51
  97. package/dist/sap/base/util/extend.js +58 -7
  98. package/dist/sap/base/util/isEmptyObject.js +34 -0
  99. package/dist/sap/base/util/isPlainObject.js +35 -1
  100. package/dist/sap/base/util/now.js +24 -3
  101. package/dist/sap/base/util/resolveReference.js +157 -0
  102. package/dist/sap/base/util/uid.js +27 -0
  103. package/dist/sap/ui/base/DataType.js +657 -0
  104. package/dist/sap/ui/base/Interface.js +47 -1
  105. package/dist/sap/ui/base/Metadata.js +433 -180
  106. package/dist/sap/ui/base/Object.js +284 -48
  107. package/dist/sap/ui/core/CalendarType.js +23 -1
  108. package/dist/sap/ui/core/Locale.js +189 -57
  109. package/dist/sap/ui/core/LocaleData.js +2670 -1380
  110. package/dist/sap/ui/core/Supportability.js +5 -0
  111. package/dist/sap/ui/core/Theming.js +539 -0
  112. package/dist/sap/ui/core/date/Buddhist.js +162 -87
  113. package/dist/sap/ui/core/date/CalendarUtils.js +61 -21
  114. package/dist/sap/ui/core/date/CalendarWeekNumbering.js +29 -1
  115. package/dist/sap/ui/core/date/Gregorian.js +25 -10
  116. package/dist/sap/ui/core/date/Islamic.js +298 -185
  117. package/dist/sap/ui/core/date/Japanese.js +210 -115
  118. package/dist/sap/ui/core/date/Persian.js +324 -195
  119. package/dist/sap/ui/core/date/UI5Date.js +923 -237
  120. package/dist/sap/ui/core/date/UniversalDate.js +1238 -245
  121. package/dist/sap/ui/core/date/_Calendars.js +10 -1
  122. package/dist/sap/ui/core/format/DateFormat.js +3163 -2145
  123. package/dist/sap/ui/core/format/TimezoneUtil.js +23 -1
  124. package/package-scripts.cjs +4 -10
  125. package/package.json +9 -5
  126. package/tsconfig.json +2 -1
  127. package/used-modules.txt +20 -1
  128. package/dist/sap/ui/Device.js +0 -5
@@ -0,0 +1,1130 @@
1
+ /*!
2
+ * OpenUI5
3
+ * (c) Copyright 2009-2024 SAP SE or an SAP affiliate company.
4
+ * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
5
+ */
6
+ import assert from "../assert.js";
7
+ import BaseConfig from "../config.js";
8
+ import Eventing from "../Eventing.js";
9
+ import Log from "../Log.js";
10
+ import Localization from "./Localization.js";
11
+ import LanguageTag from "./LanguageTag.js";
12
+ import CalendarType from "./date/CalendarType.js";
13
+ import CalendarWeekNumbering from "./date/CalendarWeekNumbering.js";
14
+ import deepEqual from "../util/deepEqual.js";
15
+ import extend from "../util/extend.js";
16
+ import isEmptyObject from "../util/isEmptyObject.js";
17
+ const oEventing = new Eventing();
18
+ const oWritableConfig = BaseConfig.getWritableInstance();
19
+ const mSettings = {};
20
+ let mChanges;
21
+ let aCustomIslamicCalendarData;
22
+ const M_ABAP_DATE_FORMAT_PATTERN = {
23
+ "": {
24
+ pattern: null
25
+ },
26
+ "1": {
27
+ pattern: "dd.MM.yyyy"
28
+ },
29
+ "2": {
30
+ pattern: "MM/dd/yyyy"
31
+ },
32
+ "3": {
33
+ pattern: "MM-dd-yyyy"
34
+ },
35
+ "4": {
36
+ pattern: "yyyy.MM.dd"
37
+ },
38
+ "5": {
39
+ pattern: "yyyy/MM/dd"
40
+ },
41
+ "6": {
42
+ pattern: "yyyy-MM-dd"
43
+ },
44
+ "7": {
45
+ pattern: "Gyy.MM.dd"
46
+ },
47
+ "8": {
48
+ pattern: "Gyy/MM/dd"
49
+ },
50
+ "9": {
51
+ pattern: "Gyy-MM-dd"
52
+ },
53
+ "A": {
54
+ pattern: "yyyy/MM/dd"
55
+ },
56
+ "B": {
57
+ pattern: "yyyy/MM/dd"
58
+ },
59
+ "C": {
60
+ pattern: "yyyy/MM/dd"
61
+ }
62
+ };
63
+ const M_ABAP_TIME_FORMAT_PATTERN = {
64
+ "": {
65
+ "short": null,
66
+ medium: null,
67
+ dayPeriods: null
68
+ },
69
+ "0": {
70
+ "short": "HH:mm",
71
+ medium: "HH:mm:ss",
72
+ dayPeriods: null
73
+ },
74
+ "1": {
75
+ "short": "hh:mm a",
76
+ medium: "hh:mm:ss a",
77
+ dayPeriods: ["AM", "PM"]
78
+ },
79
+ "2": {
80
+ "short": "hh:mm a",
81
+ medium: "hh:mm:ss a",
82
+ dayPeriods: ["am", "pm"]
83
+ },
84
+ "3": {
85
+ "short": "KK:mm a",
86
+ medium: "KK:mm:ss a",
87
+ dayPeriods: ["AM", "PM"]
88
+ },
89
+ "4": {
90
+ "short": "KK:mm a",
91
+ medium: "KK:mm:ss a",
92
+ dayPeriods: ["am", "pm"]
93
+ }
94
+ };
95
+ const M_ABAP_NUMBER_FORMAT_SYMBOLS = {
96
+ "": {
97
+ groupingSeparator: null,
98
+ decimalSeparator: null
99
+ },
100
+ " ": {
101
+ groupingSeparator: ".",
102
+ decimalSeparator: ","
103
+ },
104
+ "X": {
105
+ groupingSeparator: ",",
106
+ decimalSeparator: "."
107
+ },
108
+ "Y": {
109
+ groupingSeparator: " ",
110
+ decimalSeparator: ","
111
+ }
112
+ };
113
+ function check(bCondition, sMessage) {
114
+ if (!bCondition) {
115
+ throw new TypeError(sMessage);
116
+ }
117
+ }
118
+ function _set(sKey, oValue) {
119
+ // Invalidating the BaseConfig is necessary, because Formatting.getLanguageTag
120
+ // does defaulting depending on the mSettings. In case no specifc LaguageTag was
121
+ // set the default would become applied and cached. If the mSettings are changed
122
+ // inbetween the cache would not become invalidated because there is no direct
123
+ // change to the Configuration and therefore the cached value would be wrong.
124
+ BaseConfig._.invalidate();
125
+ const oOldValue = mSettings[sKey];
126
+ if (oValue != null) {
127
+ mSettings[sKey] = oValue;
128
+ } else {
129
+ delete mSettings[sKey];
130
+ }
131
+ // report a change only if old and new value differ (null/undefined are treated as the same value)
132
+ if ((oOldValue != null || oValue != null) && !deepEqual(oOldValue, oValue)) {
133
+ const bFireEvent = !mChanges;
134
+ mChanges ??= {};
135
+ mChanges[sKey] = oValue;
136
+ if (bFireEvent) {
137
+ fireChange();
138
+ }
139
+ }
140
+ }
141
+
142
+ /**
143
+ * Helper that creates a LanguageTag object from the given language
144
+ * or, throws an error for non BCP-47 compliant languages.
145
+ *
146
+ * @param {string|module:sap/base/i18n/LanguageTag} vLanguageTag A BCP-47 compliant language tag
147
+ * @returns {module:sap/base/i18n/LanguageTag} The resulting LanguageTag
148
+ * @private
149
+ * @since 1.116.0
150
+ */
151
+ function createLanguageTag(vLanguageTag) {
152
+ let oLanguageTag;
153
+ if (vLanguageTag && typeof vLanguageTag === 'string') {
154
+ try {
155
+ oLanguageTag = new LanguageTag(vLanguageTag);
156
+ } catch (e) {
157
+ // ignore
158
+ }
159
+ } else if (vLanguageTag instanceof LanguageTag) {
160
+ oLanguageTag = vLanguageTag;
161
+ }
162
+ return oLanguageTag;
163
+ }
164
+
165
+ /**
166
+ * Configuration for formatting specific parameters
167
+ * @public
168
+ * @alias module:sap/base/i18n/Formatting
169
+ * @namespace
170
+ * @since 1.120
171
+ */
172
+ const Formatting = {
173
+ /**
174
+ * The <code>change</code> event is fired, when the configuration options are changed.
175
+ * For the event parameters please refer to {@link module:sap/base/i18n/Formatting$ChangeEvent}.
176
+ *
177
+ * @name module:sap/base/i18n/Formatting.change
178
+ * @event
179
+ * @param {module:sap/base/i18n/Formatting$ChangeEvent} oEvent
180
+ * @public
181
+ * @since 1.120
182
+ */
183
+
184
+ /**
185
+ * The formatting change event. Contains only the parameters which were changed.
186
+ *
187
+ * The list below shows the possible combinations of parameters available as part of the change event.
188
+ *
189
+ * <ul>
190
+ * <li>{@link module:sap/base/i18n/Formatting.setLanguageTag Formatting.setLanguageTag}:
191
+ * <ul>
192
+ * <li><code>languageTag</code></li>
193
+ * </ul>
194
+ * </li>
195
+ * <li>{@link module:sap/base/i18n/Formatting.setCustomIslamicCalendarData Formatting.setCustomIslamicCalendarData}:
196
+ * <ul>
197
+ * <li><code>customIslamicCalendarData</code></li>
198
+ * </ul>
199
+ * </li>
200
+ * <li>{@link module:sap/base/i18n/Formatting.setCalendarWeekNumbering Formatting.setCalendarWeekNumbering}:
201
+ * <ul>
202
+ * <li><code>calendarWeekNumbering</code></li>
203
+ * </ul>
204
+ * </li>
205
+ * <li>{@link module:sap/base/i18n/Formatting.setCalendarType Formatting.setCalendarType}:
206
+ * <ul>
207
+ * <li><code>calendarType</code></li>
208
+ * </ul>
209
+ * </li>
210
+ * <li>{@link module:sap/base/i18n/Formatting.addCustomCurrencies Formatting.addCustomCurrencies} / {@link module:sap/base/i18n/Formatting.setCustomCurrencies Formatting.setCustomCurrencies}:
211
+ * <ul>
212
+ * <li><code>currency</code></li>
213
+ * </ul>
214
+ * </li>
215
+ * <li>{@link module:sap/base/i18n/Formatting.setABAPDateFormat Formatting.setABAPDateFormat} (all parameters listed below):
216
+ * <ul>
217
+ * <li><code>ABAPDateFormat</code></li>
218
+ * <li><code>"dateFormats-short"</code></li>
219
+ * <li><code>"dateFormats-medium"</code></li>
220
+ * </ul>
221
+ * </li>
222
+ * <li>{@link module:sap/base/i18n/Formatting.setABAPTimeFormat Formatting.setABAPTimeFormat} (all parameters listed below):
223
+ * <ul>
224
+ * <li><code>ABAPTimeFormat</code></li>
225
+ * <li><code>"timeFormats-short"</code></li>
226
+ * <li><code>"timeFormats-medium"</code></li>
227
+ * <li><code>"dayPeriods-format-abbreviated"</code></li>
228
+ * </ul>
229
+ * </li>
230
+ * <li>{@link module:sap/base/i18n/Formatting.setABAPNumberFormat Formatting.setABAPNumberFormat} (all parameters listed below):
231
+ * <ul>
232
+ * <li><code>ABAPNumberFormat</code></li>
233
+ * <li><code>"symbols-latn-group"</code></li>
234
+ * <li><code>"symbols-latn-decimal"</code></li>
235
+ * </ul>
236
+ * </li>
237
+ * <li>{@link module:sap/base/i18n/Formatting.setDatePattern Formatting.setDatePattern} (one of the parameters listed below):
238
+ * <ul>
239
+ * <li><code>"dateFormats-short"</code></li>
240
+ * <li><code>"dateFormats-medium"</code></li>
241
+ * <li><code>"dateFormats-long"</code></li>
242
+ * <li><code>"dateFormats-full"</code></li>
243
+ * </ul>
244
+ * </li>
245
+ * <li>{@link module:sap/base/i18n/Formatting.setTimePattern Formatting.setTimePattern} (one of the parameters listed below):
246
+ * <ul>
247
+ * <li><code>"timeFormats-short"</code></li>
248
+ * <li><code>"timeFormats-medium"</code></li>
249
+ * <li><code>"timeFormats-long"</code></li>
250
+ * <li><code>"timeFormats-full"</code></li>
251
+ * </ul>
252
+ * </li>
253
+ * <li>{@link module:sap/base/i18n/Formatting.setNumberSymbol Formatting.setNumberSymbol} (one of the parameters listed below):
254
+ * <ul>
255
+ * <li><code>"symbols-latn-group"</code></li>
256
+ * <li><code>"symbols-latn-decimal"</code></li>
257
+ * <li><code>"symbols-latn-plusSign"</code></li>
258
+ * <li><code>"symbols-latn-minusSign"</code></li>
259
+ * </ul>
260
+ * </li>
261
+ * </ul>
262
+ *
263
+ * @typedef {object} module:sap/base/i18n/Formatting$ChangeEvent
264
+ * @property {string} [languageTag] The formatting language tag.
265
+ * @property {string} [ABAPDateFormat] The ABAP date format.
266
+ * @property {string} [ABAPTimeFormat] The ABAP time format.
267
+ * @property {string} [ABAPNumberFormat] The ABAP number format.
268
+ * @property {object[]} [legacyDateCalendarCustomizing] The legacy date calendar customizing.
269
+ * @property {object} [calendarWeekNumbering] The calendar week numbering.
270
+ * @property {object} [calendarType] The calendar type.
271
+ * @property {string} ["dateFormats-short"] The short date format.
272
+ * @property {string} ["dateFormats-medium"] The medium date format.
273
+ * @property {string} ["dateFormats-long"] The long date format.
274
+ * @property {string} ["dateFormats-full"] The full date format.
275
+ * @property {string} ["timeFormats-short"] The short time format.
276
+ * @property {string} ["timeFormats-medium"] The medium time format.
277
+ * @property {string} ["timeFormats-long"] The long time format.
278
+ * @property {string} ["timeFormats-full"] The full time format.
279
+ * @property {string} ["symbols-latn-group"] The latin symbols group.
280
+ * @property {string} ["symbols-latn-decimal"] The latin symbols decimal.
281
+ * @property {string} ["symbols-latn-plusSign"] The latin symbols plusSign.
282
+ * @property {string} ["symbols-latn-minusSign"] The latin symbols minusSign.
283
+ * @property {Object<string,string>} [currency] The currency.
284
+ * @property {string[]} ["dayPeriods-format-abbreviated"] The abbreviated day periods format.
285
+ * @public
286
+ * @since 1.120
287
+ */
288
+
289
+ /**
290
+ * Attaches the <code>fnFunction</code> event handler to the {@link #event:change change} event
291
+ * of <code>module:sap/base/i18n/Formatting</code>.
292
+ *
293
+ * @param {function(module:sap/base/i18n/Formatting$ChangeEvent)} fnFunction
294
+ * The function to be called when the event occurs
295
+ * @public
296
+ * @since 1.120
297
+ */
298
+ attachChange(fnFunction) {
299
+ oEventing.attachEvent("change", fnFunction);
300
+ },
301
+ /**
302
+ * Detaches event handler <code>fnFunction</code> from the {@link #event:change change} event of
303
+ * this <code>module:sap/base/i18n/Formatting</code>.
304
+ *
305
+ * @param {function(module:sap/base/i18n/Formatting$ChangeEvent)} fnFunction Function to be called when the event occurs
306
+ * @public
307
+ * @since 1.120
308
+ */
309
+ detachChange(fnFunction) {
310
+ oEventing.detachEvent("change", fnFunction);
311
+ },
312
+ /**
313
+ * Returns the LanguageTag to be used for formatting.
314
+ *
315
+ * If no such LanguageTag has been defined, this method falls back to the language,
316
+ * see {@link module:sap/base/i18n/Localization.getLanguage Localization.getLanguage()}.
317
+ *
318
+ * If any user preferences for date, time or number formatting have been set,
319
+ * and if no format LanguageTag has been specified, then a special private use subtag
320
+ * is added to the LanguageTag, indicating to the framework that these user preferences
321
+ * should be applied.
322
+ *
323
+ * @returns {module:sap/base/i18n/LanguageTag} the format LanguageTag
324
+ * @public
325
+ * @since 1.120
326
+ */
327
+ getLanguageTag() {
328
+ function fallback() {
329
+ let oLanguageTag = new LanguageTag(Localization.getLanguage());
330
+ // if any user settings have been defined, add the private use subtag "sapufmt"
331
+ if (!isEmptyObject(mSettings) || Formatting.getCalendarWeekNumbering() !== CalendarWeekNumbering.Default) {
332
+ let l = oLanguageTag.toString();
333
+ if (l.indexOf("-x-") < 0) {
334
+ l += "-x-sapufmt";
335
+ } else if (l.indexOf("-sapufmt") <= l.indexOf("-x-")) {
336
+ l += "-sapufmt";
337
+ }
338
+ oLanguageTag = new LanguageTag(l);
339
+ }
340
+ return oLanguageTag;
341
+ }
342
+ return oWritableConfig.get({
343
+ name: "sapUiFormatLocale",
344
+ type: function (sFormatLocale) {
345
+ return new LanguageTag(sFormatLocale);
346
+ },
347
+ defaultValue: fallback,
348
+ external: true
349
+ });
350
+ },
351
+ /**
352
+ * Sets a new language tag to be used from now on for retrieving language
353
+ * specific formatters. Modifying this setting does not have an impact on
354
+ * the retrieval of translated texts!
355
+ *
356
+ * Can either be set to a concrete value (a BCP47 or Java locale compliant
357
+ * language tag) or to <code>null</code>. When set to <code>null</code> (default
358
+ * value) then locale specific formatters are retrieved for the current language.
359
+ *
360
+ * After changing the format locale, the framework tries to update localization
361
+ * specific parts of the UI. See the documentation of
362
+ * {@link module:sap/base/i18n/Localization.setLanguage Localization.setLanguage()}
363
+ * for details and restrictions.
364
+ *
365
+ * <b>Note</b>: When a language tag is set, it has higher priority than a number,
366
+ * date or time format defined with a call to <code>setABAPNumberFormat</code>,
367
+ * <code>setABAPDateFormat</code> or <code>setABAPTimeFormat</code>.
368
+ *
369
+ * <b>Note</b>: See documentation of
370
+ * {@link module:sap/base/i18n/Localization.setLanguage Localization.setLanguage()}
371
+ * for restrictions.
372
+ *
373
+ * @param {string|module:sap/base/i18n/LanguageTag|null} vLanguageTag the new BCP47 compliant language tag;
374
+ * case doesn't matter and underscores can be used instead of dashes to separate
375
+ * components (compatibility with Java Locale IDs)
376
+ * @throws {TypeError} When <code>sLanguageTag</code> is given, but is not a valid BCP47 language
377
+ * tag or Java locale identifier
378
+ * @public
379
+ * @since 1.120
380
+ */
381
+ setLanguageTag(vLanguageTag) {
382
+ const oLanguageTag = createLanguageTag(vLanguageTag);
383
+ check(vLanguageTag == null || oLanguageTag, "vLanguageTag must be a BCP47 language tag or Java Locale id or null");
384
+ const oOldLanguageTag = Formatting.getLanguageTag();
385
+ oWritableConfig.set("sapUiFormatLocale", oLanguageTag?.toString());
386
+ const oCurrentLanguageTag = Formatting.getLanguageTag();
387
+ if (oOldLanguageTag.toString() !== oCurrentLanguageTag.toString()) {
388
+ const bFireEvent = !mChanges;
389
+ mChanges ??= {};
390
+ mChanges.languageTag = oCurrentLanguageTag.toString();
391
+ if (bFireEvent) {
392
+ fireChange();
393
+ }
394
+ }
395
+ },
396
+ /**
397
+ * @deprecated As of Version 1.120
398
+ */
399
+ _set: _set,
400
+ /**
401
+ * Retrieves the custom units.
402
+ * These custom units are set by {@link #setCustomUnits} and {@link #addCustomUnits}
403
+ * @returns {object} custom units object
404
+ * @see {@link module:sap/base/i18n/Formatting.setCustomUnits}
405
+ * @see {@link module:sap/base/i18n/Formatting.addCustomUnits}
406
+ * @private
407
+ * @since 1.116.0
408
+ */
409
+ getCustomUnits() {
410
+ return mSettings["units"]?.["short"];
411
+ },
412
+ /**
413
+ * Sets custom units which can be used to do Unit Formatting.
414
+ *
415
+ * The custom unit object consists of:
416
+ * * a custom unit key which can then be referenced to use this unit.
417
+ * * <code>displayName</code> which represents the name of the unit.
418
+ * * <code>unitPattern-count-&lt;pluralName&gt;</code> which represents the plural category of the locale for the given value.
419
+ * The plural category is defined within the locale, e.g. in the 'en' locale:
420
+ * <code>unitPattern-count-one</code> for <code>1</code>,
421
+ * <code>unitPattern-count-zero</code> for <code>0</code>,
422
+ * <code>unitPattern-count-other</code> for all the res
423
+ * To retrieve all plural categories defined for a locale use <code>sap.ui.core.LocaleData.prototype.getPluralCategories</code>.
424
+ *
425
+ * A Sample custom unit definition could look like this:
426
+ * <code>
427
+ * {
428
+ * "BAG": {
429
+ * "displayName": "Bag",
430
+ * "unitPattern-count-one": "{0} bag",
431
+ * "unitPattern-count-other": "{0} bags"
432
+ * }
433
+ * }
434
+ * </code>
435
+ * In the above snippet:
436
+ * * <code>"BAG"</code> represent the unit key which is used to reference it.
437
+ * * <code>"unitPattern-count-one"</code> represent the unit pattern for the form "one", e.g. the number <code>1</code> in the 'en' locale.
438
+ * * <code>"unitPattern-count-other"</code> represent the unit pattern for all other numbers which do not
439
+ * match the plural forms of the previous patterns.
440
+ * * In the patterns <code>{0}</code> is replaced by the number
441
+ *
442
+ * E.g. In locale 'en' value <code>1</code> would result in <code>1 Bag</code>, while <code>2</code> would result in <code>2 Bags</code>
443
+ * @param {object} mUnits custom unit object which replaces the current custom unit definition. Call with <code>null</code> to delete custom units.
444
+ * @private
445
+ * @since 1.116.0
446
+ */
447
+ setCustomUnits(mUnits) {
448
+ // add custom units, or remove the existing ones if none are given
449
+ let mUnitsshort = null;
450
+ if (mUnits) {
451
+ mUnitsshort = {
452
+ "short": mUnits
453
+ };
454
+ }
455
+ _set("units", mUnitsshort);
456
+ },
457
+ /**
458
+ * Adds custom units.
459
+ * Similar to {@link #setCustomUnits} but instead of setting the custom units, it will add additional ones.
460
+ * @param {object} mUnits custom unit object which replaces the current custom unit definition. Call with <code>null</code> to delete custom units.
461
+ * @see {@link module:sap/base/i18n/Formatting.setCustomUnits}
462
+ * @private
463
+ * @since 1.116.0
464
+ */
465
+ addCustomUnits(mUnits) {
466
+ // add custom units, or remove the existing ones if none are given
467
+ const mExistingUnits = Formatting.getCustomUnits();
468
+ if (mExistingUnits) {
469
+ mUnits = extend({}, mExistingUnits, mUnits);
470
+ }
471
+ Formatting.setCustomUnits(mUnits);
472
+ },
473
+ /**
474
+ * Sets custom unit mappings.
475
+ * Unit mappings contain key value pairs (both strings)
476
+ * * {string} key: a new entry which maps to an existing unit key
477
+ * * {string} value: an existing unit key
478
+ *
479
+ * Example:
480
+ * <code>
481
+ * {
482
+ * "my": "my-custom-unit",
483
+ * "cm": "length-centimeter"
484
+ * }
485
+ * </code>
486
+ * Note: It is possible to create multiple entries per unit key.
487
+ * Call with <code>null</code> to delete unit mappings.
488
+ * @param {object} mUnitMappings unit mappings
489
+ * @private
490
+ * @since 1.116.0
491
+ */
492
+ setUnitMappings(mUnitMappings) {
493
+ _set("unitMappings", mUnitMappings);
494
+ },
495
+ /**
496
+ * Adds unit mappings.
497
+ * Similar to {@link #setUnitMappings} but instead of setting the unit mappings, it will add additional ones.
498
+ * @param {object} mUnitMappings unit mappings
499
+ * @see {@link module:sap/base/i18n/Formatting.setUnitMappings}
500
+ * @private
501
+ * @since 1.116.0
502
+ */
503
+ addUnitMappings(mUnitMappings) {
504
+ // add custom units, or remove the existing ones if none are given
505
+ const mExistingUnits = Formatting.getUnitMappings();
506
+ if (mExistingUnits) {
507
+ mUnitMappings = extend({}, mExistingUnits, mUnitMappings);
508
+ }
509
+ Formatting.setUnitMappings(mUnitMappings);
510
+ },
511
+ /**
512
+ * Retrieves the unit mappings.
513
+ * These unit mappings are set by {@link #setUnitMappings} and {@link #addUnitMappings}
514
+ * @private
515
+ * @returns {object} unit mapping object
516
+ * @see {@link module:sap/base/i18n/Formatting.setUnitMappings}
517
+ * @see {@link module:sap/base/i18n/Formatting.addUnitMappings}
518
+ * @since 1.116.0
519
+ */
520
+ getUnitMappings() {
521
+ return mSettings["unitMappings"];
522
+ },
523
+ /**
524
+ * Returns the currently set date pattern or undefined if no pattern has been defined.
525
+ * @param {"short"|"medium"|"long"|"full"} sStyle The date style (short, medium, long or full)
526
+ * @returns {string} The resulting date pattern
527
+ * @public
528
+ * @since 1.120
529
+ */
530
+ getDatePattern(sStyle) {
531
+ assert(sStyle == "short" || sStyle == "medium" || sStyle == "long" || sStyle == "full", "sStyle must be short, medium, long or full");
532
+ return mSettings["dateFormats-" + sStyle];
533
+ },
534
+ /**
535
+ * Defines the preferred format pattern for the given date format style.
536
+ *
537
+ * Calling this method with a null or undefined pattern removes a previously set pattern.
538
+ *
539
+ * If a pattern is defined, it will be preferred over patterns derived from the current locale.
540
+ *
541
+ * See class {@link sap.ui.core.format.DateFormat} for details about the pattern syntax.
542
+ *
543
+ * After changing the date pattern, the framework tries to update localization
544
+ * specific parts of the UI. See the documentation of {@link module:sap/base/i18n/Localization.setLanguage Localization.setLanguage()}
545
+ * for details and restrictions.
546
+ *
547
+ * @param {"short"|"medium"|"long"|"full"} sStyle must be one of short, medium, long or full.
548
+ * @param {string} sPattern the format pattern to be used in LDML syntax.
549
+ * @public
550
+ * @since 1.120
551
+ */
552
+ setDatePattern(sStyle, sPattern) {
553
+ check(sStyle == "short" || sStyle == "medium" || sStyle == "long" || sStyle == "full", "sStyle must be short, medium, long or full");
554
+ _set("dateFormats-" + sStyle, sPattern);
555
+ },
556
+ /**
557
+ * Returns the currently set time pattern or undefined if no pattern has been defined.
558
+ * @param {"short"|"medium"|"long"|"full"} sStyle The time style (short, medium, long or full)
559
+ * @returns {string} The resulting time pattern
560
+ * @public
561
+ * @since 1.120
562
+ */
563
+ getTimePattern(sStyle) {
564
+ assert(sStyle == "short" || sStyle == "medium" || sStyle == "long" || sStyle == "full", "sStyle must be short, medium, long or full");
565
+ return mSettings["timeFormats-" + sStyle];
566
+ },
567
+ /**
568
+ * Defines the preferred format pattern for the given time format style.
569
+ *
570
+ * Calling this method with a null or undefined pattern removes a previously set pattern.
571
+ *
572
+ * If a pattern is defined, it will be preferred over patterns derived from the current locale.
573
+ *
574
+ * See class {@link sap.ui.core.format.DateFormat} for details about the pattern syntax.
575
+ *
576
+ * After changing the time pattern, the framework tries to update localization
577
+ * specific parts of the UI. See the documentation of
578
+ * {@link module:sap/base/i18n/Localization.setLanguage Localization.setLanguage()}
579
+ * for details and restrictions.
580
+ *
581
+ * @param {"short"|"medium"|"long"|"full"} sStyle must be one of short, medium, long or full.
582
+ * @param {string} sPattern the format pattern to be used in LDML syntax.
583
+ * @public
584
+ * @since 1.120
585
+ */
586
+ setTimePattern(sStyle, sPattern) {
587
+ check(sStyle == "short" || sStyle == "medium" || sStyle == "long" || sStyle == "full", "sStyle must be short, medium, long or full");
588
+ _set("timeFormats-" + sStyle, sPattern);
589
+ },
590
+ /**
591
+ * Returns the currently set number symbol of the given type or undefined if no symbol has been defined.
592
+ *
593
+ * @param {"group"|"decimal"|"plusSign"|"minusSign"} sType the type of symbol
594
+ * @returns {string} A non-numerical symbol used as part of a number for the given type,
595
+ * e.g. for locale de_DE:
596
+ * <ul>
597
+ * <li>"group": "." (grouping separator)</li>
598
+ * <li>"decimal": "," (decimal separator)</li>
599
+ * <li>"plusSign": "+" (plus sign)</li>
600
+ * <li>"minusSign": "-" (minus sign)</li>
601
+ * </ul>
602
+ * @public
603
+ * @since 1.120
604
+ */
605
+ getNumberSymbol(sType) {
606
+ assert(["group", "decimal", "plusSign", "minusSign"].includes(sType), "sType must be decimal, group, plusSign or minusSign");
607
+ return mSettings["symbols-latn-" + sType];
608
+ },
609
+ /**
610
+ * Defines the string to be used for the given number symbol.
611
+ *
612
+ * Calling this method with a null or undefined symbol removes a previously set symbol string.
613
+ * Note that an empty string is explicitly allowed.
614
+ *
615
+ * If a symbol is defined, it will be preferred over symbols derived from the current locale.
616
+ *
617
+ * See class {@link sap.ui.core.format.NumberFormat} for details about the symbols.
618
+ *
619
+ * After changing the number symbol, the framework tries to update localization
620
+ * specific parts of the UI. See the documentation of
621
+ * {@link module:sap/base/i18n/Localization.setLanguage Localization.setLanguage()}
622
+ * for details and restrictions.
623
+ *
624
+ * @param {"group"|"decimal"|"plusSign"|"minusSign"} sType the type of symbol
625
+ * @param {string} sSymbol will be used to represent the given symbol type
626
+ * @public
627
+ * @since 1.120
628
+ */
629
+ setNumberSymbol(sType, sSymbol) {
630
+ check(["group", "decimal", "plusSign", "minusSign"].includes(sType), "sType must be decimal, group, plusSign or minusSign");
631
+ _set("symbols-latn-" + sType, sSymbol);
632
+ },
633
+ /**
634
+ * Retrieves the custom currencies.
635
+ * E.g.
636
+ * <code>
637
+ * {
638
+ * "KWD": {"digits": 3},
639
+ * "TND" : {"digits": 3}
640
+ * }
641
+ * </code>
642
+ * @returns {object} the mapping between custom currencies and its digits
643
+ * @public
644
+ * @since 1.120
645
+ * @see {@link module:sap/base/i18n/Formatting.setCustomCurrencies}
646
+ * @see {@link module:sap/base/i18n/Formatting.addCustomCurrencies}
647
+ */
648
+ getCustomCurrencies() {
649
+ return mSettings["currency"];
650
+ },
651
+ /**
652
+ * Sets custom currencies and replaces existing entries.
653
+ *
654
+ * There is a special currency code named "DEFAULT" that is optional.
655
+ * In case it is set it will be used for all currencies not contained
656
+ * in the list, otherwise currency digits as defined by the CLDR will
657
+ * be used as a fallback.
658
+ *
659
+ * Example:
660
+ * To use CLDR, but override single currencies
661
+ * <code>
662
+ * {
663
+ * "KWD": {"digits": 3},
664
+ * "TND" : {"digits": 3}
665
+ * }
666
+ * </code>
667
+ *
668
+ * To replace the CLDR currency digits completely
669
+ * <code>
670
+ * {
671
+ * "DEFAULT": {"digits": 2},
672
+ * "ADP": {"digits": 0},
673
+ * ...
674
+ * "XPF": {"digits": 0}
675
+ * }
676
+ * </code>
677
+ *
678
+ * Note: To unset the custom currencies: call with <code>undefined</code>
679
+ * Custom currencies must not only consist of digits but contain at least one non-digit character, e.g. "a",
680
+ * so that the measure part can be distinguished from the number part.
681
+ * @public
682
+ * @since 1.120
683
+ * @param {object} mCurrencies currency map which is set
684
+ * @see {@link module:sap/base/i18n/Formatting.addCustomCurrencies}
685
+ */
686
+ setCustomCurrencies(mCurrencies) {
687
+ check(typeof mCurrencies === "object" || mCurrencies == null, "mCurrencyDigits must be an object");
688
+ Object.keys(mCurrencies || {}).forEach(function (sCurrencyDigit) {
689
+ check(typeof sCurrencyDigit === "string");
690
+ check(typeof mCurrencies[sCurrencyDigit] === "object");
691
+ });
692
+ _set("currency", mCurrencies);
693
+ },
694
+ /**
695
+ * Adds custom currencies to the existing entries.
696
+ * E.g.
697
+ * <code>
698
+ * {
699
+ * "KWD": {"digits": 3},
700
+ * "TND" : {"digits": 3}
701
+ * }
702
+ * </code>
703
+ *
704
+ * @public
705
+ * @since 1.120
706
+ * @param {object} mCurrencies adds to the currency map
707
+ * @see {@link module:sap/base/i18n/Formatting.setCustomCurrencies}
708
+ */
709
+ addCustomCurrencies(mCurrencies) {
710
+ // add custom units, or remove the existing ones if none are given
711
+ const mExistingCurrencies = Formatting.getCustomCurrencies();
712
+ if (mExistingCurrencies) {
713
+ mCurrencies = extend({}, mExistingCurrencies, mCurrencies);
714
+ }
715
+ Formatting.setCustomCurrencies(mCurrencies);
716
+ },
717
+ _setDayPeriods(sWidth, aTexts) {
718
+ assert(sWidth == "narrow" || sWidth == "abbreviated" || sWidth == "wide", "sWidth must be narrow, abbreviated or wide");
719
+ _set("dayPeriods-format-" + sWidth, aTexts);
720
+ },
721
+ /**
722
+ * Returns the currently set ABAP date format (its id) or undefined if none has been set.
723
+ *
724
+ * @returns {"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9"|"A"|"B"|"C"|undefined} ID of the ABAP date format,
725
+ * if not set or set to <code>""</code>, <code>undefined</code> will be returned
726
+ * @public
727
+ * @since 1.120
728
+ */
729
+ getABAPDateFormat() {
730
+ const sABAPDateFormat = oWritableConfig.get({
731
+ name: "sapUiABAPDateFormat",
732
+ type: BaseConfig.Type.String,
733
+ /**
734
+ * @deprecated As of Version 1.120
735
+ */
736
+ defaultValue: oWritableConfig.get({
737
+ name: "sapUiLegacyDateFormat",
738
+ type: BaseConfig.Type.String,
739
+ external: true
740
+ }),
741
+ external: true
742
+ });
743
+ return sABAPDateFormat ? sABAPDateFormat.toUpperCase() : undefined;
744
+ },
745
+ /**
746
+ * Allows to specify one of the ABAP date formats.
747
+ *
748
+ * This method modifies the date patterns for 'short' and 'medium' style with the corresponding ABAP
749
+ * format. When called with a null or undefined format id, any previously applied format will be removed.
750
+ *
751
+ * After changing the date format, the framework tries to update localization
752
+ * specific parts of the UI. See the documentation of
753
+ * {@link module:sap/base/i18n/Localization.setLanguage Localization.setLanguage()}
754
+ * for details and restrictions.
755
+ *
756
+ * @param {""|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9"|"A"|"B"|"C"} [sFormatId=""] ID of the ABAP date format,
757
+ * <code>""</code> will reset the date patterns for 'short' and 'medium' style to the
758
+ * locale-specific ones.
759
+ * @public
760
+ * @since 1.120
761
+ */
762
+ setABAPDateFormat(sFormatId) {
763
+ sFormatId = sFormatId ? String(sFormatId).toUpperCase() : "";
764
+ check(M_ABAP_DATE_FORMAT_PATTERN.hasOwnProperty(sFormatId), "sFormatId must be one of ['1','2','3','4','5','6','7','8','9','A','B','C'] or empty");
765
+ const bFireEvent = !mChanges;
766
+ const sOldFormat = Formatting.getABAPDateFormat();
767
+ if (sOldFormat !== sFormatId) {
768
+ mChanges ??= {};
769
+ oWritableConfig.set("sapUiABAPDateFormat", sFormatId);
770
+ mChanges.ABAPDateFormat = sFormatId;
771
+ Formatting.setDatePattern("short", M_ABAP_DATE_FORMAT_PATTERN[sFormatId].pattern);
772
+ Formatting.setDatePattern("medium", M_ABAP_DATE_FORMAT_PATTERN[sFormatId].pattern);
773
+ if (bFireEvent) {
774
+ fireChange();
775
+ }
776
+ }
777
+ },
778
+ /**
779
+ * Returns the currently set ABAP time format (its id) or undefined if none has been set.
780
+ *
781
+ * @returns {"0"|"1"|"2"|"3"|"4"|undefined} ID of the ABAP date format,
782
+ * if not set or set to <code>""</code>, <code>undefined</code> will be returned
783
+ * @public
784
+ * @since 1.120
785
+ */
786
+ getABAPTimeFormat() {
787
+ const sABAPTimeFormat = oWritableConfig.get({
788
+ name: "sapUiABAPTimeFormat",
789
+ type: BaseConfig.Type.String,
790
+ /**
791
+ * @deprecated As of Version 1.120
792
+ */
793
+ defaultValue: oWritableConfig.get({
794
+ name: "sapUiLegacyTimeFormat",
795
+ type: BaseConfig.Type.String,
796
+ external: true
797
+ }),
798
+ external: true
799
+ });
800
+ return sABAPTimeFormat ? sABAPTimeFormat.toUpperCase() : undefined;
801
+ },
802
+ /**
803
+ * Allows to specify one of the ABAP time formats.
804
+ *
805
+ * This method sets the time patterns for 'short' and 'medium' style to the corresponding ABAP
806
+ * formats and sets the day period texts to "AM"/"PM" or "am"/"pm" respectively. When called
807
+ * with a null or undefined format id, any previously applied format will be removed.
808
+ *
809
+ * After changing the time format, the framework tries to update localization
810
+ * specific parts of the UI. See the documentation of
811
+ * {@link module:sap/base/i18n/Localization.setLanguage Localization.setLanguage()}
812
+ * for details and restrictions.
813
+ *
814
+ * @param {""|"0"|"1"|"2"|"3"|"4"} [sFormatId=""] ID of the ABAP time format,
815
+ * <code>""</code> will reset the time patterns for 'short' and 'medium' style and the day
816
+ * period texts to the locale-specific ones.
817
+ * @public
818
+ * @since 1.120
819
+ */
820
+ setABAPTimeFormat(sFormatId) {
821
+ sFormatId = sFormatId || "";
822
+ check(M_ABAP_TIME_FORMAT_PATTERN.hasOwnProperty(sFormatId), "sFormatId must be one of ['0','1','2','3','4'] or empty");
823
+ const bFireEvent = !mChanges;
824
+ const sOldFormat = Formatting.getABAPTimeFormat();
825
+ if (sOldFormat !== sFormatId) {
826
+ mChanges ??= {};
827
+ oWritableConfig.set("sapUiABAPTimeFormat", sFormatId);
828
+ mChanges.ABAPTimeFormat = sFormatId;
829
+ Formatting.setTimePattern("short", M_ABAP_TIME_FORMAT_PATTERN[sFormatId]["short"]);
830
+ Formatting.setTimePattern("medium", M_ABAP_TIME_FORMAT_PATTERN[sFormatId]["medium"]);
831
+ Formatting._setDayPeriods("abbreviated", M_ABAP_TIME_FORMAT_PATTERN[sFormatId].dayPeriods);
832
+ if (bFireEvent) {
833
+ fireChange();
834
+ }
835
+ }
836
+ },
837
+ /**
838
+ * Returns the currently set ABAP number format (its id) or undefined if none has been set.
839
+ *
840
+ * @returns {" "|"X"|"Y"|undefined} ID of the ABAP number format,
841
+ * if not set or set to <code>""</code>, <code>undefined</code> will be returned
842
+ * @public
843
+ * @since 1.120
844
+ */
845
+ getABAPNumberFormat() {
846
+ const sABAPNumberFormat = oWritableConfig.get({
847
+ name: "sapUiABAPNumberFormat",
848
+ type: BaseConfig.Type.String,
849
+ /**
850
+ * @deprecated As of Version 1.120
851
+ */
852
+ defaultValue: oWritableConfig.get({
853
+ name: "sapUiLegacyNumberFormat",
854
+ type: BaseConfig.Type.String,
855
+ external: true
856
+ }),
857
+ external: true
858
+ });
859
+ return sABAPNumberFormat ? sABAPNumberFormat.toUpperCase() : undefined;
860
+ },
861
+ /**
862
+ * Allows to specify one of the ABAP number format.
863
+ *
864
+ * This method will modify the 'group' and 'decimal' symbols. When called with a null
865
+ * or undefined format id, any previously applied format will be removed.
866
+ *
867
+ * After changing the number format, the framework tries to update localization
868
+ * specific parts of the UI. See the documentation of
869
+ * {@link module:sap/base/i18n/Localization.setLanguage Localization.setLanguage()}
870
+ * for details and restrictions.
871
+ *
872
+ * @param {""|" "|"X"|"Y"} [sFormatId=""] ID of the ABAP number format set,
873
+ * <code>""</code> will reset the 'group' and 'decimal' symbols to the locale-specific
874
+ * ones.
875
+ * @public
876
+ * @since 1.120
877
+ */
878
+ setABAPNumberFormat(sFormatId) {
879
+ sFormatId = sFormatId ? sFormatId.toUpperCase() : "";
880
+ check(M_ABAP_NUMBER_FORMAT_SYMBOLS.hasOwnProperty(sFormatId), "sFormatId must be one of [' ','X','Y'] or empty");
881
+ const bFireEvent = !mChanges;
882
+ const sOldFormat = Formatting.getABAPNumberFormat();
883
+ if (sOldFormat !== sFormatId) {
884
+ mChanges ??= {};
885
+ oWritableConfig.set("sapUiABAPNumberFormat", sFormatId);
886
+ mChanges.ABAPNumberFormat = sFormatId;
887
+ Formatting.setNumberSymbol("group", M_ABAP_NUMBER_FORMAT_SYMBOLS[sFormatId].groupingSeparator);
888
+ Formatting.setNumberSymbol("decimal", M_ABAP_NUMBER_FORMAT_SYMBOLS[sFormatId].decimalSeparator);
889
+ if (bFireEvent) {
890
+ fireChange();
891
+ }
892
+ }
893
+ },
894
+ /**
895
+ *
896
+ * Customizing data for the support of Islamic calendar.
897
+ * Represents one row of data from Table TISLCAL.
898
+ *
899
+ * @typedef {object} module:sap/base/i18n/Formatting.CustomIslamicCalendarData
900
+ *
901
+ * @property {"A"|"B"} dateFormat The date format. Column DATFM in TISLCAL.
902
+ * @property {string} islamicMonthStart The Islamic date in format: 'yyyyMMdd'. Column ISLMONTHSTART in TISLCAL.
903
+ * @property {string} gregDate The corresponding Gregorian date format: 'yyyyMMdd'. Column GREGDATE in TISLCAL.
904
+ *
905
+ * @public
906
+ */
907
+
908
+ /**
909
+ * Allows to specify the customizing data for Islamic calendar support
910
+ *
911
+ * See: {@link module:sap/base/i18n/Formatting.CustomIslamicCalendarData}
912
+ *
913
+ * @param {module:sap/base/i18n/Formatting.CustomIslamicCalendarData[]} aCustomCalendarData Contains the customizing data for the support of Islamic calendar.
914
+ * One JSON object in the array represents one row of data from Table TISLCAL
915
+ * @public
916
+ * @since 1.120
917
+ */
918
+ setCustomIslamicCalendarData(aCustomCalendarData) {
919
+ check(Array.isArray(aCustomCalendarData), "aCustomCalendarData must be an Array");
920
+ const bFireEvent = !mChanges;
921
+ mChanges ??= {};
922
+ aCustomIslamicCalendarData = mChanges.customIslamicCalendarData = aCustomCalendarData.slice();
923
+ if (bFireEvent) {
924
+ fireChange();
925
+ }
926
+ },
927
+ /**
928
+ * Returns the currently set customizing data for Islamic calendar support.
929
+ *
930
+ * See: {@link module:sap/base/i18n/Formatting.CustomIslamicCalendarData}
931
+ *
932
+ * @returns {module:sap/base/i18n/Formatting.CustomIslamicCalendarData[]|undefined} Returns an array that contains the customizing data. Each element in the array has properties: dateFormat, islamicMonthStart, gregDate. For details, please see {@link #.setCustomIslamicCalendarData}
933
+ * @public
934
+ * @since 1.120
935
+ */
936
+ getCustomIslamicCalendarData() {
937
+ return aCustomIslamicCalendarData?.slice() ?? undefined;
938
+ },
939
+ /**
940
+ * Define whether the NumberFormatter shall always place the currency code after the numeric value, with
941
+ * the only exception of right-to-left locales, where the currency code shall be placed before the numeric value.
942
+ * Default configuration setting is <code>true</code>.
943
+ *
944
+ * When set to <code>false</code> the placement of the currency code is done dynamically, depending on the
945
+ * configured locale using data provided by the Unicode Common Locale Data Repository (CLDR).
946
+ *
947
+ * Each currency instance ({@link sap.ui.core.format.NumberFormat.getCurrencyInstance}) will be created
948
+ * with this setting unless overwritten on instance level.
949
+ *
950
+ * @param {boolean} bTrailingCurrencyCode Whether currency codes shall always be placed after the numeric value
951
+ * @public
952
+ * @since 1.120
953
+ */
954
+ setTrailingCurrencyCode(bTrailingCurrencyCode) {
955
+ check(typeof bTrailingCurrencyCode === "boolean", "bTrailingCurrencyCode must be a boolean");
956
+ oWritableConfig.set("sapUiTrailingCurrencyCode", bTrailingCurrencyCode);
957
+ },
958
+ /**
959
+ * Returns current trailingCurrencyCode configuration for new NumberFormatter instances
960
+ *
961
+ * @return {boolean} Whether currency codes shall always be placed after the numeric value
962
+ * @public
963
+ * @since 1.120
964
+ */
965
+ getTrailingCurrencyCode() {
966
+ return oWritableConfig.get({
967
+ name: "sapUiTrailingCurrencyCode",
968
+ type: BaseConfig.Type.Boolean,
969
+ defaultValue: true,
970
+ external: true
971
+ });
972
+ },
973
+ /**
974
+ * Returns a live object with the current settings
975
+ * TODO this method is part of the facade to be accessible from LocaleData, but it shouldn't be
976
+ *
977
+ * @returns {mSettings} The custom LocaleData settings object
978
+ * @private
979
+ * @ui5-restricted sap.ui.core
980
+ * @since 1.116.0
981
+ */
982
+ getCustomLocaleData() {
983
+ return mSettings;
984
+ },
985
+ /**
986
+ * Returns the calendar week numbering algorithm used to determine the first day of the week
987
+ * and the first calendar week of the year, see {@link module:sap/base/i18n/data/CalendarWeekNumbering}.
988
+ *
989
+ * @returns {module:sap/base/i18n/date/CalendarWeekNumbering} The calendar week numbering algorithm
990
+ *
991
+ * @public
992
+ * @since 1.120
993
+ */
994
+ getCalendarWeekNumbering() {
995
+ let oCalendarWeekNumbering = CalendarWeekNumbering.Default;
996
+ try {
997
+ oCalendarWeekNumbering = oWritableConfig.get({
998
+ name: "sapUiCalendarWeekNumbering",
999
+ type: CalendarWeekNumbering,
1000
+ defaultValue: CalendarWeekNumbering.Default,
1001
+ external: true
1002
+ });
1003
+ } catch (err) {
1004
+ //nothing to do, return default;
1005
+ }
1006
+ return oCalendarWeekNumbering;
1007
+ },
1008
+ /**
1009
+ * Sets the calendar week numbering algorithm which is used to determine the first day of the week
1010
+ * and the first calendar week of the year, see {@link module:sap/base/i18n/date/CalendarWeekNumbering}.
1011
+ *
1012
+ * @param {module:sap/base/i18n/date/CalendarWeekNumbering} sCalendarWeekNumbering
1013
+ * The calendar week numbering algorithm
1014
+ * @throws {TypeError}
1015
+ * If <code>sCalendarWeekNumbering</code> is not a valid calendar week numbering algorithm,
1016
+ * defined in {@link module:sap/base/i18n/date/CalendarWeekNumbering}
1017
+ *
1018
+ * @public
1019
+ * @since 1.120
1020
+ */
1021
+ setCalendarWeekNumbering(sCalendarWeekNumbering) {
1022
+ BaseConfig._.checkEnum(CalendarWeekNumbering, sCalendarWeekNumbering, "calendarWeekNumbering");
1023
+ const sCurrentWeekNumbering = oWritableConfig.get({
1024
+ name: "sapUiCalendarWeekNumbering",
1025
+ type: CalendarWeekNumbering,
1026
+ defaultValue: CalendarWeekNumbering.Default,
1027
+ external: true
1028
+ });
1029
+ if (sCurrentWeekNumbering !== sCalendarWeekNumbering) {
1030
+ const bFireEvent = !mChanges;
1031
+ mChanges ??= {};
1032
+ oWritableConfig.set("sapUiCalendarWeekNumbering", sCalendarWeekNumbering);
1033
+ mChanges.calendarWeekNumbering = sCalendarWeekNumbering;
1034
+ if (bFireEvent) {
1035
+ fireChange();
1036
+ }
1037
+ }
1038
+ },
1039
+ /**
1040
+ * Returns the calendar type which is being used in locale dependent functionality.
1041
+ *
1042
+ * When it's explicitly set by calling <code>setCalendarType</code>, the set calendar type is returned.
1043
+ * Otherwise, the calendar type is determined by checking the format settings and current locale.
1044
+ *
1045
+ * @returns {module:sap/base/i18n/date/CalendarType} the current calendar type, e.g. <code>Gregorian</code>
1046
+ * @public
1047
+ * @since 1.120
1048
+ */
1049
+ getCalendarType() {
1050
+ let sName,
1051
+ sCalendarType = oWritableConfig.get({
1052
+ name: "sapUiCalendarType",
1053
+ type: BaseConfig.Type.String,
1054
+ external: true
1055
+ });
1056
+ sCalendarType ??= null;
1057
+ if (sCalendarType) {
1058
+ for (sName in CalendarType) {
1059
+ if (sName.toLowerCase() === sCalendarType.toLowerCase()) {
1060
+ return sName;
1061
+ }
1062
+ }
1063
+ Log.warning("Parameter 'calendarType' is set to " + sCalendarType + " which isn't a valid value and therefore ignored. The calendar type is determined from format setting and current locale");
1064
+ }
1065
+ const sABAPDateFormat = Formatting.getABAPDateFormat();
1066
+ switch (sABAPDateFormat) {
1067
+ case "1":
1068
+ case "2":
1069
+ case "3":
1070
+ case "4":
1071
+ case "5":
1072
+ case "6":
1073
+ return CalendarType.Gregorian;
1074
+ case "7":
1075
+ case "8":
1076
+ case "9":
1077
+ return CalendarType.Japanese;
1078
+ case "A":
1079
+ case "B":
1080
+ return CalendarType.Islamic;
1081
+ case "C":
1082
+ return CalendarType.Persian;
1083
+ default:
1084
+ return Localization.getPreferredCalendarType();
1085
+ }
1086
+ },
1087
+ /**
1088
+ * Sets the new calendar type to be used from now on in locale dependent functionality (for example,
1089
+ * formatting, translation texts, etc.).
1090
+ *
1091
+ * @param {module:sap/base/i18n/date/CalendarType|null} sCalendarType the new calendar type. Set it with null to clear the calendar type
1092
+ * and the calendar type is calculated based on the format settings and current locale.
1093
+ * @public
1094
+ * @since 1.120
1095
+ */
1096
+ setCalendarType(sCalendarType) {
1097
+ const sOldCalendarType = Formatting.getCalendarType();
1098
+ oWritableConfig.set("sapUiCalendarType", sCalendarType);
1099
+ const sCurrentCalendarType = Formatting.getCalendarType();
1100
+ if (sOldCalendarType !== sCurrentCalendarType) {
1101
+ const bFireEvent = !mChanges;
1102
+ mChanges ??= {};
1103
+ mChanges.calendarType = sCurrentCalendarType;
1104
+ if (bFireEvent) {
1105
+ fireChange();
1106
+ }
1107
+ }
1108
+ }
1109
+ };
1110
+ function fireChange() {
1111
+ oEventing.fireEvent("change", mChanges);
1112
+ mChanges = undefined;
1113
+ }
1114
+ function init() {
1115
+ // init ABAP formats
1116
+ const sABAPDateFormat = Formatting.getABAPDateFormat();
1117
+ if (sABAPDateFormat !== undefined) {
1118
+ Formatting.setABAPDateFormat(sABAPDateFormat);
1119
+ }
1120
+ const sABAPNumberFormat = Formatting.getABAPNumberFormat();
1121
+ if (sABAPNumberFormat !== undefined) {
1122
+ Formatting.setABAPNumberFormat(sABAPNumberFormat);
1123
+ }
1124
+ const sABAPTimeFormat = Formatting.getABAPTimeFormat();
1125
+ if (sABAPTimeFormat !== undefined) {
1126
+ Formatting.setABAPTimeFormat(sABAPTimeFormat);
1127
+ }
1128
+ }
1129
+ init();
1130
+ export default Formatting;