require "spec_helper"
RSpec.describe IsoDoc::I18n do
it "has a version number" do
expect(IsoDoc::I18n::VERSION).not_to be nil
end
it "loads language files" do
c = IsoDoc::I18n.new("en", "Latn")
expect(c.text).to eq "text"
expect(c.at).to eq "at"
expect(c.language).to eq "en"
expect(c.script).to eq "Latn"
end
it "manipulates i18n class" do
c = IsoDoc::I18n.new("en", "Latn")
expect(c.get["text"]).to eq "text"
expect(c.get["fred"]).to be_nil
c.set("fred", "frederic")
expect(c.get["fred"]).to eq "frederic"
end
it "loads default for missing language files" do
c = IsoDoc::I18n.new("tlh", "Klin")
expect(c.text).to eq "text"
expect(c.at).to eq "at"
expect(c.language).to eq "tlh"
expect(c.script).to eq "Klin"
end
it "loads language file overrides" do
c = IsoDoc::I18n.new("en", "Latn", "spec/assets/new.yaml")
expect(c.text).to eq "text2"
expect(c.at).to eq "at"
expect(c.hash.to_s).to be_equivalent_to '{"key1"=>"val1", "key2"=>"val2"}'
expect(c.arr.to_s).to eq '["arr1", "arr2"]'
end
it "does English localisation" do
c = IsoDoc::I18n.new("en", "Latn")
expect(c.l10n("Code (hello, world.)"))
.to be_equivalent_to "Code (hello, world.)"
expect(c.l10n("Code (hello, world.)"))
.to be_equivalent_to "Code (hello, world.)"
end
it "does Chinese localisation" do
c = IsoDoc::I18n.new("zh", "Hans")
expect(c.l10n("Code (hello, world.)"))
.to be_equivalent_to "Code(hello、world.)"
expect(c.l10n("Code (hello, world.)"))
.to be_equivalent_to "Code(hello、world.)"
end
it "does Hebrew RTL localisation" do
c = IsoDoc::I18n.new("en", "Hebr")
expect(c.l10n("Code (hello, world.)"))
.to be_equivalent_to "Code (hello, world.)"
expect(c.l10n("Code (hello, world.)", "en", "Latn"))
.to be_equivalent_to "Code (hello, world.)"
c = IsoDoc::I18n.new("en", "Latn")
expect(c.l10n("Code (hello, world.)", "en", "Hebr"))
.to be_equivalent_to "Code (hello, world.)"
end
it "does Arabic RTL localisation" do
c = IsoDoc::I18n.new("en", "Arab")
expect(c.l10n("Code (hello, world.)"))
.to be_equivalent_to "Code (hello, world.)"
expect(c.l10n("Code (hello, world.)", "en", "Latn"))
.to be_equivalent_to "Code (hello, world.)"
c = IsoDoc::I18n.new("en", "Latn")
expect(c.l10n("Code (hello, world.)", "en", "Arab"))
.to be_equivalent_to "Code (hello, world.)"
end
it "does boolean conjunctions" do
c = IsoDoc::I18n.new("en", "Latn")
expect(c.boolean_conj([], "and")).to eq ""
expect(c.boolean_conj(%w(a), "and")).to eq "a"
expect(c.boolean_conj(%w(a b), "and")).to eq "a and b"
expect(c.boolean_conj(%w(a b c), "and")).to eq "a, b, and c"
expect(c.boolean_conj(%w(a b c d), "and")).to eq "a, b, c, and d"
end
end