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

Add translations for "Annex to" #49

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion i18n.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,22 @@ type:
ru: Рек.
es: Rec.
fr: Rec.
cn: 建议书
zh: 建议书
ar: "التوصية"

annex:
ru: Приложение к
fr: Annexe au
es: Anexo al
zh: 附件
ar: ملحق
en: Annex to

annex_to_itu_ob:
ru: Приложение к ОБ %-R МСЭ
fr: Annexe au BE de l'UIT %-F
zh: 国际电联第%期《操作公报》附件
ar: ملحق ابلنشرة التشغيلية رقم ‎%-A
es: Anexo al BE de la UIT N.º %-S


24 changes: 18 additions & 6 deletions lib/pubid/itu/renderer/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,25 @@ def render_base_identifier(**args)

def render_identifier(params, opts)
postfix = prefix = ""

type = @params[:type]
language = opts[:language]&.to_s || "en"

if @params[:annex] && @params[:annex][:number].nil?
prefix += "Annex to "
elsif opts[:language] &&
(type_translation = Pubid::Itu::I18N["type"][@params[:type]]&.fetch(opts[:language].to_s, nil))
if opts[:language] == :cn
postfix =+ type_translation
elsif opts[:language] == :ar
if opts[:format] == :long &&
@params >= { publisher: "ITU", series: "OB", sector: "T" } && opts[:language]

# render the whole identifier using template in i18n.yaml for long
return Pubid::Itu::I18N["annex_to_itu_ob"]&.fetch(language).sub("%", @params[:number])
end

type = "annex"
end

if (type_translation = Pubid::Itu::I18N["type"][type]&.fetch(language, nil))
if language == "zh"
postfix += type_translation
elsif language == "ar"
postfix += " #{type_translation}"
else
prefix += "#{type_translation} "
Expand Down
30 changes: 26 additions & 4 deletions spec/pubid_itu/identifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module Pubid::Itu
let(:pubid_ru) { "Рек. МСЭ-R SA.364-6" }
let(:pubid_es) { "Rec. UIT-R SA.364-6" }
let(:pubid_ar) { "ITU-R SA.364-6 التوصية" }
let(:pubid_cn) { "ITU-R SA.364-6建议书" }
let(:pubid_zh) { "ITU-R SA.364-6建议书" }

it_behaves_like "converts pubid to pubid"
it_behaves_like "converts pubid to russian pubid"
Expand Down Expand Up @@ -183,7 +183,7 @@ module Pubid::Itu
let(:pubid_es) { "Rec. UIT-T M.3016.1" }
let(:pubid_fr) { "Rec. UIT-T M.3016.1" }
let(:pubid_ru) { "Рек. МСЭ-T M.3016.1" }
let(:pubid_cn) { "ITU-T M.3016.1建议书" }
let(:pubid_zh) { "ITU-T M.3016.1建议书" }
let(:pubid_ar) { "ITU-T M.3016.1 التوصية" }

it_behaves_like "converts pubid to pubid"
Expand Down Expand Up @@ -326,8 +326,30 @@ module Pubid::Itu
context "Annex to ITU-T OB.1283 (01/2024)" do
let(:original) { "Annex to ITU-T OB.1283 (01/2024)" }
let(:pubid) { "Annex to ITU-T OB No. 1283 (01/2024)" }

it_behaves_like "converts pubid to pubid"
let(:pubid_ru) { "Приложение к МСЭ-T OB No. 1283 (01/2024)" }
let(:pubid_zh) { "ITU-T OB No. 1283 (01/2024)附件" }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"ITU-T OB No. 1283 (01/2024)附件" => "ITU-T OB No. 1283 (01/2024) 附件"

let(:pubid_ar) { "ITU-T OB No. 1283 (01/2024) ملحق" }
let(:pubid_es) { "Anexo al UIT-T OB No. 1283 (01/2024)" }
let(:pubid_fr) { "Annexe au UIT-T OB No. 1283 (01/2024)" }
let(:pubid_long) { "Annex to ITU-T OB No. 1283 (01/2024)" }
let(:pubid_long_ru) { "Приложение к ОБ 1283-R МСЭ" }
let(:pubid_long_fr) { "Annexe au BE de l'UIT 1283-F" }
let(:pubid_long_es) { "Anexo al BE de la UIT N.º 1283-S" }
let(:pubid_long_zh) { "国际电联第1283期《操作公报》附件" }
let(:pubid_long_ar) { "ملحق ابلنشرة التشغيلية رقم ‎1283-A" }

it_behaves_like "converts pubid to pubid"
it_behaves_like "converts pubid to long pubid"
it_behaves_like "converts pubid to russian pubid"
it_behaves_like "converts pubid to long russian pubid"
it_behaves_like "converts pubid to french pubid"
it_behaves_like "converts pubid to long french pubid"
it_behaves_like "converts pubid to spanish pubid"
it_behaves_like "converts pubid to long spanish pubid"
it_behaves_like "converts pubid to arabic pubid"
it_behaves_like "converts pubid to long arabic pubid"
it_behaves_like "converts pubid to chinese pubid"
it_behaves_like "converts pubid to long chinese pubid"
end

context "identifier with language" do
Expand Down
38 changes: 37 additions & 1 deletion spec/support/convert_pubid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

shared_examples "converts pubid to chinese pubid" do
it "converts pubid to chinese pubid" do
expect(subject.to_s(language: :cn)).to eq(pubid_cn)
expect(subject.to_s(language: :zh)).to eq(pubid_zh)
end
end

Expand All @@ -34,6 +34,42 @@
end
end

shared_examples "converts pubid to long pubid" do
it "converts pubid to long pubid" do
expect(subject.to_s(format: :long)).to eq(pubid_long)
end
end

shared_examples "converts pubid to long french pubid" do
it "converts pubid to long french pubid" do
expect(subject.to_s(format: :long, language: :fr)).to eq(pubid_long_fr)
end
end

shared_examples "converts pubid to long spanish pubid" do
it "converts pubid to long spanish pubid" do
expect(subject.to_s(format: :long, language: :es)).to eq(pubid_long_es)
end
end

shared_examples "converts pubid to long chinese pubid" do
it "converts pubid to long chinese pubid" do
expect(subject.to_s(format: :long, language: :zh)).to eq(pubid_long_zh)
end
end

shared_examples "converts pubid to long russian pubid" do
it "converts pubid to long russian pubid" do
expect(subject.to_s(format: :long, language: :ru)).to eq(pubid_long_ru)
end
end

shared_examples "converts pubid to long arabic pubid" do
it "converts pubid to long arabic pubid" do
expect(subject.to_s(format: :long, language: :ar)).to eq(pubid_long_ar)
end
end

shared_examples "converts pubid to pubid with type" do
it "converts pubid to pubid" do
expect(subject.to_s(with_type: true)).to eq(pubid_with_type)
Expand Down
Loading