#!/usr/bin/env ruby # frozen_string_literal: true require "optparse" require "habluhablu" require "translation" args = {} OptionParser.new do |opts| opts.banner = "Generate files including basic phrases translations (using with I18n gem)" opts.on("-l", "--language SYMBOL", "Symbol of the language you want to generate file for (en, es, ...).") opts.on("-m", "--multi SYMBOLS", "Symbols of languages you want to generate files for (en es pl ar)") opts.on("-k", "--keyword KEYWORD", "Add your own keyword for all language files (.yml).") opts.on("-s", "--sample FILES", "Add your own sample for language files (.yml).") opts.on("-t", "--translate TEXT", "Translation text example: Hello_world_test!") opts.on("-f", "--from SYMBOL", "From example: en") opts.on("-o", "--target SYMBOL", "Target language example: es") opts.on("-j", "--json SYMBOL", "Render languages' json files.") end.parse!(into: args) information = lambda do |param, exe| if File.exist?("config/locales/#{param}.#{exe}") puts "..." sleep 0.5 puts "Everything was generated successfully!" else puts "Something went wrong!" end end if args[:json].nil? == false Languages.new("en").render_json(args[:json]) information.call(args[:json].split("_").first, "json") end if args[:translate].nil? == false if args[:from].nil? == false translator = Translation.new(args[:translate], args[:target]) else translator = Translation.new(args[:translate], args[:target], args[:from]) end translator.response information.call(args[:target], "yml") end if args[:language].nil? == false Habluhablu.hablu(args[:language]) information.call(args[:language], "yml") end if args[:keyword].nil? == false Habluhablu.keyword(args[:keyword]) puts "..." sleep 0.5 puts "Everything was added successfully!" end if args[:multi].nil? == false languages_array = args[:multi].split("_") languages_array.each do |language| Habluhablu.hablu(language) end information.call(languages_array.last, "yml") end if args[:sample].nil? == false Habluhablu.render_sample(args[:sample]) information.call("sample", "yml") end