Class: IsoDoc::I18n
- Inherits:
-
Object
- Object
- IsoDoc::I18n
- Defined in:
- lib/isodoc/i18n.rb
Class Method Summary collapse
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(lang, script, i18nyaml = nil) ⇒ I18n
constructor
A new instance of I18n.
-
#l10n(x, lang = @lang, script = @script) ⇒ Object
TODO: move to localization file function localising spaces and punctuation.
- #load_yaml(lang, script, i18nyaml = nil) ⇒ Object
- #load_yaml1(lang, script) ⇒ Object
- #set(x, y) ⇒ Object
Constructor Details
#initialize(lang, script, i18nyaml = nil) ⇒ I18n
Returns a new instance of I18n.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/isodoc/i18n.rb', line 36 def initialize(lang, script, i18nyaml = nil) @lang = lang @script = script y = load_yaml(lang, script, i18nyaml) @labels = y @labels["language"] = @lang @labels["script"] = @script @labels.each do |k, v| self.class.send(:define_method, k.downcase) { v } end =begin @term_def_boilerplate = y["term_def_boilerplate"] @scope_lbl = y["scope"] @symbols_lbl = y["symbols"] @table_of_contents_lbl = y["table_of_contents"] @introduction_lbl = y["introduction"] @foreword_lbl = y["foreword"] @abstract_lbl = y["abstract"] @termsdef_lbl = y["termsdef"] @termsdefsymbols_lbl = y["termsdefsymbols"] @normref_lbl = y["normref"] @bibliography_lbl = y["bibliography"] @clause_lbl = y["clause"] @annex_lbl = y["annex"] @appendix_lbl = y["appendix"] @no_terms_boilerplate = y["no_terms_boilerplate"] @internal_terms_boilerplate = y["internal_terms_boilerplate"] @norm_with_refs_pref = y["norm_with_refs_pref"] @norm_empty_pref = y["norm_empty_pref"] @external_terms_boilerplate = y["external_terms_boilerplate"] @internal_external_terms_boilerplate = y["internal_external_terms_boilerplate"] @note_lbl = y["note"] @note_xref_lbl = y["note_xref"] @termnote_lbl = y["termnote"] @figure_lbl = y["figure"] @list_lbl = y["list"] @formula_lbl = y["formula"] @inequality_lbl = y["inequality"] @table_lbl = y["table"] @key_lbl = y["key"] @example_lbl = y["example"] @example_xref_lbl = y["example_xref"] @where_lbl = y["where"] @wholeoftext_lbl = y["wholeoftext"] @draft_lbl = y["draft_label"] @inform_annex_lbl = y["inform_annex"] @norm_annex_lbl = y["norm_annex"] @modified_lbl = y["modified"] @deprecated_lbl = y["deprecated"] @source_lbl = y["source"] @and_lbl = y["and"] @all_parts_lbl = y["all_parts"] @permission_lbl = y["permission"] @recommendation_lbl = y["recommendation"] @requirement_lbl = y["requirement"] @locality = y["locality"] @admonition = y["admonition"] =end end |
Class Method Details
.l10n(x, lang = @lang, script = @script) ⇒ Object
97 98 99 |
# File 'lib/isodoc/i18n.rb', line 97 def self.l10n(x, lang = @lang, script = @script) l10n(x, lang, script) end |
Instance Method Details
#get ⇒ Object
28 29 30 |
# File 'lib/isodoc/i18n.rb', line 28 def get @labels end |
#l10n(x, lang = @lang, script = @script) ⇒ Object
TODO: move to localization file function localising spaces and punctuation. Not clear if period needs to be localised for zh
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/isodoc/i18n.rb', line 104 def l10n(x, lang = @lang, script = @script) if lang == "zh" && script == "Hans" xml = Nokogiri::HTML::DocumentFragment.parse(x) xml.traverse do |n| next unless n.text? n.replace(n.text.gsub(/ /, "").gsub(/:/, ":").gsub(/,/, "、"). gsub(/\(/, "(").gsub(/\)/, ")"). gsub(/\[/, "【").gsub(/\]/, "】")) end xml.to_xml.gsub(/<b>/, "").gsub("</b>", "").gsub(/<\?[^>]+>/, "") else x end end |
#load_yaml(lang, script, i18nyaml = nil) ⇒ Object
6 7 8 9 10 |
# File 'lib/isodoc/i18n.rb', line 6 def load_yaml(lang, script, i18nyaml = nil) ret = load_yaml1(lang, script) return ret.merge(YAML.load_file(i18nyaml)) if i18nyaml ret end |
#load_yaml1(lang, script) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/isodoc/i18n.rb', line 12 def load_yaml1(lang, script) if lang == "en" YAML.load_file(File.join(File.dirname(__FILE__), "../isodoc-yaml/i18n-en.yaml")) elsif lang == "fr" YAML.load_file(File.join(File.dirname(__FILE__), "../isodoc-yaml/i18n-fr.yaml")) elsif lang == "zh" && script == "Hans" YAML.load_file(File.join(File.dirname(__FILE__), "../isodoc-yaml/i18n-zh-Hans.yaml")) else YAML.load_file(File.join(File.dirname(__FILE__), "../isodoc-yaml/i18n-en.yaml")) end end |
#set(x, y) ⇒ Object
32 33 34 |
# File 'lib/isodoc/i18n.rb', line 32 def set(x, y) @labels[x] = y end |