class SmartlingRails::SmartlingProcessor
Attributes
my_smartling[RW]
Public Class Methods
new()
click to toggle source
# File lib/smartling_rails/smartling_processor.rb, line 14 def initialize @my_smartling = Smartling::File.new(apiKey: SmartlingRails.api_key, projectId: SmartlingRails.project_id) SmartlingRails.print_msg "You are working with this remote file on smartling: #{ upload_file_path }", true SmartlingRails.print_msg "Smartling Ruby client #{ Smartling::VERSION }" end
Public Instance Methods
check_file_status(language_code)
click to toggle source
# File lib/smartling_rails/smartling_processor.rb, line 31 def check_file_status(language_code) res = @my_smartling.status(upload_file_path, locale: language_code) total_strings = res['stringCount'].to_i completed_strings = res['completedStringCount'].to_i file_complete = completed_strings >= total_strings SmartlingRails.print_msg "#{language_code} completed: #{ file_complete } (#{ completed_strings } / #{ total_strings })" rescue Exception => e puts e.message end
current_branch()
click to toggle source
# File lib/smartling_rails/smartling_processor.rb, line 88 def current_branch b = `git branch`.split("\n").delete_if { |i| i[0] != '*' } b.first.gsub('* ', '') end
fetch_fix_and_save_file_for_locale(locale_codes)
click to toggle source
# File lib/smartling_rails/smartling_processor.rb, line 66 def fetch_fix_and_save_file_for_locale(locale_codes) smartling_file = get_file_for_locale(locale_codes) smartling_file.fix_file_issues save_to_local_file(smartling_file.file_contents, locale_codes['custom']) end
file_statuses()
click to toggle source
# File lib/smartling_rails/smartling_processor.rb, line 20 def file_statuses SmartlingRails.print_msg("Checking status for #{ supported_locales }", true) SmartlingRails.locales.each do | _language, codes | check_file_status(codes['smartling']) end end
files()
click to toggle source
# File lib/smartling_rails/smartling_processor.rb, line 59 def files SmartlingRails.print_msg("Checking status for #{ supported_locales }", true) SmartlingRails.locales.each do | _language, locale_codes | fetch_fix_and_save_file_for_locale(locale_codes) end end
get_file_for_locale(locale_codes)
click to toggle source
# File lib/smartling_rails/smartling_processor.rb, line 72 def get_file_for_locale(locale_codes) smartling_file = SmartlingFile.new('', locale_codes) SmartlingRails.print_msg "Downloading #{ locale_codes['smartling'] }:", true begin smartling_file.file_contents = @my_smartling.download(upload_file_path, locale: locale_codes['smartling']) SmartlingRails.print_msg 'file loaded...' rescue Exception => e SmartlingRails.print_msg e end smartling_file end
local_file_path_for_locale(cb_locale)
click to toggle source
# File lib/smartling_rails/smartling_processor.rb, line 51 def local_file_path_for_locale(cb_locale) "config/locales/#{ cb_locale }.yml" end
put_files()
click to toggle source
# File lib/smartling_rails/smartling_processor.rb, line 41 def put_files SmartlingRails.print_msg('Uploading the english file to smartling to process:', true) upload_english_file end
save_to_local_file(file_contents, cb_locale)
click to toggle source
# File lib/smartling_rails/smartling_processor.rb, line 84 def save_to_local_file(file_contents, cb_locale) File.open(local_file_path_for_locale(cb_locale), 'w') { |file| file.write(file_contents) } end
supported_locales()
click to toggle source
# File lib/smartling_rails/smartling_processor.rb, line 27 def supported_locales SmartlingRails.locales.map { |language, codes| language.to_s + ' ' + codes['smartling'] } end
upload_english_file()
click to toggle source
# File lib/smartling_rails/smartling_processor.rb, line 46 def upload_english_file SmartlingRails.print_msg("uploading #{ local_file_path_for_locale('en-us') } to #{ upload_file_path }") @my_smartling.upload(local_file_path_for_locale('en-us'), upload_file_path, 'YAML') end
upload_file_path()
click to toggle source
# File lib/smartling_rails/smartling_processor.rb, line 55 def upload_file_path "/files/[#{ SmartlingRails.configuration.rails_app_name || 'app' }]-[#{ current_branch }]-en-us.yml" end