Class: LocaleBase::TranslationTracker
- Inherits:
-
Object
- Object
- LocaleBase::TranslationTracker
- Defined in:
- lib/locale_base/translation_tracker.rb
Overview
analyze performance implications TODO consider using a hash instead of any array - may have performance help on many duplicates in yaml file - is that a use case that’s valid? is there a better structure?
Instance Method Summary collapse
-
#hold(value) ⇒ Object
for things that should be hidden and not translated return they key that will be put in place and unheld later.
-
#initialize ⇒ TranslationTracker
constructor
A new instance of TranslationTracker.
- #retrieve(token) ⇒ Object
- #track(value) ⇒ Object
-
#translate_all(options) ⇒ Object
translate every token TODO make translate! in easy translate TODO move out of this class and into the Base**.
- #unhold(key) ⇒ Object
Constructor Details
#initialize ⇒ TranslationTracker
Returns a new instance of TranslationTracker.
11 12 13 14 |
# File 'lib/locale_base/translation_tracker.rb', line 11 def initialize @tracking_array = [] @holdings = {} end |
Instance Method Details
#hold(value) ⇒ Object
for things that should be hidden and not translated return they key that will be put in place and unheld later
Note: this workaround is needed due to how google translate doesn’t cleanly handle .notranslate spans
28 29 30 31 32 |
# File 'lib/locale_base/translation_tracker.rb', line 28 def hold(value) key = "h%020x" % rand(1 << 80) @holdings[key] = value key end |
#retrieve(token) ⇒ Object
43 44 45 |
# File 'lib/locale_base/translation_tracker.rb', line 43 def retrieve(token) @tracking_array[token.position] end |
#track(value) ⇒ Object
38 39 40 41 |
# File 'lib/locale_base/translation_tracker.rb', line 38 def track(value) @tracking_array << value TrackingToken.new(self, @tracking_array.size - 1) end |
#translate_all(options) ⇒ Object
translate every token TODO make translate! in easy translate TODO move out of this class and into the Base**
19 20 21 |
# File 'lib/locale_base/translation_tracker.rb', line 19 def translate_all() @tracking_array = EasyTranslate.translate(@tracking_array, .merge(:html => true)) end |
#unhold(key) ⇒ Object
34 35 36 |
# File 'lib/locale_base/translation_tracker.rb', line 34 def unhold(key) @holdings[key] end |