2013-02-05 14:16:51 -05:00
|
|
|
require 'spec_helper'
|
2015-09-18 15:12:37 -04:00
|
|
|
require 'locale_file_walker'
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
describe "i18n integrity checks" do
|
|
|
|
|
|
|
|
it 'should have an i18n key for all trust levels' do
|
|
|
|
TrustLevel.all.each do |ts|
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(ts.name).not_to match(/translation missing/)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "needs an i18n key (description) for each Site Setting" do
|
|
|
|
SiteSetting.all_settings.each do |s|
|
|
|
|
next if s[:setting] =~ /^test/
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(s[:description]).not_to match(/translation missing/)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "needs an i18n key (notification_types) for each Notification type" do
|
2015-04-18 07:53:53 -04:00
|
|
|
Notification.types.each_key do |type|
|
2015-06-15 02:34:35 -04:00
|
|
|
next if type == :custom
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(I18n.t("notification_types.#{type}")).not_to match(/translation missing/)
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-23 10:49:31 -04:00
|
|
|
it "has valid YAML for client" do
|
|
|
|
Dir["#{Rails.root}/config/locales/client.*.yml"].each do |f|
|
2013-03-23 03:57:31 -04:00
|
|
|
locale = /.*\.([^.]{2,})\.yml$/.match(f)[1]
|
|
|
|
client = YAML.load_file("#{Rails.root}/config/locales/client.#{locale}.yml")
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(client.count).to eq(1)
|
|
|
|
expect(client[locale]).not_to eq(nil)
|
|
|
|
expect(client[locale].count).to eq(2)
|
|
|
|
expect(client[locale]["js"]).not_to eq(nil)
|
|
|
|
expect(client[locale]["admin_js"]).not_to eq(nil)
|
2013-03-23 10:49:31 -04:00
|
|
|
end
|
|
|
|
end
|
2013-03-23 03:57:31 -04:00
|
|
|
|
2013-03-23 10:49:31 -04:00
|
|
|
it "has valid YAML for server" do
|
|
|
|
Dir["#{Rails.root}/config/locales/server.*.yml"].each do |f|
|
|
|
|
locale = /.*\.([^.]{2,})\.yml$/.match(f)[1]
|
2013-03-23 03:57:31 -04:00
|
|
|
server = YAML.load_file("#{Rails.root}/config/locales/server.#{locale}.yml")
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(server.count).to eq(1)
|
|
|
|
expect(server[locale]).not_to eq(nil)
|
2013-03-23 03:57:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-22 12:49:46 -04:00
|
|
|
it "does not overwrite another language" do
|
2013-03-20 05:51:28 -04:00
|
|
|
Dir["#{Rails.root}/config/locales/*.yml"].each do |f|
|
|
|
|
locale = /.*\.([^.]{2,})\.yml$/.match(f)[1] + ':'
|
|
|
|
IO.foreach(f) do |line|
|
2014-02-14 14:47:52 -05:00
|
|
|
line.strip!
|
2013-03-20 05:51:28 -04:00
|
|
|
next if line.start_with? "#"
|
|
|
|
next if line.start_with? "---"
|
2014-02-14 17:57:38 -05:00
|
|
|
next if line.blank?
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(line).to eq locale
|
2013-03-20 05:51:28 -04:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
|
2015-09-18 15:12:37 -04:00
|
|
|
describe 'keys in English locale files' do
|
|
|
|
locale_files = ['config/locales', 'plugins/**/locales']
|
|
|
|
.product(['server.en.yml', 'client.en.yml'])
|
|
|
|
.collect { |dir, filename| Dir["#{Rails.root}/#{dir}/#{filename}"] }
|
|
|
|
.flatten
|
|
|
|
.map { |path| Pathname.new(path).relative_path_from(Rails.root) }
|
|
|
|
|
|
|
|
class DuplicateKeyFinder < LocaleFileWalker
|
|
|
|
def find_duplicates(filename)
|
|
|
|
@keys_with_count = {}
|
|
|
|
|
|
|
|
document = Psych.parse_file(filename)
|
|
|
|
handle_document(document)
|
|
|
|
|
|
|
|
@keys_with_count.delete_if { |key, count| count <= 1 }.keys
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def handle_scalar(node, depth, parents)
|
|
|
|
super(node, depth, parents)
|
|
|
|
|
|
|
|
key = parents.join('.')
|
|
|
|
@keys_with_count[key] = @keys_with_count.fetch(key, 0) + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
locale_files.each do |path|
|
|
|
|
context path do
|
|
|
|
it 'has no duplicate keys' do
|
|
|
|
duplicates = DuplicateKeyFinder.new.find_duplicates("#{Rails.root}/#{path}")
|
|
|
|
expect(duplicates).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|