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

world country data #22

Closed
pcarion opened this issue Jul 21, 2016 · 8 comments
Closed

world country data #22

pcarion opened this issue Jul 21, 2016 · 8 comments

Comments

@pcarion
Copy link
Contributor

pcarion commented Jul 21, 2016

Let me expose here a concern I have with the memory usage of the CountryPicker component and I am OK to tackle this issue and submit a PR if you think it is a valid concern.

Currently, you load the countries.json file from the world_country npm module, to get extra data from the selected country.

This file is big (444K) and it may be a waste of space considering that very few piece of information is needed from the file:

  • the cca2 code
  • the translation for the different names of the countries -to allow i18n of the country list (nice feature by the way)
  • the phone calling code (that's actually what I need in my app)
  • the name of the country
  • the currency

You already have a configuration file of yours (countryFlags.js) to store the image of the flags.

My suggestion would be to parse (offline) the countries.json and generate a local countryInfo.js file, that would be stored in your repo (with proper attribution to the author of world_country) with only the information needed in the context of your app.

This would require a few changes in the code (such as orderCountryList and getCountry) but nothing major and the footprint of the component in memory would be much smaller...

@sprmn
Copy link
Contributor

sprmn commented Jul 21, 2016

I agree, the country data file is huge and a local copy of the file containing only the necessary data would be a big improvement. Maybe we could add some functionality to provide your own data as well. Not everyone needs the currency or all translations for example. Some might not even need all countries (Antartica for example doesn't even have a calling code if I'm not mistaken).

@pcarion
Copy link
Contributor Author

pcarion commented Jul 22, 2016

I started to work on such a converter... I am generating a file like this:

'use strict';
module.exports = {
  "AD": {
    "flagImage": "data:image/png;base64,iVBORw <from countries.json> Jggg==",
    "currency": "EUR",
    "callingCode": "376",
    "name": {
      "cym": "Andorra",
      "deu": "Andorra",
      "fra": "Andorre",
      "hrv": "Andora",
      "ita": "Andorra",
      "jpn": "アンドラ",
      "nld": "Andorra",
      "por": "Andorra",
      "rus": "Андорра",
      "spa": "Andorra",
      "fin": "Andorra"
    }
  },

Trying to see how I could escape the names to be more robust.

I also think that a country code of 2 characters instead of 3 for the translations would be more useful...

@arthurvi
Copy link
Collaborator

Good point. Speed and efficiency is very important for a basic component like a country picker. I think we should default include the bare minimum but make extra features possible.
Can we use the unicode flags instead of the large base64 encoded images?

+1 for a 2 char country code for translation.

@sprmn
Copy link
Contributor

sprmn commented Jul 27, 2016

Unicode flags would be a nice improvement. However, on Android, unicode flags are only supported since Lollipop. Half of the Android users still use older versions, hence I don't think unicode flags are a solid solution at the moment.

@arthurvi
Copy link
Collaborator

arthurvi commented Jul 31, 2016

Ah ok, but we can then use Platform.version to discover this and include base64 strings as legacy option?

@xcarpentier
Copy link
Owner

Hello @pcarion, thank you and I agree !
Do you have a js script file to make the new countries.js file ?
If so, could you make a PR with your script ?

@xcarpentier
Copy link
Owner

See my PR #29 :)

@xcarpentier
Copy link
Owner

Improve here #29

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

No branches or pull requests

4 participants