Class: Rich::I18n::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/rich/i18n/engine.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.cache_translationsObject

Returns the value of attribute cache_translations.



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

def cache_translations
  @cache_translations
end

.enable_enriched_outputObject

Returns the value of attribute enable_enriched_output.



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

def enable_enriched_output
  @enable_enriched_output
end

.loggerObject

Returns the value of attribute logger.



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

def logger
  @logger
end

Class Method Details

.can_enrich_output?Boolean

Returns:

  • (Boolean)


71
72
73
74
75
76
77
78
# File 'lib/rich/i18n/engine.rb', line 71

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



39
40
41
42
# File 'lib/rich/i18n/engine.rb', line 39

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



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rich/i18n/engine.rb', line 53

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_locale = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rich/i18n/engine.rb', line 10

def init(test_locale = 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.autoload_paths << path
    ActiveSupport::Dependencies.autoload_once_paths.delete path
  end

  procedure = proc {
    ::Jzip::Engine.add_template_location({File.expand_path("../../../../assets/jzip", __FILE__) => 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_locale
    Rich::I18n::Engine.logger = Rails.logger
  }

  if Rails::VERSION::MAJOR >= 3
    config.after_initialize do
      procedure.call
    end
  else
    procedure.call
  end

  test_locale
end

.load_i18n(test_locale) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/rich/i18n/engine.rb', line 44

def load_i18n(test_locale)
  if test_locale
    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!
end