-
Notifications
You must be signed in to change notification settings - Fork 5
small improvements #37
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
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this function?
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.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Flo0807 it sounds reasonable. what do you mean by numeric information?
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.
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