Module: Translation
- Included in:
- String
- Defined in:
- lib/translate_self/translation.rb
Overview
The part where the actual translation happens.
Constant Summary collapse
- LANGUAGES =
%w[bg cs da de el en es et fi fr hu it ja lt lv nl pl pt ro ru sk sl sv zh].freeze
Instance Attribute Summary collapse
-
#language ⇒ Object
Returns the value of attribute language.
Instance Method Summary collapse
- #available_languages ⇒ Object
-
#lan ⇒ String
Translates the string itself to a language the user wants to translate it to.
- #to_language ⇒ Object
- #to_language=(language) ⇒ Object
-
#translate ⇒ String
Translates self to the desired language.
-
#translate! ⇒ String
Replaces self with the translation.
Instance Attribute Details
#language ⇒ Object
Returns the value of attribute language.
6 7 8 |
# File 'lib/translate_self/translation.rb', line 6 def language @language end |
Instance Method Details
#available_languages ⇒ Object
17 18 19 |
# File 'lib/translate_self/translation.rb', line 17 def available_languages LANGUAGES end |
#lan ⇒ String
Translates the string itself to a language the user wants to translate it to. Sample usage: ‘hello’.translate_to_fi # Hei
53 54 55 56 57 58 |
# File 'lib/translate_self/translation.rb', line 53 LANGUAGES.each do |lan| define_method("translate_to_#{lan}".to_sym) do |language = lan| call_deepl(self.language, language) end alias_method "to_#{lan}".to_sym, "translate_to_#{lan}".to_sym end |
#to_language ⇒ Object
8 9 10 |
# File 'lib/translate_self/translation.rb', line 8 def to_language @to_language || 'fi' end |
#to_language=(language) ⇒ Object
12 13 14 15 |
# File 'lib/translate_self/translation.rb', line 12 def to_language=(language) defroster if needs_defrosting? @to_language = LANGUAGES.include?(language) ? language : 'fi' end |
#translate ⇒ String
Translates self to the desired language. \ Sample usage: hello = ‘hello’\ hello.to_language = ‘fi’ moi = hello.translate pp moi # ‘Hei’
29 30 31 |
# File 'lib/translate_self/translation.rb', line 29 def translate call_deepl(language, to_language) end |
#translate! ⇒ String
Replaces self with the translation. \ Sample usage: hello = ‘hello’\ hello.to_language = ‘fi’ hello.translate! pp hello # ‘Hei’
41 42 43 44 |
# File 'lib/translate_self/translation.rb', line 41 def translate! defroster if needs_defrosting? replace translate end |