module IsoDoc::I18n::Liquid
def self.set(i18n)
def self.set(i18n) @@i18n = i18n end
def inflect(word, options)
def inflect(word, options) @@i18n.inflect(word, parse_hash(options)) end
def ordinal_num(num, label = "", infl = "")
e.g. "3" | ordinal: "edition", "case:acc"
num | ordinal_num: label, inflection
def ordinal_num(num, label = "", infl = "") l = @@i18n.labels[label] h = @@i18n.labels["inflection"]&.dig(l, "grammar") || {} grammar = h.merge(parse_hash(infl, symbol: false)) @@i18n.inflect_ordinal(num.to_i, grammar, "OrdinalRules") end
def ordinal_word(num, label = "", infl = "")
def ordinal_word(num, label = "", infl = "") l = @@i18n.labels[label] h = @@i18n.labels["inflection"]&.dig(l, "grammar") || {} grammar = h.merge(parse_hash(infl, symbol: false)) @@i18n.inflect_ordinal(num.to_i, grammar, "SpelloutRules") end
def parse_hash(str, symbol: true)
def parse_hash(str, symbol: true) str.split(/,\s*/).each_with_object({}) do |e, m| k, v = e.split(/:/, 2) m[symbol ? k.to_sym : k.to_s] = v end end