Module: Internationalize::Model

Extended by:
ActiveSupport::Concern
Includes:
Validations
Defined in:
lib/internationalize/model.rb

Overview

Mixin for ActiveRecord models to enable internationalization

Examples:

class Article < ApplicationRecord
  include Internationalize::Model
  international :title, :description
end

# Querying
Article.i18n_where(title: "Hello")
Article.i18n_where(title: "hello", match: :partial)
Article.international_order(:title, :desc)

Constant Summary collapse

VALID_DIRECTIONS =
["ASC", "DESC"].freeze

Instance Method Summary collapse

Instance Method Details

#translated?(attr, locale) ⇒ Boolean

Check if a translation exists for a specific locale



437
438
439
440
# File 'lib/internationalize/model.rb', line 437

def translated?(attr, locale)
  translations = read_attribute("#{attr}_translations")
  translations[locale.to_s].present?
end

#translated_locales(attr) ⇒ Object

Returns all locales that have a translation for an attribute



443
444
445
446
# File 'lib/internationalize/model.rb', line 443

def translated_locales(attr)
  translations = read_attribute("#{attr}_translations")
  translations.filter_map { |k, v| k.to_sym if v.present? }
end