Class: TextRecord

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/text_record.rb

Overview

The TextRecord model handels all text related informations of a nearspeak tag.

Instance Method Summary (collapse)

Instance Method Details

- (Object) get_original_text

Returns the original text.



70
71
72
# File 'app/models/text_record.rb', line 70

def get_original_text
  original_text.text
end

- (Object) get_translation(lang_code)

Returns the translated text, or the original text if the language is the current

Parameters:

  • lang_code (String)

    The language code.



22
23
24
25
26
27
28
29
30
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
63
64
65
66
# File 'app/models/text_record.rb', line 22

def get_translation(lang_code)
  # format language code to a valid bing translate format
  lang_code_cut = TranslationsHelper.cut_country lang_code
  if lang_code_cut.nil?
    return nil
  end

  # check if this is a valid language code
  unless TranslationsHelper.is_valid_language lang_code_cut
    return nil
  end

  # check if original text is in the new language
  unless original_text.nil?
    lang_code_original_cut = TranslationsHelper.cut_country original_text.lang_code

    if original_text.lang_code == lang_code
      return original_text.text
    elsif original_text.lang_code == lang_code_cut
      add_translation(original_text.text, lang_code)
      return original_text.text
    elsif lang_code_original_cut == lang_code_cut
      add_translation(original_text.text, lang_code)
      return original_text.text
    end
  end

  # check if translation is already available, if not translate it via bing
  trans = translations.find_by_lang_code(lang_code)
  if trans.nil?
    trans_cut = translations.find_by_lang_code(lang_code_cut)

    # check if there is a translation only with the language code, without country code
    if trans_cut.nil?
      return translate_into_lang_code(lang_code)
    else
      add_translation(trans_cut.text, lang_code)
      return trans_cut.text
    end

    return translate_into_lang_code(lang_code)
  else
    return trans.text
  end
end

- (Object) image_url

Returrns the image url.



76
77
78
# File 'app/models/text_record.rb', line 76

def image_url
  image_uri
end

- (Object) text_url

Returns the text url.



82
83
84
# File 'app/models/text_record.rb', line 82

def text_url
  link_uri
end