require 'thor' require 'missing_translation/configuration' require 'missing_translation/translation_file' require 'missing_translation/util' require 'missing_translation_api' module MissingTranslation class Cli < Thor desc "install", "It will guide you in the configuration process" def install all = options[:all] unless Configuration.file_exists? puts "Configuration file not found, Creating file..." Configuration.create_file end api_token = ask("What is the api token of missing translation project ?") configuration = Configuration.new configuration.update_key api_token end desc "upload", 'Upload file in locale folder to missing translation' def upload file_extension = "" config_folder = "./config/locales/#{file_extension}/*.yml" file_pathnames = Dir[config_folder] return unless file_pathnames && file_pathnames.size > 0 configuration = Configuration.new api = MissingTranslationApi.new(configuration.config[:key]) file_pathnames.each do |pathname| file = MissingTranslation::TranslationFile.new(pathname) api.upload(file.language, file.group, file.to_json, "yaml") end end desc "download", "Download all file from missing translation" def download MissingTranslation::Cli.new().sort return if MissingTranslation::Util.uncommitted_changes? directory = "./config/locales" configuration = Configuration.new api = MissingTranslationApi.new(configuration.config[:key]) response = api.download("yaml") response.each do |f| file = MissingTranslation::TranslationFile.new file.group = f["group"] file.language = f["language"] file.translations = f["keys"] file.write(directory) end end desc "sort", "Sort all yaml translations" def sort return if MissingTranslation::Util.uncommitted_changes? config_folder = "./config/locales/*.yml" MissingTranslation::Util.sort(config_folder) MissingTranslation::Util.commit_all_changes("locale: Sort yml files") end end end