Class: Rosette::Core::Translation

Inherits:
Object
  • Object
show all
Includes:
TranslationToHash
Defined in:
lib/rosette/core/extractor/translation.rb

Overview

Represents a translation. Translations always have an associated phrase, a locale, and some translated text.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TranslationToHash

#to_h

Constructor Details

#initialize(phrase, locale, translation) ⇒ Translation

Creates a new translation object.

Parameters:

  • phrase (Phrase)

    The associated phrase object.

  • locale (String)

    The locale code.

  • translation (String)

    The translated text.


25
26
27
28
29
# File 'lib/rosette/core/extractor/translation.rb', line 25

def initialize(phrase, locale, translation)
  @phrase = phrase
  @locale = locale
  @translation = translation
end

Instance Attribute Details

#localeString (readonly)

Returns the locale code.

Returns:

  • (String)

    the locale code.


15
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
41
# File 'lib/rosette/core/extractor/translation.rb', line 15

class Translation
  include TranslationToHash

  attr_reader :phrase, :locale, :translation

  # Creates a new translation object.
  #
  # @param [Phrase] phrase The associated phrase object.
  # @param [String] locale The locale code.
  # @param [String] translation The translated text.
  def initialize(phrase, locale, translation)
    @phrase = phrase
    @locale = locale
    @translation = translation
  end

  # Turns this translation object into a hash.
  #
  # @return [Hash] a hash with +phrase+ as a hash, +locale+, and
  #   +translation+.
  def self.from_h(hash)
    new(
      Phrase.from_h(hash[:phrase]),
      hash[:locale], hash[:translation]
    )
  end
end

#phrasePhrase (readonly)

Returns the associated phrase object.

Returns:

  • (Phrase)

    the associated phrase object.


15
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
41
# File 'lib/rosette/core/extractor/translation.rb', line 15

class Translation
  include TranslationToHash

  attr_reader :phrase, :locale, :translation

  # Creates a new translation object.
  #
  # @param [Phrase] phrase The associated phrase object.
  # @param [String] locale The locale code.
  # @param [String] translation The translated text.
  def initialize(phrase, locale, translation)
    @phrase = phrase
    @locale = locale
    @translation = translation
  end

  # Turns this translation object into a hash.
  #
  # @return [Hash] a hash with +phrase+ as a hash, +locale+, and
  #   +translation+.
  def self.from_h(hash)
    new(
      Phrase.from_h(hash[:phrase]),
      hash[:locale], hash[:translation]
    )
  end
end

#translationString (readonly)

Returns the translation text.

Returns:

  • (String)

    the translation text.


15
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
41
# File 'lib/rosette/core/extractor/translation.rb', line 15

class Translation
  include TranslationToHash

  attr_reader :phrase, :locale, :translation

  # Creates a new translation object.
  #
  # @param [Phrase] phrase The associated phrase object.
  # @param [String] locale The locale code.
  # @param [String] translation The translated text.
  def initialize(phrase, locale, translation)
    @phrase = phrase
    @locale = locale
    @translation = translation
  end

  # Turns this translation object into a hash.
  #
  # @return [Hash] a hash with +phrase+ as a hash, +locale+, and
  #   +translation+.
  def self.from_h(hash)
    new(
      Phrase.from_h(hash[:phrase]),
      hash[:locale], hash[:translation]
    )
  end
end

Class Method Details

.from_h(hash) ⇒ Hash

Turns this translation object into a hash.

Returns:

  • (Hash)

    a hash with phrase as a hash, locale, and translation.


35
36
37
38
39
40
# File 'lib/rosette/core/extractor/translation.rb', line 35

def self.from_h(hash)
  new(
    Phrase.from_h(hash[:phrase]),
    hash[:locale], hash[:translation]
  )
end