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

Translate recommendation identifiers #48

Merged
merged 1 commit into from
Oct 9, 2024
Merged
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
13 changes: 13 additions & 0 deletions i18n.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
publisher:
ITU:
ru: МСЭ
es: UIT
fr: UIT

type:
REC:
ru: Рек.
es: Rec.
fr: Rec.
cn: 建议书
ar: "التوصية"
3 changes: 2 additions & 1 deletion lib/pubid/itu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module Itu
"es": "S",
"zh": "C",
}.freeze

I18N = YAML.load_file(File.join(File.dirname(__FILE__), "../../i18n.yaml"))
end
end

Expand All @@ -36,7 +38,6 @@ module Itu
require_relative "itu/transformer"
require_relative "itu/renderer/base"
require_relative "itu/renderer/implementers_guide"
require_relative "itu/renderer/special_publication"
require_relative "itu/renderer/contribution"
require_relative "itu/parser"
require_relative "itu/identifier"
Expand Down
7 changes: 7 additions & 0 deletions lib/pubid/itu/identifier/annex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ module Identifier
class Annex < Supplement
def_delegators 'Pubid::Itu::Identifier::Annex', :type

attr_accessor :base

def initialize(base: nil, **opts)
super(**opts)
@base = base
end

def self.type
{ key: :annex, title: "Annex" }
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pubid/itu/identifier/question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Question < Base
def_delegators 'Pubid::Itu::Identifier::Question', :type

def self.type
{ key: :question, title: "Question" }
{ key: :question, title: "Question", short: :question }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pubid/itu/identifier/resolution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Resolution < Base
def_delegators 'Pubid::Itu::Identifier::Resolution', :type

def self.type
{ key: :resolution, title: "Resolition" }
{ key: :resolution, title: "Resolition", short: :resolution }
end
end
end
Expand Down
4 changes: 0 additions & 4 deletions lib/pubid/itu/identifier/special_publication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ class SpecialPublication < Base
def self.type
{ key: :sp, title: "Special Publication", short: "SP" }
end

def self.get_renderer_class
Renderer::SpecialPublication
end
end
end
end
40 changes: 34 additions & 6 deletions lib/pubid/itu/renderer/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,48 @@ def render_type_series(params)
"%{type}%{series}" % params
end

def render_base_identifier(**args)
prerender(**args)

# pass args to render_identifier
render_identifier(@prerendered_params, args)
end

# can prepend entity, can postpend, can use item holder

def render_identifier(params)
prefix = ""
def render_identifier(params, opts)
postfix = prefix = ""
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
postfix += " #{type_translation}"
else
prefix += "#{type_translation} "
end
end

"#{prefix}%{publisher}-%{sector} #{render_type_series(params)}%{number}%{subseries}"\
"%{part}%{second_number}%{range}%{annex}%{amendment}%{corrigendum}%{supplement}"\
"%{addendum}%{appendix}%{date}" % params
"%{addendum}%{appendix}%{date}#{postfix}" % params
end

def render_publisher(publisher, opts, params)
if opts[:language] &&
(publisher_translation = Pubid::Itu::I18N["publisher"][publisher]&.fetch(opts[:language].to_s, nil))
return super(publisher_translation, opts, params)
end

super
end

def render_number(number, _opts, params)
params[:series] ? ".#{number}" : number
return " No. #{number}" if params[:series] == "OB"

number
end

def render_date(date, opts, _params)
Expand All @@ -44,8 +72,8 @@ def render_part(part, opts, _params)
"-#{part}"
end

def render_series(series, _opts, _params)
"#{series}"
def render_series(series, _opts, params)
series + (params[:series] != "OB" && params[:number] ? "." : "")
end

def render_amendment(amendment, _opts, _params)
Expand Down
6 changes: 5 additions & 1 deletion lib/pubid/itu/renderer/contribution.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
module Pubid::Itu::Renderer
class Contribution < Base
def render_identifier(params)
def render_identifier(params, _opts)
("%{series}-C%{number}" % params)
end

def render_series(series, _opts, _params)
series
end

def render_number(number, _opts, params)
number
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pubid/itu/renderer/implementers_guide.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Pubid::Itu::Renderer
class ImplementersGuide < Base
def render_type_series(params)
("%{series}" % params) + (params[:series] ? ".Imp" : "Imp")
("%{series}Imp" % params)
end

def render_number(number, _opts, params)
Expand Down
7 changes: 0 additions & 7 deletions lib/pubid/itu/renderer/special_publication.rb

This file was deleted.

2 changes: 1 addition & 1 deletion spec/pubid_itu/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ module Pubid::Itu
end

it "renders annex to identifier" do
expect(subject.to_s).to eq("Annex to ITU-T OB.1")
expect(subject.to_s).to eq("Annex to ITU-T OB No. 1")
end
end
end
Expand Down
25 changes: 24 additions & 1 deletion spec/pubid_itu/identifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,25 @@ module Pubid::Itu

context "ITU-R SA.364-6" do
let(:pubid) { "ITU-R SA.364-6" }
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建议书" }

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

# question
context "ITU-R SG01.222-200" do
let(:pubid) { "ITU-R SG01.222-200" }
let(:pubid_ru) { "МСЭ-R SG01.222-200" }

it_behaves_like "converts pubid to pubid"
it_behaves_like "converts pubid to russian pubid"

it { expect(subject).to be_a(Identifier::Question) }
end
Expand Down Expand Up @@ -170,8 +180,18 @@ module Pubid::Itu

context "ITU-T M.3016.1" do
let(:pubid) { "ITU-T M.3016.1" }
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_ar) { "ITU-T M.3016.1 التوصية" }

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

context "ITU-R RR (2020)" do
Expand Down Expand Up @@ -296,13 +316,16 @@ module Pubid::Itu
context "ITU-T Z.100 App. II (03/1993)" do
let(:original) { "ITU-T Z.100 App. II (03/1993)" }
let(:pubid) { "ITU-T Z.100 App. 2 (03/1993)" }
let(:pubid_ru) { "Рек. МСЭ-T Z.100 App. 2 (03/1993)" }

it_behaves_like "converts pubid to pubid"
it_behaves_like "converts pubid to russian pubid"
it { expect(subject).to be_a(Identifier::Appendix) }
end

context "Annex to ITU-T OB.1283 (01/2024)" do
let(:pubid) { "Annex to ITU-T OB.1283 (01/2024)" }
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"
end
Expand Down
30 changes: 30 additions & 0 deletions spec/support/convert_pubid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,36 @@
end
end

shared_examples "converts pubid to french pubid" do
it "converts pubid to french pubid" do
expect(subject.to_s(language: :fr)).to eq(pubid_fr)
end
end

shared_examples "converts pubid to spanish pubid" do
it "converts pubid to spanish pubid" do
expect(subject.to_s(language: :es)).to eq(pubid_es)
end
end

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)
end
end

shared_examples "converts pubid to russian pubid" do
it "converts pubid to russian pubid" do
expect(subject.to_s(language: :ru)).to eq(pubid_ru)
end
end

shared_examples "converts pubid to arabic pubid" do
it "converts pubid to arabic pubid" do
expect(subject.to_s(language: :ar)).to eq(pubid_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