#!/usr/bin/env ruby # encoding: UTF-8 # coding: UTF-8 require 'fileutils' # Displays message when something goes wrong def check condition, err_msg if condition then puts err_msg + ' For help use -h or --help.'; abort end end # To the root directory Dir.chdir(File.dirname(__FILE__) + '/../..') # Variables pot_dir = 'content/pot/' pot_path = '' po_dir = 'content/po/' po_name = '' locales = ['en', 'es'] # Displays help if ARGV[0] =~ /-h/ puts "pot2pos generates po files from a pot file." puts "\nUse:" puts " pot2pos [pot file] [option]" puts "\nOption:" puts " -m Merges to an existing po file." puts "\nExamples:" puts " pot2pos file.pot" puts " pot2pos file.pot -m" puts "\nCurrent supported locales:" puts " " + locales.join("\n ") puts "\nThe pot file has to be in '#{pot_dir}' and the po files are going to be stored in '#{po_dir}*', where '*' are the locales folders." abort end # Checks if the user gave the path to the file check(ARGV[0] == nil, "ERROR: File is required.") # Cleans path pot_path = pot_dir + File.basename(ARGV[0]) po_name = File.basename(ARGV[0], '.*') + '.po' # Checks if the file exists check(File.exist?(pot_path) == false, "ERROR: File doesn't exist.") # Creates locale directory if need it locales.each do |l| if File.exist?(po_dir + l) == false Dir.mkdir(po_dir + l) end end # Creates or merges po files locales.each do |l| if ARGV[1] == nil system("msginit --input=#{pot_path} --locale=#{l} --no-translator --output=#{po_dir + l}/#{po_name}") else system("msgmerge --update #{po_dir + l}/#{po_name} #{pot_path}") end end