Skip to content

falls back to english if country not translated - #30

Open
dbaq wants to merge 1 commit into
cainlevy:masterfrom
dbaq:fix_localization_fallback
Open

dbaq wants to merge 1 commit into
cainlevy:masterfrom
dbaq:fix_localization_fallback

Conversation

@dbaq

@dbaq dbaq commented Jun 20, 2016 •

Copy link
Copy Markdown
Contributor

hi @cainlevy,

In some rare cases, the translation might not be present (thinking about AF for instance). The fallback code to english was broken due to the match function. Also, if a country is not a valid
iso code, we should display the raw value.

In some rare cases, the translation might not be present. The fallback
code to english was broken due to the `match`. Also, if a country is not a valid
iso code, we should display the raw value.
@cainlevy

Copy link
Copy Markdown
Owner

Hi @dbaq! Apologies for the delay. I've been away for a bit.

Thanks for catching the bug in translated_country!

I'm unsure what to do with invalid country ISO codes though. I have two concerns:

  1. This is a backwards incompatible change. It changes the meaning of the country attribute.
  2. If Snail is provided an unknown country code, can it do its job? It won't be able to translate or provide correct formatting.

I have empathy for anyone relying on country name data (we did at one point as well) but I'm not convinced that Snail should support it. If the country names are provided by users, the system has no consistency or accuracy. If the names are enumerated, then the system should map them back to ISO codes for processing.

Thoughts? I can be persuaded.

@dbaq

dbaq commented Nov 18, 2016

Copy link
Copy Markdown
Contributor Author

hey @cainlevy, just went through my open PR and found this one.

It's been a while but we have this PR in production since then. The bug fix for translated_country is useful.

If Snail is provided an unknown country code, can it do its job? It won't be able to translate or provide correct formatting.

It is correct, it is a pure design choice. Do you prefer throw an error or a graceful degradation? On my side, I always go try to go for graceful degradations.

On our side, why did/do we need it? I migrated 1M addresses from an open country input to a dropdown country list with the iso code as a key. I was able to map 65% of values to an iso code but at the time we still had to support other values. I understand your point of view but I think such a use case could be common and allow to fallback to default formatting and english is decent enough.

Let me know your thoughts.

@cainlevy

Copy link
Copy Markdown
Owner

Okay, I've spent some time thinking about this and concluded that graceful degredation is the way to go because that's how the postal system works, too. Sending snail mail is all about making the best of imperfect data.

@cainlevy cainlevy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll get this merged yet!

Please let me know if you don't expect to get back to this in the next month or so, and I'll finish up. I'd rather you got credit for contributing, but I realize this has been open for some time and you may or may not still be interested.

Comment thread lib/snail.rb
def country=(val)
@country = Snail.lookup_country_iso(val)
@country = val
@country_iso = Snail.lookup_country_iso(val)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd like to make this change more backwards compatible. let's go with @country = Snail.lookup_country_iso(val) || val and drop the @country_iso ivar. this should mean that behavior will only change for unknown countries: anyone with a standardized data will be unaffected, and anyone with mixed data will hopefully see an improvement in formatting.

Comment thread lib/snail.rb
def translated_country(origin, country)
path = File.join(File.dirname(File.expand_path(__FILE__)), "../assets/#{origin}.yml")
File.read(path).match(/^#{country}: (.*)$/)[1]
matches = File.read(path).match(/^#{country}: (.*)$/)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd love to see this bugfix in a separate commit.

@dbaq

dbaq commented Dec 19, 2016

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I'll try to take a look at it soon.

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

Successfully merging this pull request may close these issues.

2 participants