diff --git a/.env b/.env index 8b3b02b3d97..6b3e9013d81 100644 --- a/.env +++ b/.env @@ -12,3 +12,4 @@ REACT_CARE_API_URL=https://careapi.ohc.network # Dev envs ESLINT_NO_DEV_ERRORS=true CARE_CDN_URL="https://egov-s3-facility-10bedicu.s3.amazonaws.com https://egov-s3-patient-data-10bedicu.s3.amazonaws.com http://localhost:4566" +REACT_ALLOWED_LOCALES="en,hi,ta,ml,mr,kn" \ No newline at end of file diff --git a/.example.env b/.example.env index 127db15e710..848dd4bee93 100644 --- a/.example.env +++ b/.example.env @@ -76,3 +76,6 @@ REACT_JWT_TOKEN_REFRESH_INTERVAL= # Minimum encounter date (default: 2020-01-01) REACT_MIN_ENCOUNTER_DATE= + +# Available languages to switch between (2 Digit language code seperated by comas. See src->Locale->config.ts for available codes) +REACT_ALLOWED_LOCALES="en,hi,ta,ml,mr,kn" \ No newline at end of file diff --git a/care.config.ts b/care.config.ts index e3effeca1b0..57b5d79b229 100644 --- a/care.config.ts +++ b/care.config.ts @@ -38,6 +38,9 @@ const careConfig = { customLogo: logo(env.REACT_CUSTOM_LOGO), customLogoAlt: logo(env.REACT_CUSTOM_LOGO_ALT), customDescription: env.REACT_CUSTOM_DESCRIPTION, + availableLocales: (env.REACT_ALLOWED_LOCALES || "") + .split(",") + .map((l) => l.trim()), gmapsApiKey: env.REACT_GMAPS_API_KEY || "AIzaSyDsBAc3y7deI5ZO3NtK5GuzKwtUzQNJNUk", diff --git a/src/Components/Common/LanguageSelector.tsx b/src/Components/Common/LanguageSelector.tsx index 34e261bff93..38fc8024a01 100644 --- a/src/Components/Common/LanguageSelector.tsx +++ b/src/Components/Common/LanguageSelector.tsx @@ -1,8 +1,9 @@ import { useEffect } from "react"; import { useTranslation } from "react-i18next"; -import { LANGUAGE_NAMES } from "../../Locale/config"; import { classNames } from "../../Utils/utils"; import CareIcon from "../../CAREUI/icons/CareIcon"; +import careConfig from "@careConfig"; +import { LANGUAGES } from "../../i18n"; export const LanguageSelector = (props: any) => { const { i18n } = useTranslation(); @@ -19,6 +20,10 @@ export const LanguageSelector = (props: any) => { } }; + const availableLocales = Object.keys(LANGUAGES).filter((l) => + careConfig.availableLocales?.includes(l), + ); + return (
diff --git a/src/Components/Common/LanguageSelectorLogin.tsx b/src/Components/Common/LanguageSelectorLogin.tsx index 1fc4cf4ac77..905b97a734c 100644 --- a/src/Components/Common/LanguageSelectorLogin.tsx +++ b/src/Components/Common/LanguageSelectorLogin.tsx @@ -1,7 +1,8 @@ import { useEffect } from "react"; import { useTranslation } from "react-i18next"; -import { LANGUAGE_NAMES } from "../../Locale/config"; import { classNames } from "../../Utils/utils"; +import careConfig from "@careConfig"; +import { LANGUAGES } from "../../i18n"; export const LanguageSelectorLogin = () => { const { i18n, t } = useTranslation(); @@ -17,12 +18,16 @@ export const LanguageSelectorLogin = () => { } }; + const availableLocales = Object.keys(LANGUAGES).filter((l) => + careConfig.availableLocales?.includes(l), + ); + return (
{t("available_in")}
-
- {Object.keys(LANGUAGE_NAMES).map((e: string) => ( +
+ {availableLocales.map((e: string) => ( ))}
diff --git a/src/Locale/config.ts b/src/Locale/config.ts deleted file mode 100644 index cc41f589581..00000000000 --- a/src/Locale/config.ts +++ /dev/null @@ -1,7 +0,0 @@ -export const LANGUAGE_NAMES: { [key: string]: any } = { - en: "English", - ta: "தமிழ்", - ml: "മലയാളം", - mr: "मराठी", - kn: "ಕನ್ನಡ", -}; diff --git a/src/Locale/en/index.js b/src/Locale/en/index.ts similarity index 100% rename from src/Locale/en/index.js rename to src/Locale/en/index.ts diff --git a/src/Locale/hi/HCX.json b/src/Locale/hi/HCX.json new file mode 100644 index 00000000000..9e26dfeeb6e --- /dev/null +++ b/src/Locale/hi/HCX.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/src/Locale/hi/Patient.json b/src/Locale/hi/Patient.json new file mode 100644 index 00000000000..9e26dfeeb6e --- /dev/null +++ b/src/Locale/hi/Patient.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/src/Locale/hi/index.ts b/src/Locale/hi/index.ts new file mode 100644 index 00000000000..808520605ed --- /dev/null +++ b/src/Locale/hi/index.ts @@ -0,0 +1,45 @@ +import Asset from "./Asset.json"; +import Auth from "./Auth.json"; +import Bed from "./Bed.json"; +import Common from "./Common.json"; +import Consultation from "./Consultation.json"; +import CoverImageEdit from "./CoverImageEdit.json"; +import Diagnosis from "./Diagnosis.json"; +import Entities from "./Entities.json"; +import ErrorPages from "./ErrorPages.json"; +import ExternalResult from "./ExternalResult.json"; +import Facility from "./Facility.json"; +import FileUpload from "./FileUpload.json"; +import HCX from "./HCX.json"; +import Hub from "./Hub.json"; +import LogUpdate from "./LogUpdate.json"; +import Medicine from "./Medicine.json"; +import Notifications from "./Notifications.json"; +import Patient from "./Patient.json"; +import Resource from "./Resource.json"; +import Shifting from "./Shifting.json"; +import Users from "./Users.json"; + +export default { + ...Auth, + ...Asset, + ...Common, + ...Consultation, + ...CoverImageEdit, + ...Entities, + ...ErrorPages, + ...ExternalResult, + ...Facility, + ...Hub, + ...Medicine, + ...Diagnosis, + ...Notifications, + ...Patient, + ...Resource, + ...Shifting, + ...Bed, + ...Users, + ...LogUpdate, + ...FileUpload, + ...HCX, +}; diff --git a/src/Locale/kn/index.js b/src/Locale/kn/index.ts similarity index 89% rename from src/Locale/kn/index.js rename to src/Locale/kn/index.ts index 5c2b9219ced..ffaa7cab1c8 100644 --- a/src/Locale/kn/index.js +++ b/src/Locale/kn/index.ts @@ -11,8 +11,10 @@ import ExternalResult from "./ExternalResult.json"; import Facility from "./Facility.json"; import FileUpload from "./FileUpload.json"; import Hub from "./Hub.json"; +import LogUpdate from "./LogUpdate.json"; import Medicine from "./Medicine.json"; import Notifications from "./Notifications.json"; +import Resource from "./Resource.json"; import Shifting from "./Shifting.json"; import Users from "./Users.json"; @@ -30,8 +32,10 @@ export default { ...Medicine, ...Diagnosis, ...Notifications, + ...Resource, ...Shifting, ...Bed, ...Users, + ...LogUpdate, ...FileUpload, }; diff --git a/src/Locale/ml/index.ts b/src/Locale/ml/index.ts new file mode 100644 index 00000000000..ffaa7cab1c8 --- /dev/null +++ b/src/Locale/ml/index.ts @@ -0,0 +1,41 @@ +import Asset from "./Asset.json"; +import Auth from "./Auth.json"; +import Bed from "./Bed.json"; +import Common from "./Common.json"; +import Consultation from "./Consultation.json"; +import CoverImageEdit from "./CoverImageEdit.json"; +import Diagnosis from "./Diagnosis.json"; +import Entities from "./Entities.json"; +import ErrorPages from "./ErrorPages.json"; +import ExternalResult from "./ExternalResult.json"; +import Facility from "./Facility.json"; +import FileUpload from "./FileUpload.json"; +import Hub from "./Hub.json"; +import LogUpdate from "./LogUpdate.json"; +import Medicine from "./Medicine.json"; +import Notifications from "./Notifications.json"; +import Resource from "./Resource.json"; +import Shifting from "./Shifting.json"; +import Users from "./Users.json"; + +export default { + ...Auth, + ...Asset, + ...Common, + ...Consultation, + ...CoverImageEdit, + ...Entities, + ...ErrorPages, + ...ExternalResult, + ...Facility, + ...Hub, + ...Medicine, + ...Diagnosis, + ...Notifications, + ...Resource, + ...Shifting, + ...Bed, + ...Users, + ...LogUpdate, + ...FileUpload, +}; diff --git a/src/Locale/mr/index.js b/src/Locale/mr/index.js deleted file mode 100644 index cbf1d10c3b9..00000000000 --- a/src/Locale/mr/index.js +++ /dev/null @@ -1,11 +0,0 @@ -import Auth from "./Auth.json"; -import Common from "./Common.json"; -import Entities from "./Entities.json"; -import Facility from "./Facility.json"; - -export default { - ...Auth, - ...Common, - ...Entities, - ...Facility, -}; diff --git a/src/Locale/ml/index.js b/src/Locale/mr/index.ts similarity index 100% rename from src/Locale/ml/index.js rename to src/Locale/mr/index.ts diff --git a/src/Locale/ta/index.js b/src/Locale/ta/index.js deleted file mode 100644 index cbf1d10c3b9..00000000000 --- a/src/Locale/ta/index.js +++ /dev/null @@ -1,11 +0,0 @@ -import Auth from "./Auth.json"; -import Common from "./Common.json"; -import Entities from "./Entities.json"; -import Facility from "./Facility.json"; - -export default { - ...Auth, - ...Common, - ...Entities, - ...Facility, -}; diff --git a/src/Locale/ta/index.ts b/src/Locale/ta/index.ts new file mode 100644 index 00000000000..ffaa7cab1c8 --- /dev/null +++ b/src/Locale/ta/index.ts @@ -0,0 +1,41 @@ +import Asset from "./Asset.json"; +import Auth from "./Auth.json"; +import Bed from "./Bed.json"; +import Common from "./Common.json"; +import Consultation from "./Consultation.json"; +import CoverImageEdit from "./CoverImageEdit.json"; +import Diagnosis from "./Diagnosis.json"; +import Entities from "./Entities.json"; +import ErrorPages from "./ErrorPages.json"; +import ExternalResult from "./ExternalResult.json"; +import Facility from "./Facility.json"; +import FileUpload from "./FileUpload.json"; +import Hub from "./Hub.json"; +import LogUpdate from "./LogUpdate.json"; +import Medicine from "./Medicine.json"; +import Notifications from "./Notifications.json"; +import Resource from "./Resource.json"; +import Shifting from "./Shifting.json"; +import Users from "./Users.json"; + +export default { + ...Auth, + ...Asset, + ...Common, + ...Consultation, + ...CoverImageEdit, + ...Entities, + ...ErrorPages, + ...ExternalResult, + ...Facility, + ...Hub, + ...Medicine, + ...Diagnosis, + ...Notifications, + ...Resource, + ...Shifting, + ...Bed, + ...Users, + ...LogUpdate, + ...FileUpload, +}; diff --git a/src/Locale/update_locale.js b/src/Locale/update_locale.js index b6c0b17c5e3..61f5e32cf84 100644 --- a/src/Locale/update_locale.js +++ b/src/Locale/update_locale.js @@ -21,7 +21,7 @@ if (lng === DEFAULT_LOCALE) { process.exit(1); } -const defaultEntryFile = readFile(`./${DEFAULT_LOCALE}/index.js`); +const defaultEntryFile = readFile(`./${DEFAULT_LOCALE}/index.ts`); const defaultAllJsonFiles = getAllJSONFiles(DEFAULT_LOCALE); if (existsSync(lng)) { @@ -36,8 +36,8 @@ if (existsSync(lng)) { console.log(`Create: ${file}`); } - writeFile(`./${lng}/index.js`, defaultEntryFile); - console.log("Create: index.js"); + writeFile(`./${lng}/index.ts`, defaultEntryFile); + console.log("Create: index.ts"); } function compareBothFiles(defaultFile, newFile) { diff --git a/src/i18n.ts b/src/i18n.ts index 289e0fc325f..c2bfe58d541 100644 --- a/src/i18n.ts +++ b/src/i18n.ts @@ -6,6 +6,16 @@ import ta from "./Locale/ta"; import ml from "./Locale/ml"; import mr from "./Locale/mr"; import kn from "./Locale/kn"; +import hi from "./Locale/hi"; + +export const LANGUAGES: { [key: string]: any } = { + en: "English", + ta: "தமிழ்", + ml: "മലയാളം", + mr: "मराठी", + kn: "ಕನ್ನಡ", + hi: "हिन्दी", +}; const resources = { en: { translation: en }, @@ -13,6 +23,7 @@ const resources = { ml: { translation: ml }, mr: { translation: mr }, kn: { translation: kn }, + hi: { translation: hi }, }; i18n diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts index 7a50ebe49db..a14b5cd2122 100644 --- a/src/vite-env.d.ts +++ b/src/vite-env.d.ts @@ -31,6 +31,7 @@ interface ImportMetaEnv { readonly REACT_STILL_WATCHING_PROMPT_DURATION?: string; readonly REACT_JWT_TOKEN_REFRESH_INTERVAL?: string; readonly REACT_MIN_ENCOUNTER_DATE?: string; + readonly REACT_ALLOWED_LOCALES?: string; // Plugins related envs... readonly REACT_PLAUSIBLE_SERVER_URL?: string;