Implement library to convert a phone number into a locally formatted phone number
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Upwork Posting: https://www.upwork.com/jobs/~0129906b4c8ea7c94b
We are implementing the structure for internationalization and localization.
As part of that, we need to implement a library (a single new file) to convert a phone number into a locally formatted phone number. You can check this PR that added this file which is related to this project.
This new library will expose 2 methods:
toLocalPhone(locale, number)which will get thelocalizationConfig.phoneCountryCodekey from the translations, and if it matches the beginning of the number passed, it will remove it and return the restfromLocalPhone(locale, number)which will add the country code to the beginning of the number (if it is not there already)
You will need to add localizationConfig.phoneCountryCode to the en-EN and es-ES translation files. It should be a string without the + (so it would be "1" for en-EN and "34" for es-ES).
Please include JUnit tests for the added methods.
Expensify/Expensify Issue URL: https://github.com/Expensify/Expensify/issues/152151
I will create a single file library for your app. It will expose 2 methods. toLocalPhone and fromLocalPhone. The implementation will be according to the guidelines given above. These methods will get locale and number as arguments and will remove or add the country code depending upon the locale.
Hi,
I would love to work on this issue! My proposal is to do the following:
-
Expose
toLocalPhone(locale, number)method: The method will getlocalizationConfig.phoneCountryCodefrom the translations, and if thecountryCodematches the beginning of the number passed, the method will remove it from the number and return the rest.So, for example, for
toLocalPhone(‘es-Es’, ‘+34910604859’), the method will getphoneCountryCodefrom thelocalizationConfig.phoneCountryCode, and if thecountryCodematches the beginning of the number passed‘+34910604859’,it will remove it from the number+34and return910604859. -
Expose
fromLocalePhone(locale, number): The method will add the country code to the beginning of the number if it is not already there:So, for example, for
fromLocalPhone(‘es-Es’, ‘910604859’), the method will getphoneCountryCodefrom thelocalizationConfig.phoneCountryCode, and add it to the beginning of the number if it’s already not there.Hence, add
+34to the beginning of given910604859and return+34910604859.As such, we need to add
localizationConfig.phoneCountryCodeto theen-ENandes-EStranslation files, which should be a string, meaning:“1”for en-EN and“34”for es-ES.For example: I'd add the following to languages/es-ES.js:
localizationConfig: { phoneCountryCode: '34' }I will add JSUnit tests to test the above two methods.
@ahmedahtazaz I've sent an offer in Upwork and assigned you the issue so you can begin working on it!
@Jag96 I have accepted your offer. Thanks a lot for assigning this issue to me.