Skip to content

Commit 334ee55

Browse files
Merge pull request #157 from pegasystems/bug/tor/-BUG-813490
Fix placeholder not being localized in Date component
2 parents 49905b8 + 45ca16f commit 334ee55

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed
Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { getLocale } from './formatters/common';
22

3-
43
export const dateFormatInfoDefault = {
5-
dateFormatString: "MM/DD/YYYY",
6-
dateFormatStringLong: "MMM DD, YYYY",
7-
dateFormatStringLC: "mm/dd/yyyy",
8-
dateFormatMask: "__/__/____"
9-
}
4+
dateFormatString: 'MM/DD/YYYY',
5+
dateFormatStringLong: 'MMM DD, YYYY',
6+
dateFormatStringLC: 'mm/dd/yyyy',
7+
dateFormatMask: '__/__/____'
8+
};
109

1110
export const getDateFormatInfo = () => {
11+
const localizedVal = PCore.getLocaleUtils().getLocaleValue;
12+
const localeCategory = 'CosmosFields';
1213
const theDateFormatInfo = dateFormatInfoDefault;
13-
const theLocale = getLocale(); // PCore.getEnvironmentInfo().getUseLocale() || "US-en";
14+
const theLocale = getLocale();
1415

1516
// NOTE: this date was chosen since it has a day larger than 12. If you change it,
1617
// you'll need to change the indexOf values below!
@@ -25,29 +26,38 @@ export const getDateFormatInfo = () => {
2526
const locDD = theTestDateLocaleString.indexOf('30');
2627
const locYYYY = theTestDateLocaleString.indexOf('2023');
2728

29+
// If localized placeholder exists for one of day/month/year then show it otherwise fall back to ddmmyyyy
30+
const localizedPlaceholderExists =
31+
localizedVal('month_placeholder', localeCategory) !== 'month_placeholder' ||
32+
localizedVal('day_placeholder', localeCategory) !== 'day_placeholder' ||
33+
localizedVal('year_placeholder', localeCategory) !== 'year_placeholder';
34+
2835
const arrPieces = [
2936
{
3037
loc: locMM,
3138
format: 'MM',
3239
longFormat: 'MMM',
33-
placeholder: 'mm',
34-
mask: '__'
40+
placeholder: localizedPlaceholderExists ? localizedVal('month_placeholder', localeCategory) : 'mm',
41+
mask: '__',
42+
separator: theTestDateLocaleString[locMM+2]
3543
},
3644
{
3745
loc: locDD,
3846
format: 'DD',
3947
longFormat: 'DD',
40-
placeholder: 'dd',
41-
mask: '__'
48+
placeholder: localizedPlaceholderExists ? localizedVal('day_placeholder', localeCategory) : 'dd',
49+
mask: '__',
50+
separator: theTestDateLocaleString[locDD+2]
4251
},
4352
{
4453
loc: locYYYY,
4554
format: 'YYYY',
4655
longFormat: 'YYYY',
47-
placeholder: 'yyyy',
48-
mask: '____'
56+
placeholder: localizedPlaceholderExists ? localizedVal('year_placeholder', localeCategory) : 'yyyy',
57+
mask: '____',
58+
separator: theTestDateLocaleString[locYYYY+4]
4959
}
50-
];
60+
];
5161

5262
// Sort the associative array by order of appearance (loc) of each piece
5363
arrPieces.sort((a, b) => {
@@ -57,10 +67,10 @@ export const getDateFormatInfo = () => {
5767
});
5868

5969
// Construct the structure to return...
60-
theDateFormatInfo.dateFormatString = `${arrPieces[0].format}/${arrPieces[1].format}/${arrPieces[2].format}`;
70+
theDateFormatInfo.dateFormatString = `${arrPieces[0].format}${arrPieces[0].separator}${arrPieces[1].format}${arrPieces[1].separator}${arrPieces[2].format}`;
6171
theDateFormatInfo.dateFormatStringLong = `${arrPieces[0].longFormat} ${arrPieces[1].longFormat}, ${arrPieces[2].longFormat}`;
62-
theDateFormatInfo.dateFormatStringLC = `${arrPieces[0].placeholder}/${arrPieces[1].placeholder}/${arrPieces[2].placeholder}`;
63-
theDateFormatInfo.dateFormatMask = `${arrPieces[0].mask}/${arrPieces[1].mask}/${arrPieces[2].mask}`;
72+
theDateFormatInfo.dateFormatStringLC = `${arrPieces[0].placeholder}${arrPieces[0].separator}${arrPieces[1].placeholder}${arrPieces[1].separator}${arrPieces[2].placeholder}`;
73+
theDateFormatInfo.dateFormatMask = `${arrPieces[0].mask}${arrPieces[0].separator}${arrPieces[1].mask}${arrPieces[1].separator}${arrPieces[2].mask}`;
6474

6575
return theDateFormatInfo;
66-
}
76+
};

packages/react-sdk-components/src/components/helpers/formatters/common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
export function getLocale(locale = "en-US") {
1+
export function getLocale(locale='') {
22
// use locale if specified
33
if (locale) return locale;
44
// otherwise, use operator locale if it's defined
5-
if (PCore.getEnvironmentInfo().getUseLocale()) return PCore.getEnvironmentInfo().getUseLocale();
5+
if (PCore.getEnvironmentInfo().getLocale()) return PCore.getEnvironmentInfo().getLocale();
66
// fallback
77
return Intl.DateTimeFormat().resolvedOptions().locale;
88
}

0 commit comments

Comments
 (0)