Module: RailsI18nManager

Defined in:
lib/rails_i18n_manager.rb,
lib/rails_i18n_manager/config.rb,
lib/rails_i18n_manager/engine.rb,
lib/rails_i18n_manager/version.rb,
app/lib/rails_i18n_manager/forms/base.rb,
app/jobs/rails_i18n_manager/application_job.rb,
app/lib/rails_i18n_manager/google_translate.rb,
app/models/rails_i18n_manager/translation_app.rb,
app/models/rails_i18n_manager/translation_key.rb,
app/models/rails_i18n_manager/translation_value.rb,
app/models/rails_i18n_manager/application_record.rb,
app/helpers/rails_i18n_manager/application_helper.rb,
app/helpers/rails_i18n_manager/custom_form_builder.rb,
app/jobs/rails_i18n_manager/translations_import_job.rb,
app/lib/rails_i18n_manager/forms/translation_file_form.rb,
app/controllers/rails_i18n_manager/application_controller.rb,
app/controllers/rails_i18n_manager/translations_controller.rb,
app/controllers/rails_i18n_manager/translation_apps_controller.rb

Defined Under Namespace

Modules: ApplicationHelper, Forms, GoogleTranslate Classes: ApplicationController, ApplicationJob, ApplicationRecord, Config, CustomFormBuilder, Engine, TranslationApp, TranslationAppsController, TranslationKey, TranslationValue, TranslationsController, TranslationsImportJob

Constant Summary collapse

VERSION =
"1.0.2".freeze

Class Method Summary collapse

Class Method Details

._recursive_fetch_keys(list:, key:, val:, prev_dot_notation_key: nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rails_i18n_manager.rb', line 28

def self._recursive_fetch_keys(list:, key:, val:, prev_dot_notation_key: nil)
  if prev_dot_notation_key
    dot_notation_key = [prev_dot_notation_key, key].compact.join(".")
  else
    dot_notation_key = key
  end

  if val.is_a?(Hash)
    val.each do |inner_key, inner_val|
      _recursive_fetch_keys(list: list, key: inner_key, val: inner_val, prev_dot_notation_key: dot_notation_key)
    end
  else
    list << dot_notation_key
  end
end

.config(&block) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/rails_i18n_manager.rb', line 6

def self.config(&block)
  c = RailsI18nManager::Config

  if block_given?
    block.call(c)
  else
    return c
  end
end

.fetch_flattened_dot_notation_keys(translations_hash) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rails_i18n_manager.rb', line 16

def self.fetch_flattened_dot_notation_keys(translations_hash)
  keys = []

  translations_hash.each do |_locale, h|
    h.each do |k,v|
      _recursive_fetch_keys(list: keys, key: k, val: v)
    end
  end

  return keys.uniq
end

.hash_deep_set(hash, keys_array, val) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rails_i18n_manager.rb', line 44

def self.hash_deep_set(hash, keys_array, val)
  if !hash.is_a?(::Hash)
    raise TypeError.new("Invalid object passed to #{__method__}, must be a Hash")
  end

  keys_array[0...-1].inject(hash){|result, key|
    if !result[key].is_a?(Hash)
      result[key] = {}
    end

    result[key]
  }.send(:[]=, keys_array.last, val)

  return hash
end