Class: Onesky::Rails::FileClient
- Defined in:
- lib/onesky/rails/file_client.rb
Constant Summary collapse
- FILE_FORMAT =
'RUBY_YAML'
- ENCODING =
'UTF-8'
- DIR_PREFIX =
'onesky_'
- TRANSLATION_NOTICE =
<<-NOTICE # This file is generated by onesky-rails gem and will be overwritten at the next download # Therefore, you should not modify this file # If you want to modify the translation, please do it at OneSky platform # If you still want to modify this file directly, please upload this file to OneSky platform after modification in order to update the translation at OneSky NOTICE
Instance Attribute Summary
Attributes inherited from Client
#base_locale, #client, #config, #onesky_locales, #project
Instance Method Summary collapse
-
#download(string_path, options = {}) ⇒ Object
Download translations from OneSky platform.
- #upload(string_path) ⇒ Object
Methods inherited from Client
#initialize, #to_onesky_locale, #to_rails_locale, #verify_languages!
Constructor Details
This class inherits a constructor from Onesky::Rails::Client
Instance Method Details
#download(string_path, options = {}) ⇒ Object
Download translations from OneSky platform
string_path
specify the folder path where all localization files locate options
indicate which files to download
- :base_only => base language only
- :all => all languages including base language
- <empty> => default value; translation languages
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/onesky/rails/file_client.rb', line 40 def download(string_path, = {}) verify_languages! files = get_default_locale_files(string_path).map {|path| File.basename(path)} locales = if [:base_only] [@base_locale] elsif [:all] [@base_locale] + @onesky_locales else @onesky_locales end locales.each do |locale| locale = locale.to_s puts "#{locale_dir(locale)}/" onesky_locale = locale.gsub('_', '-') files.each do |file| response = @project.export_translation(source_file_name: file, locale: onesky_locale) if response.code == 200 saved_file = save_translation(response, string_path, locale, file) puts " #{saved_file}" end end end end |
#upload(string_path) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/onesky/rails/file_client.rb', line 20 def upload(string_path) verify_languages! get_default_locale_files(string_path).map do |path| filename = File.basename(path) puts "Uploading #{filename}" @project.upload_file(file: path, file_format: FILE_FORMAT, is_keeping_all_strings: is_keep_strings?) path end end |