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, options = {}) ⇒ Object
Add new strings to be translated.
-
#input_string(string, options = {}) ⇒ Object
Add new strings to be translated.
-
#input_strings(strings, options = {}) ⇒ 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.
75 76 77 |
# File 'lib/one_sky/translation.rb', line 75 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.
70 71 72 |
# File 'lib/one_sky/translation.rb', line 70 def download_yaml(locale) download_file(locale, YAML_FORMAT) end |
#input_phrases(phrases, options = {}) ⇒ Object
Add new strings to be translated.
expects a hash of {"string_key1" => "String 1", "string_key2" => "String 2"}
32 33 34 35 36 37 |
# File 'lib/one_sky/translation.rb', line 32 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, options = {}) ⇒ Object
Add new strings to be translated.
expects a string, or a hash of {:string_key => k, :string => v}
26 27 28 |
# File 'lib/one_sky/translation.rb', line 26 def input_string(string, ={}) input_strings([string], ) end |
#input_strings(strings, options = {}) ⇒ 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 19 20 21 22 |
# File 'lib/one_sky/translation.rb', line 16 def input_strings(strings, ={}) params = {:input => format_input_strings(strings)} if [:tag] # include the :tag if there is one params[:tag] = [:tag] end post("string/input", params) end |
#output ⇒ Object
Get the strings with translations.
45 46 47 |
# File 'lib/one_sky/translation.rb', line 45 def output get_output end |
#output_for_locale(locale) ⇒ Object
Get the strings for a particular locale.
50 51 52 |
# File 'lib/one_sky/translation.rb', line 50 def output_for_locale(locale) get_output(locale) end |
#translate(string_key, locale, translation) ⇒ Object
Add translation to a string.
40 41 42 |
# File 'lib/one_sky/translation.rb', line 40 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.
65 66 67 |
# File 'lib/one_sky/translation.rb', line 65 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.
60 61 62 |
# File 'lib/one_sky/translation.rb', line 60 def upload_yaml(file) upload_file(file, YAML_FORMAT) end |