-
Notifications
You must be signed in to change notification settings - Fork 2
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
Closed
Closed
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
4e7148c
add getDefaultLocaleForAllCountries api
RgnDunes 48874da
add UT for getDefaultLocaleForAllCountries
RgnDunes 3d58ed1
Create silver-zoos-raise.md
RgnDunes 3d48295
migrate locale module to core module
RgnDunes ead0f79
update README
RgnDunes 104c66e
Merge remote-tracking branch 'origin/master' into ATLAS-113-add-getDe…
RgnDunes a30e0e5
add other locale based functions in code module
RgnDunes 2312772
Update silver-zoos-raise.md
RgnDunes 7205835
update README with locale apis docs
RgnDunes ca7d9cb
reformat README
RgnDunes 0cab1b6
add dynamic import in getAllLocales
RgnDunes bcb138c
add dynamic import in getDefaultLocaleForAllCountries
RgnDunes 27b22fa
resolve review comments
RgnDunes 20a7dd1
resolve review comments
RgnDunes cd440e6
Merge remote-tracking branch 'origin/master' into ATLAS-113-add-getDe…
RgnDunes dd4b0e8
update readme with locale apis desc
RgnDunes bf164a9
update readme formatting
RgnDunes b179d1d
[fix]: fix failing UT
RgnDunes f05b86b
[fix]: Failing UT plus exception messages
RgnDunes b58aaef
Merge branch 'master' into ATLAS-113-add-getDefaultLocales
RgnDunes f761fa0
Merge remote-tracking branch 'origin/master' into ATLAS-113-add-getDe…
RgnDunes 1ef3bae
Merge remote-tracking branch 'origin/master' into ATLAS-113-add-getDe…
RgnDunes 956022f
Merge remote-tracking branch 'origin/master' into ATLAS-113-add-getDe…
RgnDunes 4dc6c49
fix failing UT
RgnDunes e2907ce
fix failing UT
RgnDunes b875d5a
Merge remote-tracking branch 'origin/master' into ATLAS-113-add-getDe…
RgnDunes 37a8ff9
Merge remote-tracking branch 'origin/master' into ATLAS-113-add-getDe…
RgnDunes b17d19f
[chore]: back merge master
RgnDunes b5e1eb1
Merge branch 'master' into ATLAS-113-add-getDefaultLocales
RgnDunes File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@razorpay/i18nify-js': minor | ||
--- | ||
|
||
[feat]: add locale based apis in core module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/i18nify-js/src/modules/core/__tests__/getAllLocales.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import getAllLocales from '../getAllLocales'; | ||
|
||
// Mock the COUNTRY_TO_ALL_LOCALES data | ||
jest.mock('../data/countryToAllLocales', () => ({ | ||
COUNTRY_TO_ALL_LOCALES: { | ||
US: ['en-US', 'es-US'], | ||
GB: ['en-GB', 'cy-GB'], | ||
CA: ['en-CA', 'fr-CA'], | ||
}, | ||
})); | ||
|
||
describe('core - getAllLocales', () => { | ||
it('should return all countries with their respective locales', async () => { | ||
const expected = { | ||
US: ['en-US', 'es-US'], | ||
GB: ['en-GB', 'cy-GB'], | ||
CA: ['en-CA', 'fr-CA'], | ||
// Expected data matching the mock | ||
}; | ||
|
||
const result = await getAllLocales(); | ||
|
||
// Verify the result matches the expected object | ||
expect(result).toEqual(expected); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
packages/i18nify-js/src/modules/core/__tests__/getDefaultLocaleByCountry.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import getDefaultLocaleByCountry from '../getDefaultLocaleByCountry'; | ||
|
||
jest.mock('../data/countryToAllLocales.ts', () => ({ | ||
COUNTRY_TO_ALL_LOCALES: { | ||
AE: ['ar-AE', 'en-AE'], | ||
US: ['en-US', 'es-US', 'haw-US'], | ||
IN: ['en-IN', 'hi-IN'], | ||
// ... more countries here | ||
}, | ||
})); | ||
|
||
describe('core - getDefaultLocaleByCountry', () => { | ||
it('returns the default locale for a valid country code', async () => { | ||
await expect(getDefaultLocaleByCountry('AE')).resolves.toBe('ar-AE'); | ||
await expect(getDefaultLocaleByCountry('US')).resolves.toBe('en-US'); | ||
await expect(getDefaultLocaleByCountry('IN')).resolves.toBe('en-IN'); | ||
}); | ||
|
||
it('throws an error for an invalid country code', async () => { | ||
await expect(getDefaultLocaleByCountry('XX' as any)).rejects.toThrow( | ||
'Invalid countryCode: XX', | ||
); | ||
}); | ||
|
||
it('returns the only locale for countries with a single locale', async () => { | ||
jest.mock('../data/countryToAllLocales', () => ({ | ||
COUNTRY_TO_ALL_LOCALES: { | ||
IN: ['en-IN'], // Mocked to only have one locale | ||
}, | ||
})); | ||
await expect(getDefaultLocaleByCountry('IN')).resolves.toBe('en-IN'); | ||
}); | ||
|
||
it('always returns the first locale for countries with multiple locales', async () => { | ||
await expect(getDefaultLocaleByCountry('US')).resolves.toBe('en-US'); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
packages/i18nify-js/src/modules/core/__tests__/getDefaultLocaleForAllCountries.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import getDefaultLocaleForAllCountries from '../getDefaultLocaleForAllCountries'; | ||
|
||
// Mock the COUNTRY_TO_ALL_LOCALES data | ||
jest.mock('../data/countryToAllLocales', () => ({ | ||
COUNTRY_TO_ALL_LOCALES: { | ||
AE: ['ar-AE', 'en-AE'], | ||
US: ['en-US', 'es-US'], | ||
IN: ['hi-IN', 'en-IN'], | ||
}, | ||
})); | ||
|
||
describe('locales - getDefaultLocaleForAllCountries', () => { | ||
it('should return a map of countries to their default locales', async () => { | ||
const expected = { | ||
AE: 'ar-AE', | ||
US: 'en-US', | ||
IN: 'hi-IN', | ||
// Expected default locales for mock countries | ||
}; | ||
|
||
const result = await getDefaultLocaleForAllCountries(); | ||
|
||
// Verify the result matches the expected object | ||
expect(result).toEqual(expected); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
packages/i18nify-js/src/modules/core/__tests__/getLocalesByCountry.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import getLocalesByCountry from '../getLocalesByCountry'; | ||
|
||
// Mock the COUNTRY_TO_ALL_LOCALES data for consistent testing | ||
jest.mock('../data/countryToAllLocales', () => ({ | ||
COUNTRY_TO_ALL_LOCALES: { | ||
US: ['en-US', 'es-US'], | ||
GB: ['en-GB', 'cy-GB'], | ||
}, | ||
})); | ||
|
||
describe('core - getLocalesByCountry', () => { | ||
it('returns all locales for a valid country code', () => { | ||
expect(getLocalesByCountry('US')).toEqual(['en-US', 'es-US']); | ||
expect(getLocalesByCountry('GB')).toEqual(['en-GB', 'cy-GB']); | ||
}); | ||
|
||
it('throws an error for an invalid country code', () => { | ||
const invalidCountryCode = 'XX'; // 'XX' is not a valid country code | ||
// @ts-expect-error The function `getLocalesByCountry` is expected to have a mismatched type here so as to test the exception. | ||
expect(() => getLocalesByCountry(invalidCountryCode)).toThrow( | ||
`Invalid countryCode: ${invalidCountryCode}`, | ||
); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.