perrotuerto.blog/old/config/build/pot2pos

63 lines
1.6 KiB
Plaintext
Raw Normal View History

2019-01-28 21:39:10 -06:00
#!/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 = ''
2019-10-08 12:29:05 -05:00
locales = ['en', 'es']
2019-01-28 21:39:10 -06:00
# Displays help
if ARGV[0] =~ /-h/
2019-03-19 22:25:20 -06:00
puts "pot2pos generates po files from a pot file."
2019-01-28 21:39:10 -06:00
puts "\nUse:"
2019-03-19 22:25:20 -06:00
puts " pot2pos [pot file] [option]"
2019-01-28 21:39:10 -06:00
puts "\nOption:"
puts " -m Merges to an existing po file."
puts "\nExamples:"
2019-03-19 22:25:20 -06:00
puts " pot2pos file.pot"
puts " pot2pos file.pot -m"
2019-01-28 21:39:10 -06:00
puts "\nCurrent supported locales:"
puts " " + locales.join("\n ")
2019-03-19 22:25:20 -06:00
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."
2019-01-28 21:39:10 -06:00
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'
2019-03-16 13:58:14 -06:00
# Checks if the file exists
2019-01-28 21:39:10 -06:00
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