From ada21a5f71920d55511adc8bd744e34fdc3da893 Mon Sep 17 00:00:00 2001 From: Ratheesh kumar R <108045773+ratheesh-aot@users.noreply.github.com> Date: Mon, 27 May 2024 16:13:27 -0700 Subject: [PATCH] DESENG-611: Splitting translations based on language and common (#2525) * DESENG-611: Removing tenant related translation text, set TODO for replacement * DESENG-611: Splitting translations based on language and common * Updating changelog * Updated unit test file * Restructured the logic to get common translations and updated the comments * Spelling correction --- CHANGELOG.MD | 8 + met-web/src/App.tsx | 23 +- met-web/src/DocumentTitle.tsx | 5 +- .../comments/admin/review/CommentReview.tsx | 9 +- .../components/landing/LandingComponent.tsx | 9 +- .../layout/Header/InternalHeader.tsx | 11 +- .../components/layout/Header/PublicHeader.tsx | 12 +- met-web/src/hooks.ts | 27 +- met-web/src/i18n.ts | 1 + met-web/src/locales/common.json | 100 ++++++ .../src/locales/{en/default.json => en.json} | 86 +---- met-web/src/locales/en/gdx.json | 334 ------------------ met-web/src/routes/NotAvailable.tsx | 9 +- .../landingPage/LandingPage.test.tsx | 6 +- 14 files changed, 189 insertions(+), 451 deletions(-) create mode 100644 met-web/src/locales/common.json rename met-web/src/locales/{en/default.json => en.json} (77%) delete mode 100644 met-web/src/locales/en/gdx.json diff --git a/CHANGELOG.MD b/CHANGELOG.MD index bc4f1c293..c0ac61f3c 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -1,3 +1,11 @@ +## May 27, 2024 + +- **Feature** MET translation file keys used on pages needing translation [🎟️ DESENG-611](https://apps.itsm.gov.bc.ca/jira/browse/DESENG-611) + - Removed Tenant based translations from langauge files + - Set TODO statements to replace tenant related values from backend + - Splitting translations based on language files and added a common translation file for items common across all languages + + ## May 23, 2024 - **Feature** Finish tenant management UX [🎟️ DESENG-605](https://apps.itsm.gov.bc.ca/jira/browse/DESENG-605), [🎟️ DESENG-606](https://apps.itsm.gov.bc.ca/jira/browse/DESENG-606) diff --git a/met-web/src/App.tsx b/met-web/src/App.tsx index 89b0c50b6..84bacdd2f 100644 --- a/met-web/src/App.tsx +++ b/met-web/src/App.tsx @@ -115,9 +115,8 @@ const App = () => { if (!tenant.id) { return; } - try { - const supportedLanguages = Object.values(Languages); + const supportedLanguages: string[] = Object.values(Languages); const translationPromises = supportedLanguages.map((languageId) => getTranslationFile(languageId)); const translationFiles = await Promise.all(translationPromises); @@ -129,25 +128,31 @@ const App = () => { } }); + // Fetch the common.json file separately + const commonTranslations = await getTranslationFile('common'); + if (commonTranslations) { + translationsObj['common'] = commonTranslations.default; + } + setTranslations(translationsObj); } catch (error) { console.error('Error preloading translations:', error); } }; - const getTranslationFile = async (languageId: string) => { + const getTranslationFile = async (localeId: string) => { try { - const translationFile = await import(`./locales/${languageId}/${tenant.id}.json`); + const translationFile = await import(`./locales/${localeId}.json`); return translationFile; } catch (error) { - const defaultTranslationFile = await import(`./locales/${languageId}/default.json`); + const defaultTranslationFile = await import(`./locales/en.json`); return defaultTranslationFile; } }; useEffect(() => { preloadTranslations(); - }, [tenant.id]); // Preload translations when tenant id changes + }, [language.id, tenant.id]); // Preload translations when language id or tenant id changes const loadTranslation = async () => { if (!tenant.id || !translations[language.id]) { @@ -157,7 +162,11 @@ const App = () => { i18n.changeLanguage(language.id); // Set the language for react-i18next try { - i18n.addResourceBundle(language.id, tenant.id, translations[language.id]); + // adding language based translation resources to default namespace 'default'. like en.json, fr.json etc + i18n.addResourceBundle(language.id, 'default', translations[language.id]); + // adding common translation resource file (common.json) to namespace 'common' + i18n.addResourceBundle(language.id, 'common', translations['common']); + dispatch(loadingTenant(false)); } catch (error) { dispatch(loadingTenant(false)); diff --git a/met-web/src/DocumentTitle.tsx b/met-web/src/DocumentTitle.tsx index 9be6b3dcb..ed82b18f3 100644 --- a/met-web/src/DocumentTitle.tsx +++ b/met-web/src/DocumentTitle.tsx @@ -1,11 +1,10 @@ import React from 'react'; import { Helmet } from 'react-helmet-async'; -import { useAppTranslation } from 'hooks'; const DocumentTitle = () => { - const { t: translate } = useAppTranslation(); return ( - {translate('header.title')} + {/* TODO: LANG-BACKEND - Change the value to show tenant specific */} + Modern Engagement ); }; diff --git a/met-web/src/components/comments/admin/review/CommentReview.tsx b/met-web/src/components/comments/admin/review/CommentReview.tsx index a4288a255..5391fbd8b 100644 --- a/met-web/src/components/comments/admin/review/CommentReview.tsx +++ b/met-web/src/components/comments/admin/review/CommentReview.tsx @@ -205,7 +205,8 @@ const CommentReview = () => { }; const defaultVerdict = comment_status_id !== CommentStatus.Pending ? comment_status_id : CommentStatus.Approved; - const threatEmailContact = translate('comment.admin.review.threatContactEmail'); + // TODO: LANG-BACKEND - Change the value to show tenant specific + const threatEmailContact = 'email@gov.bc.ca'; return ( { } /> - {translate('comment.admin.review.threatTextOne')}{' '} - {translate('comment.admin.review.threatContact')}{' '} + {translate('comment.admin.review.threatTextOne')} + {/* TODO: LANG-BACKEND - Change the value to show tenant specific // + comment.admin.review.threatContact */} + {'FirstName LastName'} {translate('comment.admin.review.threatTextTwo')}{' '} {threatEmailContact} diff --git a/met-web/src/components/landing/LandingComponent.tsx b/met-web/src/components/landing/LandingComponent.tsx index 0a0618c5d..fd2b1466a 100644 --- a/met-web/src/components/landing/LandingComponent.tsx +++ b/met-web/src/components/landing/LandingComponent.tsx @@ -5,12 +5,9 @@ import { MetHeader1Old, MetParagraphOld } from 'components/common'; import TileBlock from './TileBlock'; import { Container } from '@mui/system'; import LandingPageBanner from 'assets/images/LandingPageBanner.png'; -import { useAppTranslation } from 'hooks'; import FilterBlock from './FilterBlock'; import FilterDrawer from './FilterDrawer'; const LandingComponent = () => { - const { t: translate } = useAppTranslation(); - return ( @@ -47,10 +44,12 @@ const LandingComponent = () => { rowSpacing={2} > - {translate('landing.banner.header')} + {/* TODO: LANG-BACKEND - Change the value to show tenant specific */} + Government Digital Experience Division - {translate('landing.banner.description')} + {/* TODO: LANG-BACKEND - Change the value to show tenant specific */} + Description about the office and public engagement. diff --git a/met-web/src/components/layout/Header/InternalHeader.tsx b/met-web/src/components/layout/Header/InternalHeader.tsx index 53c3860b4..65c5cdda5 100644 --- a/met-web/src/components/layout/Header/InternalHeader.tsx +++ b/met-web/src/components/layout/Header/InternalHeader.tsx @@ -16,16 +16,15 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faBars } from '@fortawesome/pro-regular-svg-icons/faBars'; import { HeaderProps } from './types'; import { useNavigate } from 'react-router-dom'; -import { useAppTranslation } from 'hooks'; const InternalHeader = ({ drawerWidth = 280 }: HeaderProps) => { const isMediumScreen: boolean = useMediaQuery((theme: Theme) => theme.breakpoints.up('md')); const [open, setOpen] = useState(false); const [imageError, setImageError] = useState(false); const navigate = useNavigate(); - const { t: translate } = useAppTranslation(); - const logoUrl = translate('common.logoUrl'); + // TODO: LANG-BACKEND - Change the value to show tenant specific + const logoUrl = ''; return ( <> { }} sx={{ flexGrow: 1, cursor: 'pointer' }} > - {translate('header.title')} + {/* TODO: LANG-BACKEND - Change the value to show tenant specific */} + {'Modern Engagement'} ) : ( { }} sx={{ flexGrow: 1, cursor: 'pointer' }} > - {translate('header.smallTitle')} + {/* TODO: LANG-BACKEND - Change the value to show tenant specific */} + {'MET'} )}