-
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
Changes from 10 commits
4e7148c
48874da
3d58ed1
3d48295
ead0f79
104c66e
a30e0e5
2312772
7205835
ca7d9cb
0cab1b6
bcb138c
27b22fa
20a7dd1
cd440e6
dd4b0e8
bf164a9
b179d1d
f05b86b
b58aaef
f761fa0
1ef3bae
956022f
4dc6c49
e2907ce
b875d5a
37a8ff9
b17d19f
b5e1eb1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@razorpay/i18nify-js": patch | ||
--- | ||
|
||
[feat]: add locale based apis in core module |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,26 +27,32 @@ Go on, code conqueror, the adventure awaits! | |
|
||
Welcome to the command center for your i18n experience! This module serves as the control hub, housing the essential functions to manage your i18n settings seamlessly. This module offers a trio of functions to handle all your i18n needs. Whether it's checking the current state, customizing settings, or starting afresh, this module has got you covered in managing your i18n world! 🚀 | ||
|
||
#### Functions | ||
#### setState(newState) | ||
|
||
**setState(newState: Partial `<I18nState>`):** Customize and update your i18n state with ease! Whether you're changing locales or tweaking directions, this function is your ticket to tailor your i18n experience precisely how you want it! 🎨 | ||
Customize and update your i18n state with ease! Whether you're changing locales or tweaking directions, this function is your ticket to tailor your i18n experience precisely how you want it! 🎨 | ||
|
||
``` | ||
import { setState } from "@razorpay/i18nify-js/core"; | ||
##### Examples | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can include 1 more API.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have this utility in |
||
|
||
```javascript | ||
import { setState } from '@razorpay/i18nify-js/core'; | ||
|
||
// Set a new locale | ||
setState({ locale: 'en-US' }); | ||
``` | ||
|
||
**getState():** Peek into the current i18n state – the active locale, direction, and country settings – at any time, giving you a snapshot of your i18n setup! 📸 | ||
#### getState() | ||
|
||
``` | ||
Peek into the current i18n state – the active locale, direction, and country settings – at any time, giving you a snapshot of your i18n setup! 📸 | ||
|
||
##### Examples | ||
|
||
```javascript | ||
import { getState } from '@razorpay/i18nify-js/core'; | ||
|
||
// Get the current state | ||
const currentState = getState(); | ||
console.log(currentState); | ||
/* | ||
/* | ||
{ | ||
locale: 'en-US', | ||
direction: '', | ||
|
@@ -55,15 +61,95 @@ console.log(currentState); | |
*/ | ||
``` | ||
|
||
**resetState():** Made a mess? No worries! Hit the reset button with this function. It's the ultimate undo for your i18n adjustments, whisking your settings back to their pristine defaults. Fresh start, anyone? 🆕 | ||
#### resetState() | ||
|
||
``` | ||
import { resetState } from "@razorpay/i18nify-js/core"; | ||
Made a mess? No worries! Hit the reset button with this function. It's the ultimate undo for your i18n adjustments, whisking your settings back to their pristine defaults. Fresh start, anyone? 🆕 | ||
|
||
##### Examples | ||
|
||
```javascript | ||
import { resetState } from '@razorpay/i18nify-js/core'; | ||
|
||
// 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! 🗺️✨ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. more crips and technical. |
||
|
||
##### Examples | ||
|
||
```javascript | ||
// Retrieve all locales for every country | ||
const allLocales = getAllLocales(); | ||
console.log(allLocales); // { AE: ['ar_AE', 'en_AE'], AL: ['sq_AL'], ... } | ||
|
||
// Exploring locales for United Arab Emirates | ||
console.log(allLocales.AE); // ['ar_AE', 'en_AE'] | ||
|
||
// Checking out the locales for Albania | ||
console.log(allLocales.AL); // ['sq_AL'] | ||
``` | ||
|
||
Embrace the linguistic landscape of our world. getAllLocales is your guide to the rich tapestry of languages that paint our global village. 🌐📚 | ||
|
||
#### 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. 🎯✨ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep this more crips and technical. |
||
|
||
##### Examples | ||
|
||
```javascript | ||
// Get the default locale for Japan | ||
const japanLocale = getDefaultLocaleByCountry('JP'); | ||
console.log(japanLocale); // 'ja-JP' | ||
|
||
// Get the default locale for Norway | ||
const norwayLocale = getDefaultLocaleByCountry('NO'); | ||
console.log(norwayLocale); // 'no-NO' | ||
``` | ||
|
||
With getDefaultLocaleByCountry, you're not just coding; you're curating cultural experiences. Fine-tune your application's language settings and celebrate the diversity of your user base! 🌍💬 | ||
|
||
#### getLocalesByCountry(countryCode) | ||
|
||
🧭 Locale Explorer. Set sail on a linguistic expedition with getLocalesByCountry! This function is your compass, pointing to all the locales a country embraces. Whether you're tailoring content for the cosmopolitan cities of Canada or the traditional towns of Tanzania, this function ensures you have the full list of linguistic lanes to traverse. It's not just a function; it's your passport to personalization and precision. 🛤️✨ | ||
|
||
##### Examples | ||
|
||
```javascript | ||
// Retrieve locales for Canada | ||
const canadaLocales = getLocalesByCountry('CA'); | ||
console.log(canadaLocales); // ['en_CA', 'fr_CA', ...] | ||
|
||
// Retrieve locales for Tanzania | ||
const tanzaniaLocales = getLocalesByCountry('TZ'); | ||
console.log(tanzaniaLocales); // ['sw_TZ', 'en_TZ'] | ||
``` | ||
|
||
With getLocalesByCountry, your application doesn't just speak languages; it speaks cultures. Navigate the nuances of localization and give your users a home feeling, no matter where they are. 🌍🔍 | ||
|
||
#### getDefaultLocales() | ||
|
||
🌐 This powerhouse function is like the United Nations of locales, bringing together a world of country codes and their corresponding default locales. It's simple: call it, and you get an object packed with every country code linked to its default locale. From 'IN' to 'MY', and beyond, gearing up your app to go global has never been easier! 🌍✨ | ||
|
||
##### Examples | ||
|
||
```javascript | ||
// Retrieve default locales for all countries | ||
const locales = getDefaultLocales(); | ||
console.log(locales); // { IN: 'en-IN', MY: 'ms-MY', ... } | ||
|
||
// Accessing the default locale for India | ||
console.log(locales.IN); // 'en-IN' | ||
|
||
// Accessing the default locale for Malaysia | ||
console.log(locales.MY); // 'ms-MY' | ||
``` | ||
|
||
With this module, localizing your application is straightforward and efficient. It's like having a world map of languages and cultures right at your fingertips. Dive in and give your users the local touch they deserve! 🌐✨ | ||
|
||
### Module 01: Currency | ||
|
||
This module's your go-to guru for everything currency/number-related. 🤑 It's all about formatting, validations, and handy tricks to make dealing with money/numbers a breeze. Here are the cool APIs and utilities this Currency Module gives you to play with! 🚀💸 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import getAllLocales from '../getAllLocales'; | ||
|
||
describe('core - getAllLocales', () => { | ||
it('should return all locales', () => { | ||
const locales = getAllLocales(); | ||
expect(locales).toBeDefined(); | ||
expect(locales.AE).toEqual(expect.arrayContaining(['ar_AE', 'en_AE'])); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import getDefaultLocaleByCountry from '../getDefaultLocaleByCountry'; | ||
|
||
describe('core - getDefaultLocaleByCountry', () => { | ||
it('should return the default locale for a valid country', () => { | ||
expect(getDefaultLocaleByCountry('AE')).toEqual('ar-AE'); | ||
}); | ||
|
||
it('should throw an error for an invalid country code', () => { | ||
expect(() => getDefaultLocaleByCountry('INVALID_CODE' as any)).toThrow('Invalid countryCode!'); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import getDefaultLocaleForAllCountries from '../getDefaultLocaleForAllCountries'; | ||
import { COUNTRY_TO_DEFAULT_LOCALES } from '../data/countryToDefaultLocales'; | ||
|
||
describe('locales - getDefaultLocaleForAllCountries', () => { | ||
test('should return the correct country to default locale mapping', () => { | ||
const defaultLocaleForAllCountriesList = getDefaultLocaleForAllCountries(); | ||
expect(defaultLocaleForAllCountriesList).toEqual(COUNTRY_TO_DEFAULT_LOCALES); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import getLocalesByCountry from '../getLocalesByCountry'; | ||
|
||
describe('core - getLocalesByCountry', () => { | ||
it('should return locales for a valid country', () => { | ||
expect(getLocalesByCountry('AE')).toEqual(expect.arrayContaining(['ar_AE', 'en_AE'])); | ||
}); | ||
|
||
it('should throw an error for an invalid country code', () => { | ||
expect(() => getLocalesByCountry('INVALID_CODE' as any)).toThrow('Invalid countryCode!'); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// A map of countries to all their respective locales. | ||
export const COUNTRY_TO_ALL_LOCALES = { | ||
AE: ["ar_AE", "en_AE"], | ||
AL: ["sq_AL"], | ||
AM: ["hy_AM"], | ||
AR: ["es_AR"], | ||
AU: ["en_AU"], | ||
AW: ["nl_AW", "pap_AW"], | ||
BB: ["en_BB"], | ||
BD: ["bn_BD"], | ||
BM: ["en_BM"], | ||
BN: ["ms_BN", "zh_BN"], | ||
BO: ["es_BO", "qu_BO", "ay_BO"], | ||
BS: ["en_BS"], | ||
BW: ["en_BW", "tn_BW"], | ||
BZ: ["en_BZ", "es_BZ"], | ||
CA: ["en_CA", "fr_CA", "iu_CA", "cr_CA"], | ||
CH: ["de_CH", "fr_CH", "it_CH", "rm_CH"], | ||
CN: ["zh_CN", "ug_CN", "ii_CN", "za_CN"], | ||
CO: ["es_CO"], | ||
CR: ["es_CR"], | ||
CU: ["es_CU"], | ||
CZ: ["cs_CZ"], | ||
DK: ["da_DK"], | ||
DO: ["es_DO"], | ||
DZ: ["ar_DZ", "kab_DZ", "tzm_DZ"], | ||
EG: ["ar_EG"], | ||
ET: ["am_ET", "om_ET", "ti_ET", "so_ET"], | ||
EU: ["en_EU", "fr_EU", "de_EU", "es_EU", "it_EU", "pt_EU"], | ||
FJ: ["en_FJ", "fj_FJ"], | ||
GB: ["en_GB", "cy_GB", "gd_GB"], | ||
GH: ["en_GH", "ak_GH", "ee_GH", "tw_GH"], | ||
GI: ["en_GI"], | ||
GM: ["en_GM"], | ||
GT: ["es_GT"], | ||
GY: ["en_GY"], | ||
HK: ["zh_HK", "en_HK"], | ||
HN: ["es_HN"], | ||
HR: ["hr_HR"], | ||
HT: ["fr_HT", "ht_HT"], | ||
HU: ["hu_HU"], | ||
ID: ["id_ID", "jv_ID", "su_ID"], | ||
IL: ["he_IL", "ar_IL"], | ||
IN: ["hi_IN", "bn_IN", "te_IN", "mr_IN", "ta_IN", "ur_IN", "gu_IN", "kn_IN", "ml_IN", "or_IN", "pa_IN", "as_IN", "ne_IN", "sat_IN", "ks_IN", "kok_IN", "doi_IN", "mni_IN", "sit_IN", "sd_IN", "brx_IN", "kmw_IN"], | ||
JM: ["en_JM"], | ||
KE: ["en_KE", "sw_KE"], | ||
KG: ["ky_KG", "uz_KG", "ru_KG"], | ||
KH: ["km_KH"], | ||
KY: ["en_KY"], | ||
KZ: ["kk_KZ", "ru_KZ"], | ||
LA: ["lo_LA"], | ||
LK: ["si_LK", "ta_LK"], | ||
LR: ["en_LR"], | ||
LS: ["st_LS", "en_LS"], | ||
MA: ["ar_MA", "tzm_MA", "shi_MA", "zgh_MA", "fr_MA"], | ||
MD: ["ro_MD", "ru_MD", "uk_MD", "bg_MD"], | ||
MK: ["mk_MK", "sq_MK", "rmm_MK", "sr_MK", "bg_MK", "cu_MK"], | ||
MM: ["my_MM"], | ||
MN: ["mn_MN"], | ||
MO: ["zh_MO", "pt_MO"], | ||
MU: ["mfe_MU", "fr_MU", "en_MU"], | ||
MV: ["dv_MV"], | ||
MW: ["ny_MW", "yao_MW", "tum_MW", "swk_MW"], | ||
MX: ["es_MX"], | ||
MY: ["ms_MY", "zh_MY", "ta_MY"], | ||
NA: ["en_NA", "af_NA"], | ||
NG: ["en_NG", "ha_NG", "yo_NG", "ig_NG", "ff_NG"], | ||
NI: ["es_NI"], | ||
NO: ["nb_NO", "nn_NO", "se_NO", "sma_NO", "smj_NO", "smn_NO", "sms_NO"], | ||
NP: ["ne_NP"], | ||
NZ: ["en_NZ", "mi_NZ"], | ||
PE: ["es_PE", "qu_PE", "ay_PE"], | ||
PG: ["tpi_PG", "ho_PG", "meu_PG", "tpi_PG"], | ||
PH: ["fil_PH", "tl_PH", "en_PH"], | ||
PK: ["ur_PK", "en_PK", "pa_PK", "sd_PK", "ps_PK", "brh_PK"], | ||
QA: ["ar_QA", "en_QA"], | ||
RU: ["ru_RU", "tt_RU", "ba_RU", "myv_RU", "sah_RU"], | ||
SA: ["ar_SA"], | ||
SC: ["fr_SC", "en_SC"], | ||
SE: ["sv_SE", "se_SE", "sma_SE", "smj_SE"], | ||
SG: ["en_SG", "zh_SG", "ms_SG", "ta_SG"], | ||
SL: ["en_SL"], | ||
SO: ["so_SO"], | ||
SS: ["en_SS"], | ||
SV: ["es_SV"], | ||
SZ: ["en_SZ", "ss_SZ"], | ||
TH: ["th_TH"], | ||
TT: ["en_TT"], | ||
TZ: ["sw_TZ", "en_TZ"], | ||
US: ["en_US", "es_US", "haw_US"], | ||
UY: ["es_UY"], | ||
UZ: ["uz_UZ", "ru_UZ", "tg_UZ"], | ||
YE: ["ar_YE"], | ||
ZA: ["zu_ZA", "xh_ZA", "af_ZA", "nso_ZA", "en_ZA", "tn_ZA", "st_ZA", "ts_ZA", "ss_ZA", "ve_ZA", "nr_ZA"], | ||
KW: ["ar_KW"], | ||
BH: ["ar_BH"], | ||
OM: ["ar_OM"] | ||
} as const; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// A map of countries to their default locale. | ||
export const COUNTRY_TO_DEFAULT_LOCALES = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to have another config, utilise |
||
AE: 'ar-AE', | ||
AL: 'sq-AL', | ||
AM: 'hy-AM', | ||
AR: 'es-AR', | ||
AU: 'en-AU', | ||
AW: 'nl-AW', | ||
BB: 'en-BB', | ||
BD: 'bn-BD', | ||
BM: 'en-BM', | ||
BN: 'ms-BN', | ||
BO: 'es-BO', | ||
BS: 'en-BS', | ||
BW: 'en-BW', | ||
BZ: 'en-BZ', | ||
CA: 'en-CA', | ||
CH: 'de-CH', | ||
CN: 'zh-CN', | ||
CO: 'es-CO', | ||
CR: 'es-CR', | ||
CU: 'es-CU', | ||
CZ: 'cs-CZ', | ||
DK: 'da-DK', | ||
DO: 'es-DO', | ||
DZ: 'ar-DZ', | ||
EG: 'ar-EG', | ||
ET: 'am-ET', | ||
EU: 'en-EU', | ||
FJ: 'en-FJ', | ||
GB: 'en-GB', | ||
GH: 'en-GH', | ||
GI: 'en-GI', | ||
GM: 'en-GM', | ||
GT: 'es-GT', | ||
GY: 'en-GY', | ||
HK: 'en-HK', | ||
HN: 'es-HN', | ||
HR: 'hr-HR', | ||
HT: 'ht-HT', | ||
HU: 'hu-HU', | ||
ID: 'id-ID', | ||
IL: 'he-IL', | ||
IN: 'en-IN', | ||
JM: 'en-JM', | ||
KE: 'en-KE', | ||
KG: 'ky-KG', | ||
KH: 'km-KH', | ||
KY: 'en-KY', | ||
KZ: 'kk-KZ', | ||
LA: 'lo-LA', | ||
LK: 'si-LK', | ||
LR: 'en-LR', | ||
LS: 'en-LS', | ||
MA: 'ar-MA', | ||
MD: 'ro-MD', | ||
MK: 'mk-MK', | ||
MM: 'my-MM', | ||
MN: 'mn-MN', | ||
MO: 'zh-MO', | ||
MU: 'en-MU', | ||
MV: 'dv-MV', | ||
MW: 'en-MW', | ||
MX: 'es-MX', | ||
MY: 'ms-MY', | ||
NA: 'en-NA', | ||
NG: 'en-NG', | ||
NI: 'es-NI', | ||
NO: 'no-NO', | ||
NP: 'ne-NP', | ||
NZ: 'en-NZ', | ||
PE: 'es-PE', | ||
PG: 'en-PG', | ||
PH: 'en-PH', | ||
PK: 'en-PK', | ||
QA: 'ar-QA', | ||
RU: 'ru-RU', | ||
SA: 'ar-SA', | ||
SC: 'en-SC', | ||
SE: 'sv-SE', | ||
SG: 'en-SG', | ||
SL: 'en-SL', | ||
SO: 'so-SO', | ||
SS: 'en-SS', | ||
SV: 'es-SV', | ||
SZ: 'en-SZ', | ||
TH: 'th-TH', | ||
TT: 'en-TT', | ||
TZ: 'sw-TZ', | ||
US: 'en-US', | ||
UY: 'es-UY', | ||
UZ: 'uz-UZ', | ||
YE: 'ar-YE', | ||
ZA: 'en-ZA', | ||
KW: 'ar-KW', | ||
BH: 'ar-BH', | ||
OM: 'ar-OM' | ||
} as const; |
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.
This will be minor.