Skip to content

Commit

Permalink
add translations
Browse files Browse the repository at this point in the history
  • Loading branch information
jabahum committed Apr 25, 2024
1 parent 5278f66 commit 7a87d2d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"coverage": "yarn test --coverage",
"analyze": "webpack --mode=production --env.analyze=true",
"prepare": "husky install",
"extract-translations": "i18next 'src/**/*.component.tsx' --config './tools/i18next-parser.config.js'"
"extract-translations": "i18next 'src/**/*.{ts,tsx}' --config './tools/i18next-parser.config.js'"
},
"browserslist": [
"extends browserslist-config-openmrs"
Expand Down
30 changes: 22 additions & 8 deletions src/validators/form-validator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { moduleName } from '../globals';
import { FormFieldValidator, FormField } from '../types';
import { isTrue } from '../utils/boolean-utils';
import { translateFrom } from '@openmrs/esm-framework';

export const fieldRequiredErrCode = 'field.required';
export const fieldOutOfBoundErrCode = 'field.outOfBound';
Expand Down Expand Up @@ -34,19 +36,27 @@ export function numberInputRangeValidator(min: number, max: number, inputValue:
if (!Number.isNaN(min) && inputValue < min) {
return [
{
resultType: 'error',
// t('error', 'error')
resultType: translateFrom(moduleName, 'error', 'error'),
errCode: fieldOutOfBoundErrCode,
message: `Value must be greater than ${min}`,
// t('minValue', 'Value must be lower than {{min}}', {min})
message: translateFrom(moduleName, 'minValue', 'Value must be lower than {{min}}', {
min,
}),
},
];
}

if (!Number.isNaN(max) && inputValue > max) {
return [
{
resultType: 'error',
// t('error', 'error')
resultType: translateFrom(moduleName, 'error', 'error'),
errCode: fieldOutOfBoundErrCode,
message: `Value must be lower than ${max}`,
// t('maxValue', 'Value must be greater than ${max}', {max})
message: translateFrom(moduleName, 'maxValue', 'Value must be greater than ${max}', {
max,
}),
},
];
}
Expand All @@ -55,9 +65,13 @@ export function numberInputRangeValidator(min: number, max: number, inputValue:
if (!isEmpty(inputValue) && inputValue.toString().includes('.')) {
return [
{
resultType: 'error',
// t('error', 'error')
resultType: translateFrom(moduleName, 'error', 'error'),
errCode: fieldOutOfBoundErrCode,
message: `Decimal values are not allowed`,
// t('decimalValue', 'Decimal values are not allowed ${inputValue}', {inputValue})
message: translateFrom(moduleName, 'decimalValue', 'Decimal values are not allowed', {
inputValue,
}),
},
];
}
Expand Down Expand Up @@ -105,9 +119,9 @@ export function textInputLengthValidator(minLength: string, maxLength: string, i
export function addError(errorCode: string, message: string): [{}] {
return [
{
resultType: 'error',
resultType: translateFrom(moduleName, 'error', 'error'),
errCode: errorCode,
message: message,
message: translateFrom(moduleName, 'message', message),
},
];
}
7 changes: 7 additions & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@
"collapseAll": "Collapse all",
"createdRecord": "Record created",
"createdRecordDescription": "A new encounter was created",
"decimalValue": "Decimal values are not allowed ${inputValue}",
"error": "error",
"errorDescription": "",
"errorDescriptionTitle": "Error on saving form",
"errorRenderingField": "Error rendering field",
"expandAll": "Expand all",
"fileUploadDescription": "",
"fileUploadDescriptionAny": "Upload any file type",
"invalidWorkspaceName": "Invalid workspace name.",
"invalidWorkspaceNameSubtitle": "Please provide a valid workspace name.",
"launchWorkspace": "",
"loading": "Loading",
"maxValue": "Value must be greater than ${max}",
"minValue": "Value must be lower than {{min}}",
"notification": "Notification",
"preview": "Preview",
"previousValue": "Previous value:",
Expand Down

0 comments on commit 7a87d2d

Please sign in to comment.