Module: Globalize::Automatic::TranslatedExtension

Extended by:
ActiveSupport::Concern
Defined in:
lib/globalize/automatic.rb

Instance Method Summary collapse

Instance Method Details

#automatic_translation_for(locale) ⇒ Object



88
89
90
91
92
# File 'lib/globalize/automatic.rb', line 88

def automatic_translation_for(locale)
  automatic_translation_caches[locale] ||=
      automatic_translations.where(locale: locale).
          first_or_initialize(default_translation_automatically(locale))
end

#automatic_translation_locale(attr_name) ⇒ Object

自動翻訳元言語 attr_nameの自動変換が有効なとき 現在翻訳元として設定されていてかつ自動変換が無効なものの中で 一番優先度の高い翻訳元localeを返す。 どの言語も設定されてない場合は一番優先度の高いもの 自動翻訳元でない場合nil



116
117
118
119
120
121
122
123
# File 'lib/globalize/automatic.rb', line 116

def automatic_translation_locale(attr_name)
  locales = automatic_translation_field_locales[attr_name]
  locales.each do |locale|
    next if send(self.class.automatic_translation_attribute_name_for(attr_name, locale))
    return locale unless translation_for(locale)[attr_name].blank?
  end
  locales.first
end

#initialize_dup(other) ⇒ Object



131
132
133
134
135
136
137
# File 'lib/globalize/automatic.rb', line 131

def initialize_dup(other)
  @automatic_translation_caches = nil
  super(other)
  other.automatic_translation_attribute_names.each do |attr_name|
    self.attributes = { attr_name => other.send(attr_name) }
  end
end

#reload(options = nil) ⇒ Object



125
126
127
128
129
# File 'lib/globalize/automatic.rb', line 125

def reload(options = nil)
  automatic_translation_caches.clear
  automatic_translation_attribute_names.each { |attr_name| @attributes.reset(attr_name.to_s) }
  super(options)
end

#run_automatic_translation(from_locale:, attribute_names:) ⇒ Object

from_locale から attribute_names を自動翻訳 自動翻訳が対象でない場合なにもしない



96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/globalize/automatic.rb', line 96

def run_automatic_translation(from_locale: , attribute_names:)
  attribute_names.each do |attr_name|
    # 自動翻訳対象以外
    next unless automatic_translation_field_locales[attr_name].include?(from_locale)
    # 自動翻訳先としては無効化されている
    next if automatic_translation_for(from_locale)[:"#{attr_name}_automatically"]
    automatic_translated_field_locales[attr_name].each do |to_locale|
      next if to_locale == from_locale
      automatic_translation_for(to_locale).translate(attr_name)
    end
  end
  true
end