Class: Multilocale::Phrase
- Inherits:
-
Object
- Object
- Multilocale::Phrase
- Defined in:
- lib/multilocale/phrase.rb
Overview
One {key, value, language} row. A key translated into 12 locales is 12
phrases, not one phrase with 12 values — every API call and every error
message counts rows, not keys.
A row can belong to several projects at once (projects). Editing it edits
it for all of them, and deleting a key deletes every row it matches
including the shared ones.
Constant Summary collapse
- ATTRIBUTE_NAMES =
{ id: "_id", key: "key", value: "value", language: "language", projects: "projects", projects_ids: "projectsIds", machine_translated: "machineTranslated", model: "model" }.freeze
Instance Attribute Summary collapse
-
#to_h ⇒ Object
readonly
Returns the value of attribute to_h.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #[](key) ⇒ Object
- #creation_time ⇒ Object
- #hash ⇒ Object
- #id ⇒ Object
-
#initialize(attributes) ⇒ Phrase
constructor
A new instance of Phrase.
- #inspect ⇒ Object
- #key ⇒ Object
- #language ⇒ Object
- #last_edit_time ⇒ Object
-
#machine_translated? ⇒ Boolean
googleTranslateis the pre-2024 spelling and is still the only provenance flag on older rows, so a reader that only looks atmachineTranslatedreports human-written text that never was. -
#model ⇒ Object
Which engine produced it, when it was machine translated.
- #organization_id ⇒ Object
- #projects ⇒ Object
- #projects_ids ⇒ Object
- #value ⇒ Object
Constructor Details
Instance Attribute Details
#to_h ⇒ Object (readonly)
Returns the value of attribute to_h.
12 13 14 |
# File 'lib/multilocale/phrase.rb', line 12 def to_h @to_h end |
Class Method Details
.to_api(attributes) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/multilocale/phrase.rb', line 95 def self.to_api(attributes) return attributes.to_h if attributes.is_a?(Phrase) attributes.each_with_object({}) do |(key, value), document| document[ATTRIBUTE_NAMES[key] || key.to_s] = value end end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
71 72 73 |
# File 'lib/multilocale/phrase.rb', line 71 def ==(other) other.is_a?(Phrase) && other.to_h == to_h end |
#[](key) ⇒ Object
67 68 69 |
# File 'lib/multilocale/phrase.rb', line 67 def [](key) @to_h[key.to_s] end |
#creation_time ⇒ Object
59 60 61 |
# File 'lib/multilocale/phrase.rb', line 59 def creation_time @to_h["creationTime"] end |
#hash ⇒ Object
76 77 78 |
# File 'lib/multilocale/phrase.rb', line 76 def hash to_h.hash end |
#id ⇒ Object
18 19 20 |
# File 'lib/multilocale/phrase.rb', line 18 def id @to_h["_id"] end |
#inspect ⇒ Object
80 81 82 |
# File 'lib/multilocale/phrase.rb', line 80 def inspect "#<Multilocale::Phrase key=#{key.inspect} language=#{language.inspect} value=#{value.inspect}>" end |
#key ⇒ Object
22 23 24 |
# File 'lib/multilocale/phrase.rb', line 22 def key @to_h["key"] end |
#language ⇒ Object
30 31 32 |
# File 'lib/multilocale/phrase.rb', line 30 def language @to_h["language"] end |
#last_edit_time ⇒ Object
63 64 65 |
# File 'lib/multilocale/phrase.rb', line 63 def last_edit_time @to_h["lastEditTime"] end |
#machine_translated? ⇒ Boolean
googleTranslate is the pre-2024 spelling and is still the only
provenance flag on older rows, so a reader that only looks at
machineTranslated reports human-written text that never was.
49 50 51 52 |
# File 'lib/multilocale/phrase.rb', line 49 def machine_translated? value = @to_h.fetch("machineTranslated") { @to_h["googleTranslate"] } !!value end |
#model ⇒ Object
Which engine produced it, when it was machine translated.
55 56 57 |
# File 'lib/multilocale/phrase.rb', line 55 def model @to_h["model"] end |
#organization_id ⇒ Object
42 43 44 |
# File 'lib/multilocale/phrase.rb', line 42 def organization_id @to_h["organizationId"] end |
#projects ⇒ Object
34 35 36 |
# File 'lib/multilocale/phrase.rb', line 34 def projects @to_h["projects"] || [] end |
#projects_ids ⇒ Object
38 39 40 |
# File 'lib/multilocale/phrase.rb', line 38 def projects_ids @to_h["projectsIds"] || [] end |
#value ⇒ Object
26 27 28 |
# File 'lib/multilocale/phrase.rb', line 26 def value @to_h["value"] end |