Conversation
| def country_alpha3_by_alpha2(alpha2) do | ||
| alpha2 = String.upcase(alpha2) | ||
|
|
||
| case Enum.find(@country_codes, &(get_alpha2(&1) == alpha2)) do | ||
| nil -> nil | ||
| info = %{} -> Map.get(info, :alpha3) | ||
| end | ||
| end | ||
|
|
There was a problem hiding this comment.
@Flo0807 I had saved alpha2 for languages and thought it's useful to find country alpha3 version from the library to use later for rendering flags. However may be it's not a best place for it and is project related. Idk, it's a helper function.
There was a problem hiding this comment.
@Flo0807 I had language code in 2 char formats and wanted quickly find what alpha3 representation is supported by Flagpack and call rendering if it's not nil. Idk, it could be app related code though I've added it to the helper.
There was a problem hiding this comment.
I would like to switch to alpha-2 codes for rendering flags in a future version of this package (see #35). How about adding a Flagpack.Helpers.get_country_codes function that returns the list of structs containing alpha-2, alpha-3, country_name and numeric information?
def get_country_codes, do: @country_codesThen you can implement the above filtering in your application, and we do not have a function mainly cut to your application.
There was a problem hiding this comment.
@Flo0807 it sounds reasonable. what do you mean by numeric information?
There was a problem hiding this comment.
See the Flag Index or the list of country_codes in the Helper module.
In addition to the name, alpha2 and alpha3, every flag also has a unique numeric code.
Helpers.country_alpha3_by_alpha2/1