mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
parent
b00ca2238e
commit
d61e9a2e47
2 changed files with 25 additions and 32 deletions
25
logstash-core/spec/static/i18n_spec.rb
Normal file
25
logstash-core/spec/static/i18n_spec.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
# encoding: utf-8
|
||||
require "spec_helper"
|
||||
require "i18n"
|
||||
|
||||
I18N_T_REGEX = Regexp.new('I18n.t.+?"(.+?)"')
|
||||
|
||||
describe I18n do
|
||||
context "when using en.yml" do
|
||||
glob_path = File.join(LogStash::Environment::LOGSTASH_HOME, "logstash-*", "lib", "**", "*.rb")
|
||||
|
||||
Dir.glob(glob_path).each do |file_name|
|
||||
|
||||
context "in file \"#{file_name}\"" do
|
||||
File.foreach(file_name) do |line|
|
||||
next unless (match = line.match(I18N_T_REGEX))
|
||||
line = $INPUT_LINE_NUMBER
|
||||
key = match[1]
|
||||
it "in line #{line} the \"#{key}\" key should exist" do
|
||||
expect(I18n.exists?(key)).to be_truthy
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,32 +0,0 @@
|
|||
require 'rubygems'
|
||||
require "bootstrap/environment"
|
||||
|
||||
namespace "test" do
|
||||
namespace "static" do
|
||||
desc "run static analysis tests on i18n calls"
|
||||
task "i18n" do
|
||||
require 'i18n'
|
||||
|
||||
locales_path = File.join(LogStash::Environment::LOGSTASH_HOME, "logstash-core", "locales", "en.yml")
|
||||
I18n.enforce_available_locales = true
|
||||
I18n.load_path << locales_path
|
||||
I18n.reload!
|
||||
|
||||
failed = []
|
||||
|
||||
glob_path = File.join(LogStash::Environment::LOGSTASH_HOME, "logstash-*", "**", "*.rb")
|
||||
Dir.glob(glob_path).each do |file_name|
|
||||
File.foreach(file_name) do |line|
|
||||
match = line.match(/I18n.t\("(.+?)"/)
|
||||
next unless match
|
||||
failed << [file_name, match[1]] unless I18n.exists?(match[1])
|
||||
end
|
||||
end
|
||||
if failed.any?
|
||||
message = ["Static Analysis revealed incorrect calls to I18t! See list below:"]
|
||||
failed.each {|file_name, line_match| message << "* #{file_name}: #{line_match}" }
|
||||
raise Exception.new(message.join("\n"))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue