Skip to content

Commit

Permalink
i18n date_printing: #1200
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Aug 8, 2024
1 parent 0dc02dd commit d8d8e95
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/isodoc/iso/i18n-en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ reference_number_abbrev: Ref. No.
price_based_on: Price based on % pages
price: Price
date_first_printing: Date of the first printing
date_printing: Date of the % printing
date_printing: "Date of the {{ var1 | ordinal_word: '', '' }} printing"
descriptor: Descriptor
under_preparation: Under preparation. (Stage at the time of publication %).
withdrawn: Withdrawn.
Expand Down
2 changes: 1 addition & 1 deletion lib/isodoc/iso/i18n-fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ reference_number_abbrev: Réf. №
price_based_on: Prix basé sur % pages
price: Prix
date_first_printing: Date de la première impression
date_printing: Date de la % impression
date_printing: "Date de la {{ var1 | ordinal_word: '', 'f' }} impression"
descriptor: Descripteur
under_preparation: En cours d'élaboration. (Stade au moment de la publication %).
withdrawn: Retiré.
Expand Down
2 changes: 1 addition & 1 deletion lib/isodoc/iso/i18n-ru.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ descriptor: Дескриптор
price_based_on: Цена рассчитана на % стр.
price: Цена
date_first_printing: Дата первой печати
date_printing: Дата % печати
date_printing: "Дата {{ var1 | ordinal_word: '', 'f.gen' }} печати"
under_preparation: В стадии подготовки. (Стадия на момент публикации %).
withdrawn: Отозван.
cancelled_and_replaced: Отменено и заменено на %.
Expand Down
10 changes: 10 additions & 0 deletions lib/isodoc/iso/presentation_bibdata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ def edition_translate(bibdata)
@lang == "fr" and e = bibdata.at(ns("./edition[@language = 'fr']")) and
e.children = e.text.sub(/(\d+)(\p{L}+)/, "\\1<sup>\\2</sup>")
@docscheme == "1951" and edition_replacement(bibdata)
edition_printing_date(bibdata)
end

def edition_printing_date(bibdata)
@i18n.date_printing &&
pd = bibdata.at(ns("//metanorma-extension/presentation-metadata" \
"[name = 'printing-date']/value")) or return
x = @i18n.populate("date_printing",
{ "var1" => pd.text.split(/,/).first.to_i })
bibdata.at(ns("./ext")) << "<date-printing>#{x}</date-printing>"
end

def edition_replacement(bibdata)
Expand Down
2 changes: 1 addition & 1 deletion metanorma-iso.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
spec.test_files = `git ls-files -- {spec}/*`.split("\n")
spec.required_ruby_version = Gem::Requirement.new(">= 3.1.0")

spec.add_dependency "metanorma-standoc", "~> 2.9.0"
spec.add_dependency "metanorma-standoc", "~> 2.9.3"
spec.add_dependency "mnconvert", "~> 1.14"
spec.add_dependency "pubid"
spec.add_dependency "tokenizer", "~> 0.3.0"
Expand Down
46 changes: 46 additions & 0 deletions spec/isodoc/i18n_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1727,4 +1727,50 @@
expect(xml.at("//xmlns:edn-replacement"))
.to be_nil
end

it "add printing number text" do
input = <<~"INPUT"
<iso-standard xmlns="http://riboseinc.com/isoxml">
<bibdata>
<language>en</language>
<script>Latn</script>
<edition>2</edition>
<ext>
<doctype>brochure</doctype>
</ext>
</bibdata>
<metanorma-extension>
<presentation-metadata><name>document-scheme</name><value>1951</value></presentation-metadata>
<presentation-metadata><name>printing-date</name><value>2,1965-12-01</value></presentation-metadata>
</metanorma-extension>
<sections>
<clause id="D" obligation="normative" type="scope">
<title>Scope</title>
<p id="E">Text</p>
</clause>
</sections>
</iso-standard>
INPUT

xml = Nokogiri::XML(IsoDoc::Iso::PresentationXMLConvert
.new(presxml_options)
.convert("test", input, true))
expect(xml.at("//xmlns:date-printing").to_xml)
.to be_equivalent_to "<date-printing>Date of the second printing</date-printing>"

xml = Nokogiri::XML(IsoDoc::Iso::PresentationXMLConvert
.new(presxml_options)
.convert("test", input
.sub("<language>en</language>", "<language>fr</language>"), true))
expect(xml.at("//xmlns:date-printing").to_xml)
.to be_equivalent_to "<date-printing>Date de la deuxi&#xE8;me impression</date-printing>"

xml = Nokogiri::XML(IsoDoc::Iso::PresentationXMLConvert
.new(presxml_options)
.convert("test", input
.sub("<language>en</language>", "<language>ru</language>")
.sub("<script>Latn</script>", "<script>Cyrl</script>"), true))
expect(xml.at("//xmlns:date-printing").to_xml)
.to be_equivalent_to "<date-printing>&#x414;&#x430;&#x442;&#x430; &#x432;&#x442;&#x43E;&#x440;&#x43E;&#x439; &#x43F;&#x435;&#x447;&#x430;&#x442;&#x438;</date-printing>"
end
end

0 comments on commit d8d8e95

Please sign in to comment.