@ui5/webcomponents-localization 1.4.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/README.md +5 -6
- package/dist/dates/convertMonthNumbersToMonthNames.js +33 -0
- package/dist/dates/getDaysInMonth.js +11 -0
- package/dist/dates/transformDateToSecondaryType.js +20 -0
- package/dist/locale/getLocaleData.js +1 -1
- package/package.json +4 -4
- package/src/dates/convertMonthNumbersToMonthNames.js +33 -0
- package/src/dates/getDaysInMonth.js +11 -0
- package/src/dates/transformDateToSecondaryType.js +20 -0
- package/src/locale/getLocaleData.js +1 -1
package/CHANGELOG.md
CHANGED
@@ -3,6 +3,33 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
+
# [1.7.0](https://github.com/SAP/ui5-webcomponents/compare/v1.6.0...v1.7.0) (2022-09-02)
|
7
|
+
|
8
|
+
**Note:** Version bump only for package @ui5/webcomponents-localization
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
# [1.6.0](https://github.com/SAP/ui5-webcomponents/compare/v1.5.0...v1.6.0) (2022-07-25)
|
15
|
+
|
16
|
+
|
17
|
+
### Features
|
18
|
+
|
19
|
+
* **ui5-calendar:** show months and years from both primary and secon… ([#5412](https://github.com/SAP/ui5-webcomponents/issues/5412)) ([d5dc7ec](https://github.com/SAP/ui5-webcomponents/commit/d5dc7ec))
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
# [1.5.0](https://github.com/SAP/ui5-webcomponents/compare/v1.4.0...v1.5.0) (2022-07-03)
|
26
|
+
|
27
|
+
**Note:** Version bump only for package @ui5/webcomponents-localization
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
6
33
|
# [1.4.0](https://github.com/SAP/ui5-webcomponents/compare/v1.3.1...v1.4.0) (2022-05-25)
|
7
34
|
|
8
35
|
**Note:** Version bump only for package @ui5/webcomponents-localization
|
package/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-

|
2
2
|
|
3
3
|
# UI5 Web Components - Localization
|
4
4
|
|
5
|
-
[](https://travis-ci.org/SAP/ui5-webcomponents)
|
6
5
|
[](https://www.npmjs.com/package/@ui5/webcomponents)
|
7
6
|
|
8
7
|
Provides date/time and CLDR functionality for the purposes of building UI5 Web Components.
|
@@ -39,16 +38,16 @@ In order to be able to use Buddhist, Islamic, Japanese, or Persian calendar with
|
|
39
38
|
(by setting its `primaryCalendarType` property), you must import one or more of the modules above.
|
40
39
|
|
41
40
|
## Resources
|
42
|
-
- [UI5 Web Components - README.md](https://github.com/SAP/ui5-webcomponents/blob/
|
41
|
+
- [UI5 Web Components - README.md](https://github.com/SAP/ui5-webcomponents/blob/main/README.md)
|
43
42
|
- [UI5 Web Components - Home Page](https://sap.github.io/ui5-webcomponents)
|
44
43
|
- [UI5 Web Components - Playground and API Reference](https://sap.github.io/ui5-webcomponents/playground/)
|
45
44
|
|
46
45
|
## Support
|
47
|
-
We welcome all comments, suggestions, questions, and bug reports. Please follow our [Support Guidelines](https://github.com/SAP/ui5-webcomponents/blob/
|
46
|
+
We welcome all comments, suggestions, questions, and bug reports. Please follow our [Support Guidelines](https://github.com/SAP/ui5-webcomponents/blob/main/SUPPORT.md#-content) on how to report an issue, or chat with us in the `#webcomponents` channel of the [OpenUI5 Community Slack](https://join-ui5-slack.herokuapp.com/).
|
48
47
|
|
49
48
|
## Contribute
|
50
|
-
Please check our [Contribution Guidelines](https://github.com/SAP/ui5-webcomponents/blob/
|
49
|
+
Please check our [Contribution Guidelines](https://github.com/SAP/ui5-webcomponents/blob/main/docs/6-contributing/02-conventions-and-guidelines.md).
|
51
50
|
|
52
51
|
## License
|
53
52
|
Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved.
|
54
|
-
This file is licensed under the Apache Software License, Version 2.0 except as noted otherwise in the [LICENSE](https://github.com/SAP/ui5-webcomponents/blob/
|
53
|
+
This file is licensed under the Apache Software License, Version 2.0 except as noted otherwise in the [LICENSE](https://github.com/SAP/ui5-webcomponents/blob/main/LICENSE.txt) file.
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import getLocale from "@ui5/webcomponents-base/dist/locale/getLocale.js";
|
2
|
+
import getCachedLocaleDataInstance from "../getCachedLocaleDataInstance.js";
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Convert month number to month name (text).
|
6
|
+
* If the numbers of the two months are the same you will get the name of the month,
|
7
|
+
* otherwise you will get the two names separated by a dash
|
8
|
+
*
|
9
|
+
* @param firstMonth CalendarDate Month
|
10
|
+
* @param lastMonth CalendarDate Month
|
11
|
+
* @param calendarType calendar type
|
12
|
+
* @returns {String}
|
13
|
+
*/
|
14
|
+
const convertMonthNumbersToMonthNames = (firstMonth, lastMonth, calendarType) => {
|
15
|
+
const localeData = getCachedLocaleDataInstance(getLocale());
|
16
|
+
const pattern = localeData.getIntervalPattern();
|
17
|
+
const secondaryMonthsNames = localeData.getMonthsStandAlone("abbreviated", calendarType);
|
18
|
+
const secondaryMonthsNamesWide = localeData.getMonthsStandAlone("wide", calendarType);
|
19
|
+
|
20
|
+
if (firstMonth === lastMonth) {
|
21
|
+
return {
|
22
|
+
text: localeData.getMonths("abbreviated", calendarType)[firstMonth],
|
23
|
+
textInfo: localeData.getMonths("wide", calendarType)[firstMonth],
|
24
|
+
};
|
25
|
+
}
|
26
|
+
|
27
|
+
return {
|
28
|
+
text: pattern.replace(/\{0\}/, secondaryMonthsNames[firstMonth]).replace(/\{1\}/, secondaryMonthsNames[lastMonth]),
|
29
|
+
textInfo: pattern.replace(/\{0\}/, secondaryMonthsNamesWide[firstMonth]).replace(/\{1\}/, secondaryMonthsNamesWide[lastMonth]),
|
30
|
+
};
|
31
|
+
};
|
32
|
+
|
33
|
+
export default convertMonthNumbersToMonthNames;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import CalendarDate from "./CalendarDate.js";
|
2
|
+
|
3
|
+
const getDaysInMonth = date => {
|
4
|
+
const tempCalendarDate = new CalendarDate(date);
|
5
|
+
tempCalendarDate.setDate(1);
|
6
|
+
tempCalendarDate.setMonth(tempCalendarDate.getMonth() + 1);
|
7
|
+
tempCalendarDate.setDate(0);
|
8
|
+
return tempCalendarDate.getDate();
|
9
|
+
};
|
10
|
+
|
11
|
+
export default getDaysInMonth;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import CalendarDate from "./CalendarDate.js";
|
2
|
+
import getDaysInMonth from "./getDaysInMonth.js";
|
3
|
+
|
4
|
+
const transformDateToSecondaryType = (primaryCalendarType, secondaryCalendarType, timeStamp, hasYearPicker) => {
|
5
|
+
let firstDate = CalendarDate.fromLocalJSDate(new Date(timeStamp * 1000), primaryCalendarType);
|
6
|
+
let lastDate = CalendarDate.fromLocalJSDate(new Date(timeStamp * 1000), primaryCalendarType);
|
7
|
+
firstDate.setDate(1);
|
8
|
+
|
9
|
+
if (hasYearPicker) {
|
10
|
+
firstDate.setMonth(0);
|
11
|
+
lastDate.setMonth(11);
|
12
|
+
}
|
13
|
+
|
14
|
+
lastDate.setDate(getDaysInMonth(lastDate));
|
15
|
+
firstDate = new CalendarDate(firstDate, secondaryCalendarType);
|
16
|
+
lastDate = new CalendarDate(lastDate, secondaryCalendarType);
|
17
|
+
return { firstDate, lastDate };
|
18
|
+
};
|
19
|
+
|
20
|
+
export default transformDateToSecondaryType;
|
@@ -7,7 +7,7 @@ const instances = new Map();
|
|
7
7
|
/**
|
8
8
|
* Fetches and returns а LocaleData object for the required locale
|
9
9
|
* For more information on this object's API, please see:
|
10
|
-
* https://
|
10
|
+
* https://sdk.openui5.org/api/sap.ui.core.LocaleData
|
11
11
|
*
|
12
12
|
* @param lang - if left empty, will use the configured/current locale
|
13
13
|
* @returns {LocaleData}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ui5/webcomponents-localization",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.7.0",
|
4
4
|
"description": "Localization for UI5 Web Components",
|
5
5
|
"author": "SAP SE (https://www.sap.com)",
|
6
6
|
"license": "Apache-2.0",
|
@@ -28,12 +28,12 @@
|
|
28
28
|
},
|
29
29
|
"devDependencies": {
|
30
30
|
"@openui5/sap.ui.core": "1.101.0",
|
31
|
-
"@ui5/webcomponents-tools": "1.
|
32
|
-
"chromedriver": "
|
31
|
+
"@ui5/webcomponents-tools": "1.7.0",
|
32
|
+
"chromedriver": "104.0.0",
|
33
33
|
"mkdirp": "^1.0.4",
|
34
34
|
"resolve": "^1.20.0"
|
35
35
|
},
|
36
36
|
"dependencies": {
|
37
|
-
"@ui5/webcomponents-base": "1.
|
37
|
+
"@ui5/webcomponents-base": "1.7.0"
|
38
38
|
}
|
39
39
|
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import getLocale from "@ui5/webcomponents-base/dist/locale/getLocale.js";
|
2
|
+
import getCachedLocaleDataInstance from "../getCachedLocaleDataInstance.js";
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Convert month number to month name (text).
|
6
|
+
* If the numbers of the two months are the same you will get the name of the month,
|
7
|
+
* otherwise you will get the two names separated by a dash
|
8
|
+
*
|
9
|
+
* @param firstMonth CalendarDate Month
|
10
|
+
* @param lastMonth CalendarDate Month
|
11
|
+
* @param calendarType calendar type
|
12
|
+
* @returns {String}
|
13
|
+
*/
|
14
|
+
const convertMonthNumbersToMonthNames = (firstMonth, lastMonth, calendarType) => {
|
15
|
+
const localeData = getCachedLocaleDataInstance(getLocale());
|
16
|
+
const pattern = localeData.getIntervalPattern();
|
17
|
+
const secondaryMonthsNames = localeData.getMonthsStandAlone("abbreviated", calendarType);
|
18
|
+
const secondaryMonthsNamesWide = localeData.getMonthsStandAlone("wide", calendarType);
|
19
|
+
|
20
|
+
if (firstMonth === lastMonth) {
|
21
|
+
return {
|
22
|
+
text: localeData.getMonths("abbreviated", calendarType)[firstMonth],
|
23
|
+
textInfo: localeData.getMonths("wide", calendarType)[firstMonth],
|
24
|
+
};
|
25
|
+
}
|
26
|
+
|
27
|
+
return {
|
28
|
+
text: pattern.replace(/\{0\}/, secondaryMonthsNames[firstMonth]).replace(/\{1\}/, secondaryMonthsNames[lastMonth]),
|
29
|
+
textInfo: pattern.replace(/\{0\}/, secondaryMonthsNamesWide[firstMonth]).replace(/\{1\}/, secondaryMonthsNamesWide[lastMonth]),
|
30
|
+
};
|
31
|
+
};
|
32
|
+
|
33
|
+
export default convertMonthNumbersToMonthNames;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import CalendarDate from "./CalendarDate.js";
|
2
|
+
|
3
|
+
const getDaysInMonth = date => {
|
4
|
+
const tempCalendarDate = new CalendarDate(date);
|
5
|
+
tempCalendarDate.setDate(1);
|
6
|
+
tempCalendarDate.setMonth(tempCalendarDate.getMonth() + 1);
|
7
|
+
tempCalendarDate.setDate(0);
|
8
|
+
return tempCalendarDate.getDate();
|
9
|
+
};
|
10
|
+
|
11
|
+
export default getDaysInMonth;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import CalendarDate from "./CalendarDate.js";
|
2
|
+
import getDaysInMonth from "./getDaysInMonth.js";
|
3
|
+
|
4
|
+
const transformDateToSecondaryType = (primaryCalendarType, secondaryCalendarType, timeStamp, hasYearPicker) => {
|
5
|
+
let firstDate = CalendarDate.fromLocalJSDate(new Date(timeStamp * 1000), primaryCalendarType);
|
6
|
+
let lastDate = CalendarDate.fromLocalJSDate(new Date(timeStamp * 1000), primaryCalendarType);
|
7
|
+
firstDate.setDate(1);
|
8
|
+
|
9
|
+
if (hasYearPicker) {
|
10
|
+
firstDate.setMonth(0);
|
11
|
+
lastDate.setMonth(11);
|
12
|
+
}
|
13
|
+
|
14
|
+
lastDate.setDate(getDaysInMonth(lastDate));
|
15
|
+
firstDate = new CalendarDate(firstDate, secondaryCalendarType);
|
16
|
+
lastDate = new CalendarDate(lastDate, secondaryCalendarType);
|
17
|
+
return { firstDate, lastDate };
|
18
|
+
};
|
19
|
+
|
20
|
+
export default transformDateToSecondaryType;
|
@@ -7,7 +7,7 @@ const instances = new Map();
|
|
7
7
|
/**
|
8
8
|
* Fetches and returns а LocaleData object for the required locale
|
9
9
|
* For more information on this object's API, please see:
|
10
|
-
* https://
|
10
|
+
* https://sdk.openui5.org/api/sap.ui.core.LocaleData
|
11
11
|
*
|
12
12
|
* @param lang - if left empty, will use the configured/current locale
|
13
13
|
* @returns {LocaleData}
|