From 3fe85c519d77c951995ac1f421d70086de4a7533 Mon Sep 17 00:00:00 2001 From: elforjani3 Date: Sat, 12 Jun 2021 18:13:49 +0200 Subject: [PATCH 1/4] feat: yup locale. --- client/src/components/AppIntlLoader.js | 13 ++++ .../src/containers/Setup/SetupCongratsPage.js | 2 +- client/src/lang/ar-ly/locale.js | 64 +++++++++++++++++++ client/src/lang/en/locale.js | 1 + 4 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 client/src/lang/ar-ly/locale.js diff --git a/client/src/components/AppIntlLoader.js b/client/src/components/AppIntlLoader.js index 03f4251c4..fdd533325 100644 --- a/client/src/components/AppIntlLoader.js +++ b/client/src/components/AppIntlLoader.js @@ -1,5 +1,6 @@ import React from 'react'; import moment from 'moment'; +import { setLocale } from 'yup'; import intl from 'react-intl-universal'; import { find } from 'lodash'; import rtlDetect from 'rtl-detect'; @@ -32,6 +33,10 @@ function loadLocales(currentLocale) { return import(`../lang/${currentLocale}/index.json`); } +function loadYupLocales(currentLocale) { + return import(`../lang/${currentLocale}/locale`); +} + /** * Modifies the html document direction to RTl if it was rtl-language. */ @@ -74,6 +79,14 @@ export default function AppIntlLoader({ children }) { }); }, [currentLocale, setIsLoading]); + React.useEffect(() => { + loadYupLocales(currentLocale) + .then(({ locale }) => { + setLocale(locale); + }) + .then(() => {}); + }, [currentLocale]); + return ( {children} diff --git a/client/src/containers/Setup/SetupCongratsPage.js b/client/src/containers/Setup/SetupCongratsPage.js index 0eb7104f4..de78fe0ce 100644 --- a/client/src/containers/Setup/SetupCongratsPage.js +++ b/client/src/containers/Setup/SetupCongratsPage.js @@ -2,7 +2,7 @@ import React, { useCallback } from 'react'; import { Button, Intent } from '@blueprintjs/core'; import { useHistory } from 'react-router-dom'; import WorkflowIcon from './WorkflowIcon'; -import { FormattedMessage as T } from 'react-intl'; +import { FormattedMessage as T } from 'components'; import withOrganizationActions from 'containers/Organization/withOrganizationActions'; import 'style/pages/Setup/Congrats.scss'; diff --git a/client/src/lang/ar-ly/locale.js b/client/src/lang/ar-ly/locale.js new file mode 100644 index 000000000..bd7d5db24 --- /dev/null +++ b/client/src/lang/ar-ly/locale.js @@ -0,0 +1,64 @@ +// Based on https://github.com/jquense/yup/blob/2973d0a/src/locale.js + +import printValue from '../printValue'; + +export const locale = { + mixed: { + default: '${path} غير صالح.', + required: '${path} هو حقل مطلوب', + oneOf: '${path} يجب أن تكون واحدة من القيم التالية: ${values}', + notOneOf: '${path} لا يجب أن تكون واحدة من القيم التالية: ${values}', + notType: ({ path, type, value, originalValue }) => { + const isCast = originalValue != null && originalValue !== value; + let msg = + `${path} يجب أن يكون \`${type}\` نوع, ` + + `ولكن القيمة النهائية كانت في: \`${printValue(value, true)}\`` + + (isCast + ? ` (المدلى بها من قيمة \`${printValue(originalValue, true)}\`).` + : '.'); + + if (value === null) { + msg += + `\n إذا كان المقصود "لاغية" كقيمة فارغة مما لا شك فيه للاحتفال مخطط كما` + + ' `.nullable()`'; + } + + return msg; + }, + }, + + string: { + length: '${path} يجب أن يكون بالضبط ${length} حرفا', + min: '${path} يجب أن تكون على الأقل ${min} حرفا', + max: '${path} يجب أن تكون على الأكثر ${max} حرفا', + matches: '${path} يجب أن يطابق ما يلي: "${regex}"', + email: '${path} يجب أن يكون عنوان بريد إلكتروني صالح', + url: '${path} يجب أن يكون عنوان URL صالحا', + trim: '${path} يجب أن تكون سلسلة قلص', + lowercase: '${path} يجب أن تكون سلسلة صغيرة', + uppercase: '${path} يجب أن تكون سلسلة الحالة العلوي', + }, + + number: { + min: '${path} يجب أن تكون أكبر من أو يساوي ${min}', + max: '${path} يجب أن يكون أقل من أو يساوي ${max}', + lessThan: '${path} يجب أن يكون أقل من ${less}', + moreThan: '${path} يجب أن تكون أكبر من ${more}', + positive: '${path} يجب أن يكون رقما موجبا', + negative: '${path} يجب أن يكون رقما سالبا', + integer: '${path} يجب أن يكون رقما', + }, + date: { + min: '${path} يجب أن يكون حقل في وقت لاحق من ${min}', + max: '${path} يجب أن يكون حقل في وقت سابق من ${max}', + }, + boolean: {}, + + object: { + noUnknown: '${path} حقل لا يمكن أن يكون مفاتيح غير محددة في شكل وجوه', + }, + array: { + min: 'يجب أن يكون ${path} حقل على الأقل ${min} من العناصر', + max: '${path} يجب أن يكون الحقل أقل من أو يساوي إلى ${max} من العناصر', + }, +}; diff --git a/client/src/lang/en/locale.js b/client/src/lang/en/locale.js index 395a78ccc..8ebf81b3e 100644 --- a/client/src/lang/en/locale.js +++ b/client/src/lang/en/locale.js @@ -1,4 +1,5 @@ import printValue from '../printValue'; + export const locale = { mixed: { default: '${path} is invalid', From 7a384c54be8880547f4d282227f2c7b783d0fbdc Mon Sep 17 00:00:00 2001 From: elforjani3 Date: Sat, 12 Jun 2021 19:36:14 +0200 Subject: [PATCH 2/4] feat: message lang. --- client/src/components/AccountsMultiSelect.js | 2 +- client/src/components/ContactSelecetList.js | 2 +- client/src/components/ContactsMultiSelect.js | 2 +- client/src/components/ItemsListField.js | 2 +- client/src/components/PaymentReceiveListField.js | 2 +- .../Dialogs/ItemCategoryDialog/ItemCategoryForm.js | 2 +- .../InventoryValuation/InventoryValuationTable.js | 8 ++++---- .../PurchasesByItems/PurchasesByItemsTable.js | 6 +++--- .../FinancialStatements/SalesByItems/SalesByItemsTable.js | 6 +++--- client/src/containers/GeneralSearch/Search.js | 3 ++- client/src/containers/Setup/SetupOrganizationForm.js | 6 +++--- client/src/lang/en/index.json | 5 ++++- 12 files changed, 25 insertions(+), 21 deletions(-) diff --git a/client/src/components/AccountsMultiSelect.js b/client/src/components/AccountsMultiSelect.js index 071211e5f..726bd7f18 100644 --- a/client/src/components/AccountsMultiSelect.js +++ b/client/src/components/AccountsMultiSelect.js @@ -56,7 +56,7 @@ export default function AccountsMultiSelect({ accounts, onAccountSelected }) { return ( } + noResults={} />} itemRenderer={accountItem} popoverProps={{ minimal: true }} filterable={true} diff --git a/client/src/components/ContactSelecetList.js b/client/src/components/ContactSelecetList.js index 8dfeb32f6..401de14bf 100644 --- a/client/src/components/ContactSelecetList.js +++ b/client/src/components/ContactSelecetList.js @@ -79,7 +79,7 @@ export default function ContactSelecetList({ return (