Class: OneSky::Translation
- Inherits:
-
Object
- Object
- OneSky::Translation
- Defined in:
- lib/one_sky/translation.rb
Overview
Implements the Translation I/O API for a given :platform_id
Constant Summary collapse
- YAML_FORMAT =
"RUBY_YAML".freeze
- PO_FORMAT =
"GNU_PO".freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#platform_id ⇒ Object
readonly
Returns the value of attribute platform_id.
Instance Method Summary collapse
-
#download_po(locale) ⇒ Object
Download strings and translations as string file.
-
#download_yaml(locale) ⇒ Object
Download strings and translations as string file.
-
#initialize(platform_id, client) ⇒ Translation
constructor
Provide the id of the platform, together with an instance of OneSky::Client.
-
#input_phrases(phrases) ⇒ Object
Add new strings to be translated.
-
#input_string(string) ⇒ Object
Add new strings to be translated.
-
#input_strings(strings) ⇒ Object
Add new strings to be translated.
-
#output ⇒ Object
Get the strings with translations.
-
#output_for_locale(locale) ⇒ Object
Get the strings for a particular locale.
-
#translate(string_key, locale, translation) ⇒ Object
Add translation to a string.
-
#upload_po(file) ⇒ Object
Upload a string file to add new strings.
-
#upload_yaml(file) ⇒ Object
Upload a string file to add new strings.
Constructor Details
#initialize(platform_id, client) ⇒ Translation
Provide the id of the platform, together with an instance of OneSky::Client.
9 10 11 12 |
# File 'lib/one_sky/translation.rb', line 9 def initialize(platform_id, client) @platform_id = platform_id @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/one_sky/translation.rb', line 6 def client @client end |
#platform_id ⇒ Object (readonly)
Returns the value of attribute platform_id.
6 7 8 |
# File 'lib/one_sky/translation.rb', line 6 def platform_id @platform_id end |
Instance Method Details
#download_po(locale) ⇒ Object
Download strings and translations as string file. In GNU_PO format.
71 72 73 |
# File 'lib/one_sky/translation.rb', line 71 def download_po(locale) download_file(locale, PO_FORMAT) end |
#download_yaml(locale) ⇒ Object
Download strings and translations as string file. In RUBY_YAML format.
66 67 68 |
# File 'lib/one_sky/translation.rb', line 66 def download_yaml(locale) download_file(locale, YAML_FORMAT) end |
#input_phrases(phrases) ⇒ Object
Add new strings to be translated.
expects a hash of {"string_key1" => "String 1", "string_key2" => "String 2"}
28 29 30 31 32 33 |
# File 'lib/one_sky/translation.rb', line 28 def input_phrases(phrases) strings = phrases.map do |string_key, string| {:string_key => string_key, :string => string} end input_strings(strings) end |
#input_string(string) ⇒ Object
Add new strings to be translated.
expects a string, or a hash of {:string_key => k, :string => v}
22 23 24 |
# File 'lib/one_sky/translation.rb', line 22 def input_string(string) input_strings([string]) end |
#input_strings(strings) ⇒ Object
Add new strings to be translated.
expects an array of strings, or an array of hashes [{:string_key => k, :string => v}, ...]
16 17 18 |
# File 'lib/one_sky/translation.rb', line 16 def input_strings(strings) post("string/input", :input => format_input_strings(strings)) end |
#output ⇒ Object
Get the strings with translations.
41 42 43 |
# File 'lib/one_sky/translation.rb', line 41 def output get_output end |
#output_for_locale(locale) ⇒ Object
Get the strings for a particular locale.
46 47 48 |
# File 'lib/one_sky/translation.rb', line 46 def output_for_locale(locale) get_output(locale) end |
#translate(string_key, locale, translation) ⇒ Object
Add translation to a string.
36 37 38 |
# File 'lib/one_sky/translation.rb', line 36 def translate(string_key, locale, translation) post("string/translate", :"string-key" => string_key, :locale => locale, :translation => translation) end |
#upload_po(file) ⇒ Object
Upload a string file to add new strings. In GNU_PO format.
61 62 63 |
# File 'lib/one_sky/translation.rb', line 61 def upload_po(file) upload_file(file, PO_FORMAT) end |
#upload_yaml(file) ⇒ Object
Upload a string file to add new strings. In RUBY_YAML format.
56 57 58 |
# File 'lib/one_sky/translation.rb', line 56 def upload_yaml(file) upload_file(file, YAML_FORMAT) end |