Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows configuring available languages through env and adds Hindi to CARE #8692

Merged
merged 8 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -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_AVAILABLE_LOCALES="EN,HI,TA,ML,MR,KN"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we pick small case? 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't 'ALLOWED_LOCALES' term be more appropriate?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 changes: 3 additions & 0 deletions .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,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_AVAILABLE_LOCALES=EN,HI,TA,ML,MR,KN
3 changes: 3 additions & 0 deletions care.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_AVAILABLE_LOCALES || "")
.split(",")
.map((l) => l.trim().toLowerCase()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.map((l) => l.trim().toLowerCase()),
.map((l) => l.trim()),

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bodhish this is to be sure that random case characters in the ENV don't break things.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets not have it, env configuration is one time and validation for the env will take care of it. #8470


gmapsApiKey:
env.REACT_GMAPS_API_KEY || "AIzaSyDsBAc3y7deI5ZO3NtK5GuzKwtUzQNJNUk",
Expand Down
7 changes: 6 additions & 1 deletion src/Components/Common/LanguageSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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";

export const LanguageSelector = (props: any) => {
const { i18n } = useTranslation();
Expand All @@ -19,6 +20,10 @@ export const LanguageSelector = (props: any) => {
}
};

const availableLocales = Object.keys(LANGUAGE_NAMES).filter(
(l) => l === "en" || careConfig.availableLocales?.includes(l),
);

return (
<div className="relative flex w-full items-center justify-end">
<select
Expand All @@ -31,7 +36,7 @@ export const LanguageSelector = (props: any) => {
value={i18n.language}
onChange={(e: any) => handleLanguage(e.target.value)}
>
{Object.keys(LANGUAGE_NAMES).map((e: string) => (
{availableLocales.map((e: string) => (
<option key={e} value={e}>
{LANGUAGE_NAMES[e]}
</option>
Expand Down
9 changes: 7 additions & 2 deletions src/Components/Common/LanguageSelectorLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useEffect } from "react";
import { useTranslation } from "react-i18next";
import { LANGUAGE_NAMES } from "../../Locale/config";
import { classNames } from "../../Utils/utils";
import careConfig from "@careConfig";

export const LanguageSelectorLogin = () => {
const { i18n, t } = useTranslation();
Expand All @@ -17,12 +18,16 @@ export const LanguageSelectorLogin = () => {
}
};

const availableLocales = Object.keys(LANGUAGE_NAMES).filter(
(l) => l === "en" || careConfig.availableLocales?.includes(l),
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need a special case for en?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that even when there are no available languages set in env english is still there

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its safe to assume that the env will configured correctly, we also have a default set, so I think we can ignore it


return (
<div className="mt-8 flex flex-col items-center text-sm text-secondary-800">
{t("available_in")}
<br />
<div className="inline-flex flex-wrap gap-3">
{Object.keys(LANGUAGE_NAMES).map((e: string) => (
<div className="inline-flex flex-wrap items-center justify-center gap-3">
{availableLocales.map((e: string) => (
<button
key={e}
onClick={() => handleLanguage(e)}
Expand Down
1 change: 1 addition & 0 deletions src/Locale/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export const LANGUAGE_NAMES: { [key: string]: any } = {
ml: "മലയാളം",
mr: "मराठी",
kn: "ಕನ್ನಡ",
hi: "हिन्दी",
};
1 change: 1 addition & 0 deletions src/Locale/hi/HCX.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions src/Locale/hi/Patient.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
45 changes: 45 additions & 0 deletions src/Locale/hi/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import Asset from "./Asset.json";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this for all languages 🤔
Can't we write a dynamic import? ie all files in a folder 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Using dynamic imports as much as possible now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: Dynamic imports were causing issues during build due to their async nature. Reverted back.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't want us to have this file for each language, not a priority to fix now but I think we should find a better solution for this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can take this up in a later issue. Tracking it through #8705

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,
};
2 changes: 2 additions & 0 deletions src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ 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";

const resources = {
en: { translation: en },
ta: { translation: ta },
ml: { translation: ml },
mr: { translation: mr },
kn: { translation: kn },
hi: { translation: hi },
};

i18n
Expand Down
1 change: 1 addition & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_AVAILABLE_LOCALES?: string;

// Plugins related envs...
readonly REACT_PLAUSIBLE_SERVER_URL?: string;
Expand Down
Loading