Class: Translatomatic::Model::Locale

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/translatomatic/model/locale.rb

Overview

Locale database record. Used to store translations in the database.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_tag(tag) ⇒ Translatomatic::Model::Locale

Create a locale record from an I18n::Locale::Tag object or string

Returns:



12
13
14
15
16
17
# File 'lib/translatomatic/model/locale.rb', line 12

def self.from_tag(tag)
  tag = Translatomatic::Locale.parse(tag)
  find_or_create_by!(
    language: tag.language, script: tag.script, region: tag.region
  )
end

Instance Method Details

#to_sString

Returns Locale as string.

Returns:

  • (String)

    Locale as string



20
21
22
# File 'lib/translatomatic/model/locale.rb', line 20

def to_s
  [language, script, region].compact.join('-')
end