Module: Sinatra::I18n::Helpers

Included in:
ReportBuilder::ProcessReport::Excel
Defined in:
lib/sinatra/i18n.rb

Instance Method Summary collapse

Instance Method Details

#available_localesObject



97
98
99
# File 'lib/sinatra/i18n.rb', line 97

def available_locales
  [:es,:en,:pl]
end

#available_locales_hashObject



100
101
102
103
104
105
# File 'lib/sinatra/i18n.rb', line 100

def available_locales_hash
  available_locales.inject({}) {|ac,v|
    ac[v] = ::I18n.t("locale.#{v}");ac
  }

end

#get_lang(http_lang) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sinatra/i18n.rb', line 31

def get_lang(http_lang)
  accepted=["en","es","pl"]
  unless http_lang.nil?
    langs=http_lang.split(",").map {|v|
      v.split(";")[0].split("-")[0]
    }.each  {|l|
      return l if accepted.include? l
    }
  end
  "en"
end

#tObject

Just a wrapper for I18n::t method



44
45
46
# File 'lib/sinatra/i18n.rb', line 44

def t(...)
  ::I18n::t(...)
end

#t_canonical_document_title(cd_title, secondary, translate_secondary = true) ⇒ Object

Set title for canonical document pages



87
88
89
90
# File 'lib/sinatra/i18n.rb', line 87

def t_canonical_document_title(cd_title, secondary, translate_secondary=true)
  cd_title = ::I18n::t(:canonical_document_title, cd_title: cd_title)
  t_generic_title(cd_title, secondary, translate_secondary)
end

#t_desc_value(term, value) ⇒ Object

Put the term on strong tag, double colon, and later the value

Parameters:

  • term

    Term to be i18n and marked with strong tag

  • value

    Value to be presented, without changes



70
71
72
# File 'lib/sinatra/i18n.rb', line 70

def t_desc_value(term, value)
  "<strong>#{::I18n::t(term)}:</strong>&nbsp;#{value}"
end

#t_generic_title(object_name, secondary, translate_secondary = true) ⇒ Object



74
75
76
77
78
# File 'lib/sinatra/i18n.rb', line 74

def t_generic_title(object_name, secondary, translate_secondary=true)
  secondary_traslation= translate_secondary ? ::I18n::t(secondary) : secondary
  @title="#{secondary_traslation} - #{object_name}"
  "<h2>#{object_name}</h2><h3>#{secondary_traslation}</h3>"
end

#t_search_title(sr_name, search_name, secondary) ⇒ Object

Set title for searches pages



93
94
95
96
# File 'lib/sinatra/i18n.rb', line 93

def t_search_title(sr_name, search_name, secondary)
  @title="#{::I18n::t(secondary)} - #{::I18n::t(:search_title, search_name:search_name)} - #{::I18n::t(:systematic_review_title_abbrev, sr_name:sr_name)}"
  "<h2>#{::I18n::t(:search_title, search_name: search_name)} - #{::I18n::t(:systematic_review_title_abbrev, sr_name:sr_name)}</h2><h3>#{::I18n::t(secondary)}</h3>"
end

#t_systematic_review_title(sr_name, secondary, translate_secondary = true) ⇒ Object

Set title for systematic review pages



81
82
83
84
# File 'lib/sinatra/i18n.rb', line 81

def t_systematic_review_title(sr_name, secondary, translate_secondary=true)
  sr_title = ::I18n::t(:systematic_review_title, sr_name: sr_name)
  t_generic_title(sr_title, secondary, translate_secondary)
end

#t_taxonomy_category(terms) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/sinatra/i18n.rb', line 51

def t_taxonomy_category(terms)
  $log.info(terms)
  if terms.is_a? String
    ::I18n::t("sr_taxonomy_category.#{terms}")
  elsif is_a? Array
    terms.map {|term| ::I18n::t("sr_taxonomy_category.#{term}")}.join("," )
  end
end

#t_taxonomy_group(term) ⇒ Object



48
49
50
# File 'lib/sinatra/i18n.rb', line 48

def t_taxonomy_group(term)
  ::I18n::t("sr_taxonomy.#{term}")
end

#t_yes_no_nil(x) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/sinatra/i18n.rb', line 59

def t_yes_no_nil(x)
  if x.nil?
    ::I18n::t(:Not_defined)
  else
    x ? ::I18n::t(:Yes) : ::I18n::t(:No)
  end
end