Class: Fastlane::Helper::TranslationProgressHelper::TranslationProgressTracker
- Inherits:
-
Object
- Object
- Fastlane::Helper::TranslationProgressHelper::TranslationProgressTracker
- Defined in:
- lib/fastlane/plugin/translate/helper/translation_progress_helper.rb
Instance Method Summary collapse
- #cleanup ⇒ Object
- #get_translated_strings ⇒ Object
- #has_progress? ⇒ Boolean
-
#initialize(xcstrings_path, target_language) ⇒ TranslationProgressTracker
constructor
A new instance of TranslationProgressTracker.
- #load_progress ⇒ Object
- #progress_summary ⇒ Object
- #save_translated_strings(translated_strings) ⇒ Object
Constructor Details
#initialize(xcstrings_path, target_language) ⇒ TranslationProgressTracker
Returns a new instance of TranslationProgressTracker.
17 18 19 20 |
# File 'lib/fastlane/plugin/translate/helper/translation_progress_helper.rb', line 17 def initialize(xcstrings_path, target_language) @progress_file = "#{xcstrings_path}.translation_progress_#{target_language}.json" @translated_strings = {} end |
Instance Method Details
#cleanup ⇒ Object
55 56 57 58 59 60 |
# File 'lib/fastlane/plugin/translate/helper/translation_progress_helper.rb', line 55 def cleanup if File.exist?(@progress_file) File.delete(@progress_file) UI.verbose('🗑️ Cleaned up progress file') end end |
#get_translated_strings ⇒ Object
62 63 64 |
# File 'lib/fastlane/plugin/translate/helper/translation_progress_helper.rb', line 62 def get_translated_strings load_progress['translated_strings'] end |
#has_progress? ⇒ Boolean
32 33 34 |
# File 'lib/fastlane/plugin/translate/helper/translation_progress_helper.rb', line 32 def has_progress? File.exist?(@progress_file) && load_progress['translated_strings'].any? end |
#load_progress ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fastlane/plugin/translate/helper/translation_progress_helper.rb', line 36 def load_progress return default_progress unless File.exist?(@progress_file) begin JSON.parse(File.read(@progress_file)) rescue JSON::ParserError => e UI.important("⚠️ Corrupted progress file, starting fresh: #{e.}") default_progress end end |
#progress_summary ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/fastlane/plugin/translate/helper/translation_progress_helper.rb', line 47 def progress_summary progress = load_progress { translated_count: progress['translated_strings'].size, last_updated: progress['last_updated'] } end |
#save_translated_strings(translated_strings) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/fastlane/plugin/translate/helper/translation_progress_helper.rb', line 22 def save_translated_strings(translated_strings) progress = load_progress progress['translated_strings'].merge!(translated_strings) progress['last_updated'] = Time.now.iso8601 progress['total_translated'] = progress['translated_strings'].size File.write(@progress_file, JSON.pretty_generate(progress)) UI.verbose("💾 Saved progress: #{translated_strings.size} new translations") end |