Class: Rosette::Core::Commands::TranslationLookupCommand

Inherits:
GitCommand show all
Includes:
WithLocale, WithRef, WithRepoName
Defined in:
lib/rosette/core/commands/translations/translation_lookup_command.rb

Overview

Returns the translation for the given phrase and locale combination.

Examples:

cmd = TranslationLookupCommand.new(configuration)
  .set_repo_name('my_repo')
  .set_locale('es')
  .set_meta_key('my.phrase')
  .set_key('I am a phrase')

cmd.execute# => "Soy una frase"

Instance Attribute Summary collapse

Attributes included from WithRef

#commit_str

Attributes inherited from Command

#configuration

Instance Method Summary collapse

Methods included from WithLocale

#set_locale

Methods included from WithRef

#commit_id, #set_commit_id, #set_ref

Methods included from WithRepoName

#set_repo_name

Methods inherited from GitCommand

#valid?

Methods inherited from Command

#initialize, #messages, #valid?, validate, validators

Constructor Details

This class inherits a constructor from Rosette::Core::Commands::Command

Instance Attribute Details

#keyString (readonly)

Returns the phrase key.

Returns:

  • (String)

    the phrase key.


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rosette/core/commands/translations/translation_lookup_command.rb', line 31

class TranslationLookupCommand < GitCommand
  attr_reader :key, :meta_key

  include WithRepoName
  include WithRef
  include WithLocale

  def set_key(key)
    @key = key
    self
  end

  def set_meta_key(meta_key)
    @meta_key = meta_key
    self
  end

  def execute
    phrase = datastore.lookup_phrase(repo_name, key, meta_key, commit_id)
    repo_config.tms.lookup_translation(locale_obj, phrase)
  end

  protected

  def repo_config
    configuration.get_repo(repo_name)
  end

  def locale_obj
    repo_config.locales.find { |l| l.code == locale }
  end
end

#localeString (readonly)

Returns the locale of the translation to look up.

Returns:

  • (String)

    the locale of the translation to look up.


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rosette/core/commands/translations/translation_lookup_command.rb', line 31

class TranslationLookupCommand < GitCommand
  attr_reader :key, :meta_key

  include WithRepoName
  include WithRef
  include WithLocale

  def set_key(key)
    @key = key
    self
  end

  def set_meta_key(meta_key)
    @meta_key = meta_key
    self
  end

  def execute
    phrase = datastore.lookup_phrase(repo_name, key, meta_key, commit_id)
    repo_config.tms.lookup_translation(locale_obj, phrase)
  end

  protected

  def repo_config
    configuration.get_repo(repo_name)
  end

  def locale_obj
    repo_config.locales.find { |l| l.code == locale }
  end
end

#meta_keyString (readonly)

Returns the phrase meta key.

Returns:

  • (String)

    the phrase meta key.


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rosette/core/commands/translations/translation_lookup_command.rb', line 31

class TranslationLookupCommand < GitCommand
  attr_reader :key, :meta_key

  include WithRepoName
  include WithRef
  include WithLocale

  def set_key(key)
    @key = key
    self
  end

  def set_meta_key(meta_key)
    @meta_key = meta_key
    self
  end

  def execute
    phrase = datastore.lookup_phrase(repo_name, key, meta_key, commit_id)
    repo_config.tms.lookup_translation(locale_obj, phrase)
  end

  protected

  def repo_config
    configuration.get_repo(repo_name)
  end

  def locale_obj
    repo_config.locales.find { |l| l.code == locale }
  end
end

#repo_nameString (readonly)

Returns the name of the repo the phrase (and therefore the translation) belongs to.

Returns:

  • (String)

    the name of the repo the phrase (and therefore the translation) belongs to.


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rosette/core/commands/translations/translation_lookup_command.rb', line 31

class TranslationLookupCommand < GitCommand
  attr_reader :key, :meta_key

  include WithRepoName
  include WithRef
  include WithLocale

  def set_key(key)
    @key = key
    self
  end

  def set_meta_key(meta_key)
    @meta_key = meta_key
    self
  end

  def execute
    phrase = datastore.lookup_phrase(repo_name, key, meta_key, commit_id)
    repo_config.tms.lookup_translation(locale_obj, phrase)
  end

  protected

  def repo_config
    configuration.get_repo(repo_name)
  end

  def locale_obj
    repo_config.locales.find { |l| l.code == locale }
  end
end

Instance Method Details

#executeObject


48
49
50
51
# File 'lib/rosette/core/commands/translations/translation_lookup_command.rb', line 48

def execute
  phrase = datastore.lookup_phrase(repo_name, key, meta_key, commit_id)
  repo_config.tms.lookup_translation(locale_obj, phrase)
end

#set_key(key) ⇒ Object


38
39
40
41
# File 'lib/rosette/core/commands/translations/translation_lookup_command.rb', line 38

def set_key(key)
  @key = key
  self
end

#set_meta_key(meta_key) ⇒ Object


43
44
45
46
# File 'lib/rosette/core/commands/translations/translation_lookup_command.rb', line 43

def set_meta_key(meta_key)
  @meta_key = meta_key
  self
end