Skip to content

Commit 65e2c81

Browse files
committed
Fix localization issues
1 parent 289b95c commit 65e2c81

File tree

2 files changed

+57
-23
lines changed

2 files changed

+57
-23
lines changed

packages/react-sdk-components/src/components/field/Dropdown/Dropdown.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ export default function Dropdown(props) {
4242
useEffect(() => {
4343
const list = Utils.getOptionList(props, getPConnect().getDataObject());
4444
const optionsList = [...list];
45-
optionsList.unshift({ key: placeholder, value: placeholder });
45+
optionsList.unshift({ key: placeholder, value: thePConn.getLocalizedValue(placeholder) });
4646
setOptions(optionsList);
4747
}, [datasource]);
4848

4949
const metaData = Array.isArray(fieldMetadata)
50-
? fieldMetadata.filter((field) => field?.classID === className)[0]
50+
? fieldMetadata.filter(field => field?.classID === className)[0]
5151
: fieldMetadata;
5252

5353
let displayName = metaData?.datasource?.propertyForDisplayText;
@@ -60,11 +60,30 @@ export default function Dropdown(props) {
6060
let readOnlyProp = {};
6161

6262
if (displayMode === 'LABELS_LEFT') {
63-
return <FieldValueList name={hideLabel ? '' : label} value={value} />;
63+
return (
64+
<FieldValueList
65+
name={hideLabel ? '' : label}
66+
value={thePConn.getLocalizedValue(
67+
value,
68+
localePath,
69+
thePConn.getLocaleRuleNameFromKeys(localeClass, localeContext, localeName)
70+
)}
71+
/>
72+
);
6473
}
6574

6675
if (displayMode === 'STACKED_LARGE_VAL') {
67-
return <FieldValueList name={hideLabel ? '' : label} value={value} variant='stacked' />;
76+
return (
77+
<FieldValueList
78+
name={hideLabel ? '' : label}
79+
value={thePConn.getLocalizedValue(
80+
value,
81+
localePath,
82+
thePConn.getLocaleRuleNameFromKeys(localeClass, localeContext, localeName)
83+
)}
84+
variant='stacked'
85+
/>
86+
);
6887
}
6988

7089
if (readOnly) {

packages/react-sdk-components/src/components/field/RadioButtons/RadioButtons.tsx

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,14 @@ export default function RadioButtons(props) {
4141
configProperty = configProperty.startsWith('.') ? configProperty.substring(1) : configProperty;
4242

4343
const metaData = Array.isArray(fieldMetadata)
44-
? fieldMetadata.filter((field) => field?.classID === className)[0]
45-
: fieldMetadata;
46-
let displayName = metaData?.datasource?.propertyForDisplayText;
47-
displayName = displayName?.slice(displayName.lastIndexOf('.') + 1);
48-
const localeContext = metaData?.datasource?.tableType === 'DataPage' ? 'datapage' : 'associated';
49-
const localeClass = localeContext === 'datapage' ? '@baseclass' : className;
50-
const localeName = localeContext === 'datapage' ? metaData?.datasource?.name : configProperty;
51-
const localePath = localeContext === 'datapage' ? displayName : localeName;
52-
53-
44+
? fieldMetadata.filter(field => field?.classID === className)[0]
45+
: fieldMetadata;
46+
let displayName = metaData?.datasource?.propertyForDisplayText;
47+
displayName = displayName?.slice(displayName.lastIndexOf('.') + 1);
48+
const localeContext = metaData?.datasource?.tableType === 'DataPage' ? 'datapage' : 'associated';
49+
const localeClass = localeContext === 'datapage' ? '@baseclass' : className;
50+
const localeName = localeContext === 'datapage' ? metaData?.datasource?.name : configProperty;
51+
const localePath = localeContext === 'datapage' ? displayName : localeName;
5452

5553
// theOptions will be an array of JSON objects that are literally key/value pairs.
5654
// Ex: [ {key: "Basic", value: "Basic"} ]
@@ -62,11 +60,30 @@ const localePath = localeContext === 'datapage' ? displayName : localeName;
6260
}, [value]);
6361

6462
if (displayMode === 'LABELS_LEFT') {
65-
return <FieldValueList name={hideLabel ? '' : label} value={value} />;
63+
return (
64+
<FieldValueList
65+
name={hideLabel ? '' : label}
66+
value={thePConn.getLocalizedValue(
67+
value,
68+
localePath,
69+
thePConn.getLocaleRuleNameFromKeys(localeClass, localeContext, localeName)
70+
)}
71+
/>
72+
);
6673
}
6774

6875
if (displayMode === 'STACKED_LARGE_VAL') {
69-
return <FieldValueList name={hideLabel ? '' : label} value={value} variant='stacked' />;
76+
return (
77+
<FieldValueList
78+
name={hideLabel ? '' : label}
79+
value={thePConn.getLocalizedValue(
80+
value,
81+
localePath,
82+
thePConn.getLocaleRuleNameFromKeys(localeClass, localeContext, localeName)
83+
)}
84+
variant='stacked'
85+
/>
86+
);
7087
}
7188

7289
const handleChange = event => {
@@ -91,13 +108,11 @@ const localePath = localeContext === 'datapage' ? displayName : localeName;
91108
<FormControlLabel
92109
value={theOption.key}
93110
key={theOption.key}
94-
label={
95-
thePConn.getLocalizedValue(
96-
theOption.value,
97-
localePath,
98-
thePConn.getLocaleRuleNameFromKeys(localeClass, localeContext, localeName)
99-
)
100-
}
111+
label={thePConn.getLocalizedValue(
112+
theOption.value,
113+
localePath,
114+
thePConn.getLocaleRuleNameFromKeys(localeClass, localeContext, localeName)
115+
)}
101116
control={<Radio key={theOption.key} color='primary' disabled={readOnly} />}
102117
/>
103118
);

0 commit comments

Comments
 (0)