Class: I18n::JS::Segment
- Inherits:
-
Object
- Object
- I18n::JS::Segment
- Defined in:
- lib/i18n/js/segment.rb
Overview
Class which enscapulates a translations hash and outputs a single JSON translation file
Constant Summary collapse
- OPTIONS =
[:namespace, :pretty_print, :js_extend, :sort_translation_keys].freeze
- LOCALE_INTERPOLATOR =
/%\{locale\}/
Instance Method Summary collapse
-
#initialize(file, translations, options = {}) ⇒ Segment
constructor
A new instance of Segment.
-
#save! ⇒ Object
Saves JSON file containing translations.
Constructor Details
#initialize(file, translations, options = {}) ⇒ Segment
Returns a new instance of Segment.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/i18n/js/segment.rb', line 13 def initialize(file, translations, = {}) @file = file # `#slice` will be used # But when activesupport is absent, # the core extension from `i18n` gem will be used instead # And it's causing errors (at least in test) # # So the input is wrapped by our class for better `#slice` @translations = Private::HashWithSymbolKeys.new(translations) @namespace = [:namespace] || 'I18n' @pretty_print = !![:pretty_print] @js_extend = .key?(:js_extend) ? !![:js_extend] : true @sort_translation_keys = .key?(:sort_translation_keys) ? !![:sort_translation_keys] : true end |
Instance Method Details
#save! ⇒ Object
Saves JSON file containing translations
29 30 31 32 33 34 35 36 37 |
# File 'lib/i18n/js/segment.rb', line 29 def save! if @file =~ LOCALE_INTERPOLATOR I18n.available_locales.each do |locale| write_file(file_for_locale(locale), @translations.slice(locale)) end else write_file end end |