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

DESENG-611: Splitting translations based on language and common #2525

Merged
merged 6 commits into from
May 27, 2024

Conversation

ratheesh-aot
Copy link
Collaborator

@ratheesh-aot ratheesh-aot commented May 27, 2024

Issue #: https://apps.itsm.gov.bc.ca/jira/browse/DESENG-611

Description of changes:

  • Removed Tenant based translations from language files
    • Set TODO statements to replace tenant-related values from the backend. Ticket for this
    • Splitting translations based on language files and adding a common translation file for items common across all languages

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the met-public license (Apache 2.0).

@ratheesh-aot
Copy link
Collaborator Author

ratheesh-aot commented May 27, 2024

Quality Gate Failed Quality Gate failed

Failed conditions B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

Its because of the TODO Statements to replace tenant specific values from database which will done in another story

@codecov-commenter
Copy link

codecov-commenter commented May 27, 2024

Codecov Report

Attention: Patch coverage is 58.33333% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 76.02%. Comparing base (0959d82) to head (b8e1b55).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2525      +/-   ##
==========================================
- Coverage   76.04%   76.02%   -0.03%     
==========================================
  Files         617      617              
  Lines       22093    22095       +2     
  Branches     1686     1688       +2     
==========================================
- Hits        16801    16798       -3     
- Misses       5028     5032       +4     
- Partials      264      265       +1     
Flag Coverage Δ
metweb 64.70% <58.33%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...components/comments/admin/review/CommentReview.tsx 69.93% <100.00%> (ø)
...et-web/src/components/landing/LandingComponent.tsx 100.00% <ø> (ø)
...eb/src/components/layout/Header/InternalHeader.tsx 67.44% <100.00%> (-1.45%) ⬇️
met-web/src/hooks.ts 48.38% <50.00%> (-7.62%) ⬇️

Copy link
Collaborator

@Baelx Baelx left a comment

Choose a reason for hiding this comment

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

Thanks! You're free to merge but it'd be appreciated if you could maybe change variable names and add a bit more commenting so it can be clear how the complex language system of the app works.

@@ -137,17 +138,17 @@ const App = () => {

const getTranslationFile = async (languageId: string) => {
try {
const translationFile = await import(`./locales/${languageId}/${tenant.id}.json`);
const translationFile = await import(`./locales/${languageId}.json`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, here you might expect languageId to only correspond to a language, but now it can also be the word "common". I think we need to update variable names to account for this, or possibly restructure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed to localeId

const supportedLanguages = Object.values(Languages);
const supportedLanguages: string[] = Object.values(Languages);
// Adding keyword `common` into supportedLanguages to fetch locale/common.json
supportedLanguages.push('common');
Copy link
Collaborator

Choose a reason for hiding this comment

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

In reading this code, one would expect supportedLanguages to be a list of languages. I think adding the common entry could be confusing, although I can see that it simplifies the work a little bit.

For readability, I'd recommend either renaming Languages to LocaleFiles or some other solution that can make things a bit easier to understand.

Copy link
Collaborator Author

@ratheesh-aot ratheesh-aot May 27, 2024

Choose a reason for hiding this comment

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

Separated the code to load a common translation file

const translate = useTranslation();
const tenantId = sessionStorage.getItem('tenantId');
// Every language has its own default and common namespaces
const translate = useTranslation(['default', 'common']);

const { t } = translate;

Copy link
Collaborator

Choose a reason for hiding this comment

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

The language system in MET is inherently a bit confusing. The comments in this file are great so far, and maybe we could add a higher-level one above this function. Would this comment describe the intended behaviour?

Suggested change
/**
* Look to see if a string has a tenant-level translation (if it's related to an engagement, survey, widget, static
* tenant text, etc.). If none is found, look for a common static text translation found in the common locale file.
**/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated the comments

Copy link
Collaborator

@Baelx Baelx left a comment

Choose a reason for hiding this comment

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

Thanks for this!

Copy link

sonarcloud bot commented May 27, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

@ratheesh-aot ratheesh-aot merged commit ada21a5 into main May 27, 2024
7 of 8 checks passed
@NatSquared NatSquared deleted the DESENG-611-LanguageTranslation branch June 26, 2024 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants