Skip to content

Commit 3789a6e

Browse files
authored
fix: No records found message translation (#461)
* fix: No records found message translation * refactor: replace localized no records message function with generic fields localization
1 parent eb9f312 commit 3789a6e

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed
Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
1-
/* eslint-disable import/prefer-default-export */
21
export function isEmptyObject(obj: Object): boolean {
32
return Object.keys(obj).length === 0;
43
}
4+
5+
/**
6+
* Get a localized value from the Generic Fields
7+
* @param path - The path within Generic Fields (e.g., 'CosmosFields.fields.lists')
8+
* @param key - The key of the string to localize
9+
* @returns The localized string or the key itself if no translation is found
10+
*/
11+
export function getGenericFieldsLocalizedValue(path: string, key: string): string {
12+
const GENERIC_BUNDLE_KEY = PCore.getLocaleUtils().GENERIC_BUNDLE_KEY;
13+
const localeStore = PCore.getLocaleUtils().localeStore[GENERIC_BUNDLE_KEY];
14+
15+
if (!localeStore) return key;
16+
17+
// Split the path and traverse the object
18+
const pathParts = path.split('.');
19+
let currentObj = localeStore;
20+
21+
for (const part of pathParts) {
22+
if (!currentObj[part]) return key;
23+
currentObj = currentObj[part];
24+
}
25+
26+
return currentObj[key] || key;
27+
}

packages/react-sdk-components/src/components/template/ListView/ListView.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { filterData } from '../../helpers/simpleTableHelpers';
4343
import './ListView.css';
4444
import { getDateFormatInfo } from '../../helpers/date-format-utils';
4545
import { getCurrencyOptions } from '../../field/Currency/currency-utils';
46+
import { getGenericFieldsLocalizedValue } from '../../helpers/common-utils';
4647
import { format } from '../../helpers/formatters';
4748

4849
import useInit from './hooks';
@@ -1129,7 +1130,9 @@ export default function ListView(props: ListViewProps) {
11291130
})}
11301131
</TableBody>
11311132
</Table>
1132-
{arRows && arRows.length === 0 && <div className='no-records'>No records found.</div>}
1133+
{arRows && arRows.length === 0 && (
1134+
<div className='no-records'>{getGenericFieldsLocalizedValue('CosmosFields.fields.lists', 'No records found.')}</div>
1135+
)}
11331136
</TableContainer>
11341137
)}
11351138
</>

packages/react-sdk-components/src/components/template/SimpleTable/SimpleTableManual/SimpleTableManual.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import createPConnectComponent from '../../../../bridge/react_pconnect';
2727
import { Utils } from '../../../helpers/utils';
2828
import { getReferenceList } from '../../../helpers/field-group-utils';
2929
import { getDataPage } from '../../../helpers/data_page';
30+
import { getGenericFieldsLocalizedValue } from '../../../helpers/common-utils';
3031
import { buildFieldsForTable, filterData, getContext } from '../../../helpers/simpleTableHelpers';
3132
import { PConnProps } from '../../../../types/PConnProps';
3233
import { format } from '../../../helpers/formatters';
@@ -711,7 +712,7 @@ export default function SimpleTableManual(props: PropsWithChildren<SimpleTableMa
711712
</Table>
712713
{((readOnlyMode && (!rowData || rowData?.length === 0)) || (editableMode && (!referenceList || referenceList?.length === 0))) && (
713714
<div className='no-records' id='no-records'>
714-
No records found.
715+
{getGenericFieldsLocalizedValue('CosmosFields.fields.lists', 'No records found.')}
715716
</div>
716717
)}
717718
</TableContainer>

0 commit comments

Comments
 (0)