App icon indicating copy to clipboard operation
App copied to clipboard

Implement library to convert a phone number into a locally formatted phone number

Open Jag96 opened this issue 5 years ago • 4 comments

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:

  1. toLocalPhone(locale, number) which will get the localizationConfig.phoneCountryCode key from the translations, and if it matches the beginning of the number passed, it will remove it and return the rest
  2. fromLocalPhone(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

Jag96 avatar Mar 25 '21 20:03 Jag96

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.

ahmedahtazaz avatar Mar 25 '21 20:03 ahmedahtazaz

Hi,

I would love to work on this issue! My proposal is to do the following:

  1. Expose toLocalPhone(locale, number) method: The method will get localizationConfig.phoneCountryCode from the translations, and if the countryCode matches 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 get phoneCountryCode from the localizationConfig.phoneCountryCode, and if the countryCode matches the beginning of the number passed ‘+34910604859’, it will remove it from the number +34 and return 910604859. 



  2. 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 get phoneCountryCode from the localizationConfig.phoneCountryCode, and add it to the beginning of the number if it’s already not there.

    Hence, add +34 to the beginning of given 910604859 and return +34910604859.

    As such, we need to add localizationConfig.phoneCountryCode to the en-EN and es-ES translation 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.

Regaron avatar Mar 25 '21 21:03 Regaron

@ahmedahtazaz I've sent an offer in Upwork and assigned you the issue so you can begin working on it!

Jag96 avatar Mar 25 '21 21:03 Jag96

@Jag96 I have accepted your offer. Thanks a lot for assigning this issue to me.

ahmedahtazaz avatar Mar 25 '21 21:03 ahmedahtazaz