Skip to content
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

Upgrade i18n version #22550

Merged
merged 3 commits into from
Jul 24, 2023
Merged

Upgrade i18n version #22550

merged 3 commits into from
Jul 24, 2023

Conversation

kbrock
Copy link
Member

@kbrock kbrock commented Jun 6, 2023

Overview

i18n version 1.14 broke our build.

Temporary Solution

We had pegged i18n to version 1.13

Permanent Solution (this PR)

This reverts commit 6e11232, reversing changes made to b4c7593.

We then added the 3 following fixes to resolve issues of i18n v 1.14

  • i18n 1.14 introduced an issue around empty default values, 1.14.1 fixed this issue.
  • i18n 1.14 introduces an issue around frozen strings. rails-i18n 1.11 fixes that
  • i18n 1.14 changes a string returned breaking our string compare. A commit fixes that.

For that last one, we had 2 options:

  • peg i18n to >=1.14 and have a single string comparison.
  • Handle both string comparisons

We chose to handle both string comparisons. (thank you Jason for making sure we got the best performing code)

@kbrock kbrock requested a review from Fryguy as a code owner June 6, 2023 13:24
@kbrock kbrock changed the title Revert "Merge pull request #22545 from kbrock/peg_i18n" [WIP] Revert "Merge pull request #22545 from kbrock/peg_i18n" Jun 6, 2023
@kbrock kbrock added wip and removed petrosian/yes? labels Jun 6, 2023
@kbrock
Copy link
Member Author

kbrock commented Jun 6, 2023

ok, I thought someone already merged ruby-i18n/i18n#658 but it isn't even a PR yet.

Lets hold off on this one until that is fixed

Maybe we need to ensure we are using grosser/gettext_i18n_rails#196

@kbrock kbrock requested a review from agrare as a code owner June 13, 2023 00:04
@kbrock kbrock changed the title [WIP] Revert "Merge pull request #22545 from kbrock/peg_i18n" Revert "Merge pull request #22545 from kbrock/peg_i18n" Jun 13, 2023
@kbrock kbrock removed the wip label Jun 13, 2023
@kbrock
Copy link
Member Author

kbrock commented Jun 13, 2023

update:

  • minor code change to handle a string change in i18n

@kbrock kbrock force-pushed the unpeg_i18n branch 2 times, most recently from f642102 to 5aa9478 Compare June 13, 2023 00:12
@Fryguy
Copy link
Member

Fryguy commented Jun 16, 2023

I also felt string comparison was possibly quicker than going the regular expression route.

I figured I'd benchmark this:

tl;dr I believe a case-insensitive regex is fastest, even though it's slightly slower in a particular error case.
A case-insenstive regex compared with start_with? is ~44% faster on "normal" strings, which I believe would be the most of the actual cases; it is ~15% faster when the error starts with a lower-case t, but 18% slower when the error starts with an upper-case T; the nil case is identical

def test_start_with?(result)
  result && !result.start_with?("Translation missing:") && !result.start_with?("translation missing:")
end

def test_regex_case_sensitive(result)
  result && !result.match?(/^[Tt]ranslation missing:/)
end

def test_regex_case_insensitive(result)
  result && !result.match?(/Translation missing:/i)
end

CASES = [
  ["translation missing: foo", false],
  ["Translation missing: foo", false],
  [nil, nil],
  ["Other", true],
]

CASES.each do |result, expectation|
  raise "test_start_with? for #{result.inspect} is bad." if test_start_with?(result) != expectation
  raise "test_regex_case_sensitive for #{result.inspect} is bad." if test_regex_case_sensitive(result) != expectation
  raise "test_regex_case_insensitive for #{result.inspect} is bad." if test_regex_case_insensitive(result) != expectation
end

CASES.each do |result, expectation|
  puts "==================="
  puts "Testing #{result.inspect}..."
  puts

  Benchmark.ips do |x|
    x.report("start_with?") {
      test_start_with?(result)
    }

    x.report("regex case sensitive") {
      test_regex_case_sensitive(result)
    }

    x.report("regex case insensitive") {
      test_regex_case_insensitive(result)
    }
  end
end
===================
Testing "translation missing: foo"...

Warming up --------------------------------------
         start_with?   680.626k i/100ms
regex case sensitive   777.370k i/100ms
regex case insensitive
                       490.301k i/100ms
Calculating -------------------------------------
         start_with?      6.852M (± 0.7%) i/s -     34.712M in   5.066333s
regex case sensitive      7.796M (± 0.5%) i/s -     39.646M in   5.085398s
regex case insensitive
                          4.899M (± 0.4%) i/s -     24.515M in   5.004260s
===================
Testing "Translation missing: foo"...

Warming up --------------------------------------
         start_with?   928.360k i/100ms
regex case sensitive   765.993k i/100ms
regex case insensitive
                       491.627k i/100ms
Calculating -------------------------------------
         start_with?      9.312M (± 0.6%) i/s -     47.346M in   5.084781s
regex case sensitive      7.658M (± 1.1%) i/s -     38.300M in   5.002230s
regex case insensitive
                          4.889M (± 1.0%) i/s -     24.581M in   5.028671s
===================
Testing nil...

Warming up --------------------------------------
         start_with?     1.628M i/100ms
regex case sensitive     1.567M i/100ms
regex case insensitive
                         1.630M i/100ms
Calculating -------------------------------------
         start_with?     16.324M (± 0.5%) i/s -     83.006M in   5.085165s
regex case sensitive     16.332M (± 0.7%) i/s -     83.072M in   5.086727s
regex case insensitive
                         16.341M (± 0.6%) i/s -     83.121M in   5.086663s
===================
Testing "Other"...

Warming up --------------------------------------
         start_with?   718.943k i/100ms
regex case sensitive     1.036M i/100ms
regex case insensitive
                         1.050M i/100ms
Calculating -------------------------------------
         start_with?      7.159M (± 0.7%) i/s -     35.947M in   5.021308s
regex case sensitive     10.348M (± 0.4%) i/s -     51.794M in   5.005429s
regex case insensitive
                         10.465M (± 0.4%) i/s -     52.481M in   5.014804s

@Fryguy
Copy link
Member

Fryguy commented Jun 16, 2023

BTW, I don't strongly care one way or another and won't hold up merge for that - just let me know what you'd prefer

@Fryguy Fryguy self-assigned this Jun 16, 2023
missing translation: changed to Missing translation in the source
Changed our dictionary to handle this case

Support missing translations for i18n 1.14

i18n gem used to return "missing translation:"
As of 1.14, it returns "Missing translation:"

Changed our dictionary to handle this case
@kbrock
Copy link
Member Author

kbrock commented Jun 20, 2023

update:

  • changed to regular expression.

Thnx for challenging me on this one

@miq-bot
Copy link
Member

miq-bot commented Jun 20, 2023

Checked commits kbrock/manageiq@b4c7969~...1dc4bd9 with ruby 2.6.10, rubocop 1.28.2, haml-lint 0.35.0, and yamllint
2 files checked, 0 offenses detected
Everything looks fine. 🍰

@kbrock kbrock changed the title Revert "Merge pull request #22545 from kbrock/peg_i18n" Upgrade i18n version Jul 17, 2023
@Fryguy Fryguy merged commit 02ac620 into ManageIQ:master Jul 24, 2023
9 checks passed
@kbrock kbrock deleted the unpeg_i18n branch July 25, 2023 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants