Skip to content

Commit

Permalink
Improve i18n newlines test output
Browse files Browse the repository at this point in the history
Followup to: ManageIQ#23213

We found the overall number of newlines test failures between English strings
and their translations was printed to the screen but not failing the tests.

This was ignored.  It was decided in the above PR that this test was valid
and should fail the tests on failure.

I also changed the output to be a bit more readable.

Before:

```
Randomized with seed 49148
The following translation entries do not honor overall number of newlines:
>> File: /Users/joerafaniello/Code/manageiq/locale/es/manageiq.po
----------
»VMs must be scanned from an EVM server whose host is attached to the same
  storage as the VM unless overridden via SmartProxy affinity.
  Please verify that:
  1) Direct LUNs are attached to ManageIQ appliance
  2) Management Relationship is set for the ManageIQ appliance«
»Se deben analizar las MV desde un servidor EVM cuyo host esté conectado al mismo almacenamiento que la MV, a menos que se anule mediante afinidad con SmartProxy.
  Compruebe que:
  1) Los LUN directos estén conectados a un dispositivo ManageIQ
  2) La relación de gestión esté configurada para el dispositivo ManageIQ«
----------

>> File: /Users/joerafaniello/Code/manageiq/locale/it/manageiq.po
----------
»VMs must be scanned from an EVM server whose host is attached to the same
  storage as the VM unless overridden via SmartProxy affinity.
  Please verify that:
  1) Direct LUNs are attached to ManageIQ appliance
  2) Management Relationship is set for the ManageIQ appliance«
»Le VM devono essere scansate da un server EVM il cui host è collegato alla stessa memoria della VM a meno che non sovrascrivi tramite affinità SmartProxy.
  Si prega di verificare che: 1) I LUN diretti siano collegati al dispositivo ManageIQ 2) La Relazione di gestione sia impostata per il dispositivo ManageIQ«
----------

  2) 为 ManageIQ 设备设置了管理关系«
----------

...

>> File: /Users/joerafaniello/Code/manageiq/locale/zh_TW/manageiq.po
----------
»Provision failed for the following reasons:
%{errors}«
»供應失敗,原因如下:%{errors}«
----------
»VMs must be scanned from an EVM server whose host is attached to the same
  storage as the VM unless overridden via SmartProxy affinity.
  Please verify that:
  1) Direct LUNs are attached to ManageIQ appliance
  2) Management Relationship is set for the ManageIQ appliance«
»除非透過 SmartProxy 親緣性置換,否則必須從其主機連接至與 VM 相同的儲存體的 EVM 伺服器中掃描 VM。
  請驗證:  1) 直接 LUN 已連接至 ManageIQ 應用裝置  2) 已為 ManageIQ 應用裝置設定管理關係«
----------

.

Finished in 2.9 seconds (files took 2.97 seconds to load)
1 example, 0 failures
```

After:

```
  1) newlines translations honor newlines
     Failure/Error: expect(err).to be_empty, "Rule: #{rule} was violated in:\n #{err_msg}"

       Rule: equal number of overall newlines was violated in:
        File: /Users/joerafaniello/Code/manageiq/locale/es/manageiq.po
         English:
           "»VMs must be scanned from an EVM server whose host is attached to the same\n  storage as the VM unless overridden via SmartProxy affinity.\n  Please verify that:\n  1) Direct LUNs are attached to ManageIQ appliance\n  2) Management Relationship is set for the ManageIQ appliance«"
         Translation:
           "»Se deben analizar las MV desde un servidor EVM cuyo host esté conectado al mismo almacenamiento que la MV, a menos que se anule mediante afinidad con SmartProxy.\n  Compruebe que:\n  1) Los LUN directos estén conectados a un dispositivo ManageIQ\n  2) La relación de gestión esté configurada para el dispositivo ManageIQ«"
       File: /Users/joerafaniello/Code/manageiq/locale/it/manageiq.po
         English:
           "»VMs must be scanned from an EVM server whose host is attached to the same\n  storage as the VM unless overridden via SmartProxy affinity.\n  Please verify that:\n  1) Direct LUNs are attached to ManageIQ appliance\n  2) Management Relationship is set for the ManageIQ appliance«"
         Translation:
           "»Le VM devono essere scansate da un server EVM il cui host è collegato alla stessa memoria della VM a meno che non sovrascrivi tramite affinità SmartProxy.\n  Si prega di verificare che: 1) I LUN diretti siano collegati al dispositivo ManageIQ 2) La Relazione di gestione sia impostata per il dispositivo ManageIQ«"
       File: /Users/joerafaniello/Code/manageiq/locale/pt_BR/manageiq.po
         English:
           "»Enables defining a URL path prefix for XCCDF file instead of accessing the default location.\n  example: http://my_file_server.org:3333/xccdf_files/\n  Expecting to find com.redhat.rhsa-RHEL7.ds.xml.bz2 file there.«"
         Translation:
           "»Permite definir um prefixo de caminho de URL para o arquivo XCCDF em vez de acessar o local padrão.\n  Por exemplo: http://my_file_server.org: 3333/xccdf_files/ Esperando encontrar o arquivo com.redhat.rhsa-RHEL7.ds.xml.bz2 lá.«"
         English:
           "»Enables defining a URL path prefix for XCCDF file instead of accessing the default location.\nexample: http://my_file_server.org:3333/xccdf_files/\nExpecting to find com.redhat.rhsa-RHEL7.ds.xml.bz2 file there.«"
         Translation:
           "»Permite definir um prefixo de caminho de URL para o arquivo XCCDF em vez de acessar o local padrão.\nPor exemplo: http://my_file_server.org: 3333/xccdf_files/ Esperando encontrar o arquivo com.redhat.rhsa-RHEL7.ds.xml.bz2 lá.«"
         English:
           "»Provision failed for the following reasons:\n%{errors}«"
         Translation:
           "»A provisão falhou pelos seguintes motivos: %{errors}«"
         English:
           "»VMs must be scanned from an EVM server whose host is attached to the same\n  storage as the VM unless overridden via SmartProxy affinity.\n  Please verify that:\n  1) Direct LUNs are attached to ManageIQ appliance\n  2) Management Relationship is set for the ManageIQ appliance«"
         Translation:
           "»As VMs devem ser escaneadas a partir de um servidor EVM cujo host esteja conectado ao mesmo armazenamento que a VM, a menos que seja substituído por meio da afinidade do SmartProxy.\n  Verifique se: 1) LUNs diretas estão conectadas ao dispositivo ManageIQ\n2) O relacionamento de gerenciamento está configurado para o dispositivo ManageIQ«"
       File: /Users/joerafaniello/Code/manageiq/locale/zh_CN/manageiq.po
         English:
           "»Enables defining a URL path prefix for XCCDF file instead of accessing the default location.\n  example: http://my_file_server.org:3333/xccdf_files/\n  Expecting to find com.redhat.rhsa-RHEL7.ds.xml.bz2 file there.«"
         Translation:
           "»允许为 XCCDF 文件定义 URL 路径前缀,而不是访问缺省位置。示例:http://my_file_server.org:3333/xccdf_files/\n  应该可在那里找到 com.redhat.rhsa-RHEL7.ds.xml.bz2 文件。«"
         English:
           "»Enables defining a URL path prefix for XCCDF file instead of accessing the default location.\nexample: http://my_file_server.org:3333/xccdf_files/\nExpecting to find com.redhat.rhsa-RHEL7.ds.xml.bz2 file there.«"
         Translation:
           "»允许为 XCCDF 文件定义 URL 路径前缀,而不是访问缺省位置。示例:http://my_file_server.org:3333/xccdf_files/\n  应该可在那里找到 com.redhat.rhsa-RHEL7.ds.xml.bz2 文件。«"
         English:
           "»Provision failed for the following reasons:\n%{errors}«"
         Translation:
           "»由于以下原因,供应失败:%{errors}«"
         English:
           "»VMs must be scanned from an EVM server whose host is attached to the same\n  storage as the VM unless overridden via SmartProxy affinity.\n  Please verify that:\n  1) Direct LUNs are attached to ManageIQ appliance\n  2) Management Relationship is set for the ManageIQ appliance«"
         Translation:
           "»虚拟机必须从 EVM 服务器扫描,它的主机附加到和虚拟机相同的存储器上,除非通过 SmartProxy 关联覆盖。\n  请验证:\n  1) 直接 LUN 附加到 ManageIQ 设备\n  2) 为 ManageIQ 设备设置了管理关系«"
       File: /Users/joerafaniello/Code/manageiq/locale/zh_TW/manageiq.po
         English:
           "»Datastore import was successful.\nNamespaces updated/added: %{namespace_stats}\nClasses updated/added: %{class_stats}\nInstances updated/added: %{instance_stats}\nMethods updated/added: %{method_stats}«"
         Translation:
           "»成功匯入資料儲存庫。已更新/已新增名稱空間:%{namespace_stats}\n已更新/已新增類別:%{class_stats}\n已更新/已新增實例:%{instance_stats}\n已更新/已新增方法:%{method_stats}«"
         English:
           "»Enables defining a URL path prefix for XCCDF file instead of accessing the default location.\n  example: http://my_file_server.org:3333/xccdf_files/\n  Expecting to find com.redhat.rhsa-RHEL7.ds.xml.bz2 file there.«"
         Translation:
           "»啟用為 XCCDF 檔案定義 URL 路徑字首而非存取預設位置的功能。例如:http://my_file_server.org:3333/xccdf_files/,期望在這裡能夠找到 com.redhat.rhsa-RHEL7.ds.xml.bz2 檔。«"
         English:
           "»Enables defining a URL path prefix for XCCDF file instead of accessing the default location.\nexample: http://my_file_server.org:3333/xccdf_files/\nExpecting to find com.redhat.rhsa-RHEL7.ds.xml.bz2 file there.«"
         Translation:
           "»啟用為 XCCDF 檔案定義 URL 路徑字首而非存取預設位置的功能。例如:http://my_file_server.org:3333/xccdf_files/,期望在這裡能夠找到 com.redhat.rhsa-RHEL7.ds.xml.bz2 檔。«"
         English:
           "»Provision failed for the following reasons:\n%{errors}«"
         Translation:
           "»供應失敗,原因如下:%{errors}«"
         English:
           "»VMs must be scanned from an EVM server whose host is attached to the same\n  storage as the VM unless overridden via SmartProxy affinity.\n  Please verify that:\n  1) Direct LUNs are attached to ManageIQ appliance\n  2) Management Relationship is set for the ManageIQ appliance«"
         Translation:
           "»除非透過 SmartProxy 親緣性置換,否則必須從其主機連接至與 VM 相同的儲存體的 EVM 伺服器中掃描 VM。\n  請驗證:  1) 直接 LUN 已連接至 ManageIQ 應用裝置  2) 已為 ManageIQ 應用裝置設定管理關係«"
     Shared Example Group: :newlines called from ./spec/i18n/newlines_spec.rb:2
     # ./spec/shared/i18n/newlines.rb:51:in `block (3 levels) in <main>'
     # ./spec/shared/i18n/newlines.rb:40:in `each'
     # ./spec/shared/i18n/newlines.rb:40:in `block (2 levels) in <main>'
     # /Users/joerafaniello/.gem/ruby/3.1.5/gems/webmock-3.24.0/lib/webmock/rspec.rb:39:in `block (2 levels) in <main>'

