Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Find translation results with case-insensitive comparison #45

Merged
merged 1 commit into from
Jan 12, 2021

Conversation

amake
Copy link
Contributor

@amake amake commented Jan 12, 2021

Microsoft claims e.g. at https://api.cognitive.microsofttranslator.com/languages?api-version=3.0 to support two language codes with regions: fr-ca and pt-pt

However in the actual response these are normalized to fr-CA and pt-PT (which is correct per BCP 47 recommendations).

With the way this gem currently extracts the translated payload, translations to fr-ca and pt-pt always result in nil. This PR fixes this by performing a case-insensitive comparison.

Note that I have used casecmp.zero? instead of casecmp? because the latter is apparently slower (see rubocop/rubocop-performance#100).

@amake
Copy link
Contributor Author

amake commented Jan 12, 2021

I'm not sure what to do about the test failures since they all appear to be problems with the credentials, which I can't control.

The tests pass for me locally when I supply my credentials.

@amake
Copy link
Contributor Author

amake commented Jan 12, 2021

↑ Sorry, my colleague reviewed thinking this PR was to one of our own repos.

@relrod relrod merged commit d978ef7 into relrod:master Jan 12, 2021
@relrod
Copy link
Owner

relrod commented Jan 12, 2021

Thanks for the patch!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants