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

feat[ATLAS-113]: add locale apis in core module #62

Draft
wants to merge 29 commits into
base: master
Choose a base branch
from

Conversation

RgnDunes
Copy link
Contributor

@RgnDunes RgnDunes commented Feb 1, 2024

Description

This PR adds locale apis in core module. Below are the details:

  • getLocalesByCountry : get array of locales based on the countryCode parameter passed. eg, getLocalesByCountry(IN) => ['en-IN', ‘hi-IN'..]
  • getDefaultLocales : get a country to default locale mapping for all country codes.. eg, { IN: ‘en-IN’, … }
  • getAllLocales : get a country to all locales mapping for all country codes.. eg, { IN: ['en-IN', ‘hi-IN'..], … }
  • getDefaultLocaleByCountry : get default locale based on the countryCode parameter passed. eg, getLocalesByCountry(IN) => 'en-IN'

Changes Made

List the main changes made in this pull request.

Title ---
JIRA link https://razorpay.atlassian.net/browse/ATLAS-113
Slack thread (if any) NA
Product spec NA
Tech spec/One-pager NA
Bundle Size Difference NA
Fixes Issue NA

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • This change is a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Is your change backward compatible ?
  • Tested on major browsers (Chrome, Firefox, Safari, IE) ?
  • Tested in a consumer application(s) ?

Additional Notes

Any additional information that would be helpful for the reviewer.

Checklist:

  • Add Jira ID(s) in PR title and in the description?
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My code is written in TypeScript and follows the coding standards of the project.
  • I have added relevant documentation and updated the README if necessary.
  • My commit messages are clear and follow the project's commit message conventions.
  • Is any external library added?
  • My changes do not introduce any new runtime errors or warnings.
  • All relevant unit tests have been added/updated in my PR for the change.
  • Any Screenshots (mobile & desktop) required for PR? If yes, have you added the respective screenshots ?
  • Any manual dev testing done by you on beta/func environment?
  • Reviewer added (SLA 2 days)

Reviewer Checklist

  • Sufficient QA/Dev-Testing is done with proof (test cases list)
  • Ensure that the change in bundle size falls within the acceptable range.

PR Title Format

Format: <type>: <subject>

Types can be as follows:

  • feat: (new feature for the user, not a new feature for build script)
  • fix: (bug fix for the user, not a fix to a build script)
  • docs: (changes to the documentation)
  • style: (formatting, missing semi colons, etc; no production code change)
  • refactor: (refactoring production code, eg. renaming a variable)
  • test: (adding missing tests, refactoring tests; no production code change)
  • chore: (updating grunt tasks etc; no production code change)

Copy link

changeset-bot bot commented Feb 1, 2024

🦋 Changeset detected

Latest commit: b5e1eb1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@razorpay/i18nify-js Minor
@razorpay/i18nify-react Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This comment has been minimized.

This comment has been minimized.

@rzpcibot
Copy link
Contributor

rzpcibot commented Feb 1, 2024

Bundle Size Report

Files

click to expand/collapse
🟢 No Change 🗑 File Deleted 🆕 New File 📈 Size Increased 👍 Size Reduced
Parsed (kb)
🚦 File Name Base PR Diff %
📈 cjs/index.js 160.1 168.14 $\textcolor{red}{8.04}$ 5.02
📈 esm/index.min.js 50.96 54.53 $\textcolor{red}{3.57}$ 7.01
📈 umd/index.js 176.26 185.19 $\textcolor{red}{8.93}$ 5.07

Generated by 🚫 dangerJS against b5e1eb1

This comment has been minimized.

This comment has been minimized.

@RgnDunes RgnDunes marked this pull request as draft February 1, 2024 10:25

This comment has been minimized.

@RgnDunes RgnDunes changed the title feat[ATLAS-113]: add getDefaultLocaleForAllCountries api in locale module feat[ATLAS-113]: add locale apis in core module Feb 5, 2024

This comment has been minimized.

@codecov-commenter
Copy link

codecov-commenter commented Feb 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.39%. Comparing base (1047227) to head (b17d19f).
Report is 12 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #62      +/-   ##
==========================================
+ Coverage   95.00%   95.39%   +0.38%     
==========================================
  Files          44       49       +5     
  Lines         501      543      +42     
  Branches      128      133       +5     
==========================================
+ Hits          476      518      +42     
  Misses         24       24              
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

This comment has been minimized.

This comment has been minimized.

@@ -0,0 +1,5 @@
---
"@razorpay/i18nify-js": patch
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will be minor.


#### getDefaultLocaleByCountry(countryCode)

📌 Pinpoint Precision. When precision matters, getDefaultLocaleByCountry is your meticulous matchmaker, pairing country codes with their default locales. This function is like having a linguistic concierge for each country, ensuring you deliver the right cultural context straight out of the box. From the bustling streets of Tokyo to the serene fjords of Norway, setting the scene for your users has never been more accurate. 🎯✨
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's keep this more crips and technical.


// Reset everything!
resetState();
```

#### getAllLocales()

🌍 The Global Gathering. Dive into the diversity of our planet with getAllLocales! This function is your atlas, mapping out a rich array of locales for each country. With a simple call, embark on a journey through countries and their multiple locales, from the peaks of Peru to the sands of Saudi Arabia. Whether it's for localization, cultural exploration, or linguistic curiosity, getAllLocales is your ticket to a world tour of languages! 🗺️✨
Copy link
Collaborator

Choose a reason for hiding this comment

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

more crips and technical.

@@ -0,0 +1,98 @@
// A map of countries to their default locale.
export const COUNTRY_TO_DEFAULT_LOCALES = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to have another config, utilise COUNTRY_TO_ALL_LOCALES and keep the default locale at 0th index for all countries. Create the config dynamically from there.

* @returns A map where the key is the country code and the value is an array of locale strings.
*/
const getAllLocales = (): typeof COUNTRY_TO_ALL_LOCALES => {
return COUNTRY_TO_ALL_LOCALES;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to dynamically import this.

* @returns The default locale string for the given country.
* @throws An error if the provided country code does not exist in the map.
*/
const getDefaultLocaleByCountry = (countryCode: keyof typeof COUNTRY_TO_DEFAULT_LOCALES): string => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Dynamic import.


```
import { setState } from "@razorpay/i18nify-js/core";
##### Examples
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can include 1 more API.. getLocale which detects locale from browser and returns it. This can be a sync utility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We already have this utility in .internal. Reusing that.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@RgnDunes RgnDunes marked this pull request as ready for review February 13, 2024 20:33

This comment has been minimized.

@RgnDunes RgnDunes marked this pull request as draft February 14, 2024 13:12
@RgnDunes RgnDunes marked this pull request as ready for review February 22, 2024 13:14

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

github-actions bot commented Apr 5, 2024

Unit Test Results

0 files  0 suites   0s ⏱️
0 tests 0 ✔️ 0 💤 0 ❌

Results for commit b5e1eb1.

@RgnDunes RgnDunes marked this pull request as draft April 9, 2024 11:04
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.

None yet

4 participants