snail
snail copied to clipboard
falls back to english if country not translated
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.
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:
- This is a backwards incompatible change. It changes the meaning of the
country
attribute. - 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.
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.
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.
Thanks for the review. I'll try to take a look at it soon.