Finished in 3.01 seconds (files took 2.75 seconds to load)
1 example, 1 failure
```
  • Loading branch information
jrafanie committed Oct 1, 2024
1 parent 2c6cd3c commit 4b0f2d4
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions spec/shared/i18n/newlines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ def add_string_chevrons(input)

shared_examples :newlines do |dir|
it "translations honor newlines" do
boundary_errors = {}
string_ends = {}
string_starts = {}
overall_errors = {}

Pathname.glob(File.join(dir, "**", "*.po")).each do |po_file|
Expand All @@ -17,12 +18,12 @@ def add_string_chevrons(input)

# Check newlines at string ends
if (translation[-1] == "\n" && original[-1] != "\n") || (translation[-1] != "\n" && original[-1] == "\n")
boundary_errors.store_path(po_file.to_s, add_string_chevrons(original), add_string_chevrons(translation))
string_ends.store_path(po_file.to_s, add_string_chevrons(original), add_string_chevrons(translation))
end

# Check newlines at string starts
if (translation[0] == "\n" && original[0] != "\n") || (translation[0] != "\n" && original[0] == "\n")
boundary_errors.store_path(po_file.to_s, add_string_chevrons(original), add_string_chevrons(translation))
string_starts.store_path(po_file.to_s, add_string_chevrons(original), add_string_chevrons(translation))
end

# Check that overall amount of newlines in original and translation matches
Expand All @@ -32,21 +33,22 @@ def add_string_chevrons(input)
end
end

[['newlines at string boundaries', boundary_errors], ['overall number of newlines', overall_errors]].each do |rule, err|
[
['no newlines at string ends', string_ends],
['no newlines at string start', string_starts],
['equal number of overall newlines', overall_errors]
].each do |rule, err|
next if err.empty?

puts "The following translation entries do not honor #{rule}:"
err_msg = ""
err.each do |file, file_errors|
puts ">> File: #{file}\n", "----------"
err_msg << "File: #{file}\n"
file_errors.each do |original, translation|
puts original, translation, "----------"
err_msg << " English:\n #{original.inspect}\n"
err_msg << " Translation:\n #{translation.inspect}\n"
end
puts
end
expect(err).to be_empty, "Rule: #{rule} was violated in:\n #{err_msg}"
end

expect(boundary_errors).to be_empty
# We intentionaly do not expect overall_errors to be empty, since in certain cases it may be desirable
# for newlines in translated string not to match its original. We'll still be logging the mismatches above.
end
end

0 comments on commit 4b0f2d4

Please sign in to comment.