From 7a87d2d564e3a319042756fd3ca435eab085af1f Mon Sep 17 00:00:00 2001 From: jabahum Date: Thu, 25 Apr 2024 17:55:03 +0300 Subject: [PATCH] add translations --- package.json | 2 +- src/validators/form-validator.ts | 30 ++++++++++++++++++++++-------- translations/en.json | 7 +++++++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index ce1d07f91..44a6f7349 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/validators/form-validator.ts b/src/validators/form-validator.ts index e02e6cdce..235d030f1 100644 --- a/src/validators/form-validator.ts +++ b/src/validators/form-validator.ts @@ -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'; @@ -34,9 +36,13 @@ 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, + }), }, ]; } @@ -44,9 +50,13 @@ export function numberInputRangeValidator(min: number, max: number, inputValue: 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, + }), }, ]; } @@ -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, + }), }, ]; } @@ -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), }, ]; } diff --git a/translations/en.json b/translations/en.json index c9034942e..4eb6f2ffa 100644 --- a/translations/en.json +++ b/translations/en.json @@ -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:",