Module: Rich::I18n::Engine

Extended by:
Engine
Included in:
Engine
Defined in:
lib/rich/i18n/engine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cache_translationsObject

Returns the value of attribute cache_translations.



7
8
9
# File 'lib/rich/i18n/engine.rb', line 7

def cache_translations
  @cache_translations
end

#enable_enriched_outputObject

Returns the value of attribute enable_enriched_output.



7
8
9
# File 'lib/rich/i18n/engine.rb', line 7

def enable_enriched_output
  @enable_enriched_output
end

Instance Method Details

#can_enrich_output?Boolean

Returns:

  • (Boolean)


63
64
65
66
67
68
69
70
# File 'lib/rich/i18n/engine.rb', line 63

def can_enrich_output?
  if @can_enrich_output.nil?
    @can_enrich_output = !!@enable_enriched_output &&
                          (@enable_enriched_output.is_a?(Symbol) ? (@current_controller.send(@enable_enriched_output) rescue false) : @enable_enriched_output)
  else
    @can_enrich_output
  end
end

#current_controller=(current_controller) ⇒ Object



26
27
28
29
# File 'lib/rich/i18n/engine.rb', line 26

def current_controller=(current_controller)
  @current_controller = current_controller
  @can_enrich_output  = nil
end

#enable_i18n_cms(enriched_output_criteria = :current_rich_cms_admin, assign_i18n_backend = true) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rich/i18n/engine.rb', line 45

def enable_i18n_cms(enriched_output_criteria = :current_rich_cms_admin, assign_i18n_backend = true)
  raise "Missing E9s module Rich-CMS, please install first" unless defined?(Cms::Engine)
  
  self.enable_enriched_output = enriched_output_criteria
  Cms::Engine.register ".i18n", {:class_name => "Translation", :key => [:key, :locale], :before_edit => "Rich.I18n.beforeEdit", :after_update => "Rich.I18n.afterUpdate"}
  
  # FIXME: the check is a dirty fix to be able to test all the E9s modules at once (find a better implementation)
  if RAILS_ENV != "test" && assign_i18n_backend
    ::I18n.backend = ::I18n::Backend::Chain.new ::I18n::Backend::ActiveRecord.new, ::I18n.backend
    ::I18n.backend.extend ::I18n::Backend::Fallbacks
  end
end

#init(test_class = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rich/i18n/engine.rb', line 9

def init(test_class = nil)
  @enable_enriched_output = true if @enable_enriched_output.nil?
  @cache_translations     = true if @cache_translations    .nil?
  
  %w(controllers).each do |dir|
    path = File.join File.dirname(__FILE__), "..", "..", "app", dir
    $LOAD_PATH << path
    ActiveSupport::Dependencies.load_paths << path
    ActiveSupport::Dependencies.load_once_paths.delete path
  end
  
  ::Jzip::Engine.add_template_location({File.join(File.dirname(__FILE__), "..", "..", "assets", "jzip") => File.join(RAILS_ROOT, "public", "javascripts")})
  ::Formtastic::SemanticFormBuilder.escape_html_entities_in_hints_and_labels = false if ::Formtastic::SemanticFormBuilder.respond_to?(:escape_html_entities_in_hints_and_labels)
  
  load_i18n test_class
end

#load_i18n(test_class) ⇒ Object



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

def load_i18n(test_class)
  if test_class
    test_locale = test_class.name.match(/(Rich\:\:I18n\:\:Test\:\:Locales\:\:)(\w+)/).captures[1].downcase.to_sym
    
    I18n.load_path  =    [File.join(File.dirname(__FILE__), "..", "..", "..", "locales", "#{test_locale}.yml")]
  else
    I18n.load_path += Dir[File.join(File.dirname(__FILE__), "..", "..", "..", "locales", "*.yml")]
  end

  I18n.backend.reload!
  
  test_locale
end