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

OAM-89: add util function to handle translations in react components #87

Merged
merged 1 commit into from
May 8, 2024

Conversation

olewandowski1
Copy link
Contributor

@olewandowski1 olewandowski1 commented May 8, 2024

OAM-89

Changes:

  • Utilized the existing 'messageService' for translating React components.
  • Created a 'formatMessage' function, akin to utility functions in popular translation libraries.

How to use it:

  1. Create keys in messages_en.json.
{
  "requisition.orderCreate.header": "Create Order",
  "requisition.orderCreate.body": "Create Order ${number}",
}
  1. Integrate the formatMessage function into your component.
const formatMessage = useMemo(() => getService('messageService'), []).formatMessage;
  1. Use the formatMessage function to get translations in your JSX.
<p> {formatMessage('requisition.orderCreate.header')} </p>
  1. You can pass an object with parameters. If you provide a parameter different from what's specified in the translation key, a placeholder labeled 'MISSING_PARAM' will be displayed.
<p> {formatMessage('requisition.orderCreate.body', { number: '1' })} </p>

NOTE: If a translation key isn't found, the key itself will be displayed, and an accurate error will be logged in the console.

Copy link

sonarcloud bot commented May 8, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud

@olewandowski1 olewandowski1 marked this pull request as ready for review May 8, 2024 07:06
Copy link
Contributor

@mdulko-soldevelo mdulko-soldevelo left a comment

Choose a reason for hiding this comment

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

lgtm

@mdulko-soldevelo mdulko-soldevelo merged commit 6d5abd3 into master May 8, 2024
1 of 2 checks passed
@olewandowski1 olewandowski1 deleted the feature/OAM-89 branch May 8, 2024 09:07
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.

2 participants