Class: PageMeta::Translator
- Inherits:
-
Object
- Object
- PageMeta::Translator
- Includes:
- ActionView::Helpers::TranslationHelper
- Defined in:
- lib/page_meta/translator.rb
Instance Attribute Summary collapse
-
#html ⇒ Object
readonly
Returns the value of attribute html.
-
#naming ⇒ Object
readonly
Returns the value of attribute naming.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
-
#initialize(scope, naming, options = {}) ⇒ Translator
constructor
A new instance of Translator.
- #override_options ⇒ Object
- #simple ⇒ Object
- #to_s ⇒ Object
- #translation_scope ⇒ Object
Constructor Details
#initialize(scope, naming, options = {}) ⇒ Translator
Returns a new instance of Translator.
9 10 11 12 13 14 |
# File 'lib/page_meta/translator.rb', line 9 def initialize(scope, naming, = {}) @scope = scope @naming = naming @html = [:html] @options = end |
Instance Attribute Details
#html ⇒ Object (readonly)
Returns the value of attribute html.
7 8 9 |
# File 'lib/page_meta/translator.rb', line 7 def html @html end |
#naming ⇒ Object (readonly)
Returns the value of attribute naming.
7 8 9 |
# File 'lib/page_meta/translator.rb', line 7 def naming @naming end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/page_meta/translator.rb', line 7 def @options end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
7 8 9 |
# File 'lib/page_meta/translator.rb', line 7 def scope @scope end |
Instance Method Details
#override_options ⇒ Object
46 47 48 |
# File 'lib/page_meta/translator.rb', line 46 def .merge(default: "") end |
#simple ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/page_meta/translator.rb', line 50 def simple translation = "" translation_scope.each do |scope| translation = t("#{scope}_html", **) if html translation = t(scope, **) if translation.blank? break if translation.present? end translation end |
#to_s ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/page_meta/translator.rb', line 16 def to_s return "" if simple.blank? value = simple [ # Set base scope for controller t( "page_meta.#{naming.controller}.#{scope}_base", value:, ** ), # Set base scope for action t( "page_meta.#{naming.controller}.#{naming.action}.#{scope}_base", value:, ** ), # Set base scope t("page_meta.#{scope}_base", value:, **, default: value) ].reject(&:blank?).first || "" end |
#translation_scope ⇒ Object
42 43 44 |
# File 'lib/page_meta/translator.rb', line 42 def translation_scope ["page_meta.#{naming.controller}.#{naming.action}.#{scope}"] end |