aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2015-03-18 17:49:45 +0000
committerLouise Crow <louise.crow@gmail.com>2015-03-23 17:41:47 +0000
commit5486a2135689eb59b03da4f9f530b58fa270d676 (patch)
tree28d436c30b50b88160b509b74e779a2f3ad28114
parentb61e6b27c8527417d91c0a06c4b0ae925e553340 (diff)
Add rake task for uppdating locale files with slightly changed msgids
We don't really want to make all the translators retranslate strings that are basically the same but slightly tweaked in the English version. So this task just replaces the msgid in the app.po files for each locale.
-rw-r--r--lib/tasks/gettext.rake47
1 files changed, 46 insertions, 1 deletions
diff --git a/lib/tasks/gettext.rake b/lib/tasks/gettext.rake
index 9bdb6169b..4df92b008 100644
--- a/lib/tasks/gettext.rake
+++ b/lib/tasks/gettext.rake
@@ -35,14 +35,59 @@ namespace :gettext do
end
end
+ desc 'Update locale files with slightly changed English msgids using a csv file of old to new strings'
+ task :update_msgids_from_csv do
+ mapping_file = find_mapping_file(ENV['MAPPING_FILE'])
+ mappings = {}
+ CSV.parse(clean_csv_mapping_file(mapping_file)) do |csv_line|
+ from,to = csv_line
+ mappings[from] = to
+ end
+ Dir.glob("locale/**/app.po").each do |po_file|
+ lang_mappings = mappings.clone
+ lines = []
+ File.read(po_file).each_line do |line|
+ /^msgid "(.*)"/ =~ line
+ if $1 && mappings[$1]
+ lines << "msgid \"#{lang_mappings.delete($1)}\""
+ else
+ lines << line
+ end
+ end
+ puts "Mappings unused in #{po_file}: #{lang_mappings.keys}" unless lang_mappings.empty?
+ File.open(po_file, "w") { |f| f.puts(lines) }
+ end
+ end
+
+ # Use a quote for quote-escaping as CSV errors on the \" with "Missing or stray quote"
+ def clean_csv_mapping_file(file)
+ data = ''
+ File.foreach(file) do |line|
+ data += line.gsub('\"', '""')
+ end
+ data
+ end
+
def find_theme(theme)
unless theme
puts "Usage: Specify an Alaveteli-theme with THEME=[theme directory name]"
- exit(0)
+ exit(1)
end
theme
end
+ def find_mapping_file(file)
+ unless file
+ puts "Usage: Specify a csv file mapping old to new strings with MAPPING_FILE=[file name]"
+ exit(1)
+ end
+ unless File.exists?(file)
+ puts "Error: MAPPING_FILE #{file} not found"
+ exit(1)
+ end
+ file
+ end
+
def theme_files_to_translate(theme)
Dir.glob("{lib/themes/#{theme}/lib}/**/*.{rb,erb}")
end