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 1 commit 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
17 changes: 17 additions & 0 deletions i18n.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,20 @@ type:
fr: Rec.
cn: 建议书
ar: "التوصية"

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

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


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 == "cn"
postfix += type_translation
elsif language == "ar"
postfix += " #{type_translation}"
else
prefix += "#{type_translation} "
Expand Down
26 changes: 24 additions & 2 deletions spec/pubid_itu/identifier_spec.rb
Original file line number Diff line number Diff line change
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_cn) { "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 МСЭ" }
let(:pubid_long_fr) { "Annexe au BE de l'UIT 1283" }
let(:pubid_long_es) { "Anexo al BE de la UIT N.º 1283" }
let(:pubid_long_cn) { "国际电联第1283期《操作公报》附件" }
let(:pubid_long_ar) { "ملحق ابلنشرة التشغيلية رقم 1283" }

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
36 changes: 36 additions & 0 deletions spec/support/convert_pubid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: :cn)).to eq(pubid_long_cn)
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