Module: Postnhost::SchemaLocalizable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/postnhost/schema_localizable.rb
Instance Method Summary collapse
- #schema_default_locale_key ⇒ Object
- #schema_locale_overrides_hash ⇒ Object
- #schema_text_for(locale:, key:, fallback:) ⇒ Object
- #schema_translations_for(locale) ⇒ Object
Instance Method Details
#schema_default_locale_key ⇒ Object
24 25 26 |
# File 'app/models/concerns/postnhost/schema_localizable.rb', line 24 def schema_default_locale_key @schema_default_locale_key ||= Postnhost::Language.find_by(default: true)&.html_lang.presence || I18n.default_locale.to_s end |
#schema_locale_overrides_hash ⇒ Object
5 6 7 |
# File 'app/models/concerns/postnhost/schema_localizable.rb', line 5 def schema_locale_overrides_hash schema_locale_overrides.is_a?(Hash) ? schema_locale_overrides.deep_stringify_keys : {} end |
#schema_text_for(locale:, key:, fallback:) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'app/models/concerns/postnhost/schema_localizable.rb', line 13 def schema_text_for(locale:, key:, fallback:) field = key.to_s value = schema_translations_for(locale)[field].presence return value if value.present? default_locale_value = schema_translations_for(schema_default_locale_key)[field].presence return default_locale_value if default_locale_value.present? fallback end |
#schema_translations_for(locale) ⇒ Object
9 10 11 |
# File 'app/models/concerns/postnhost/schema_localizable.rb', line 9 def schema_translations_for(locale) schema_locale_overrides_hash.fetch(locale.to_s, {}) end |