diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tasks/i18n.rake | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/tasks/i18n.rake b/lib/tasks/i18n.rake new file mode 100644 index 0000000..239d081 --- /dev/null +++ b/lib/tasks/i18n.rake @@ -0,0 +1,51 @@ +require 'yaml' +require 'fileutils' + +namespace :i18n do + # + # for coding, it helps to have the english strings in separate files. + # for translating, it helps to have a single file. This action will combine + # the small files into one big one. + # + # Also, transifex insists that the files be en_US and not just en. + # grrr. + # + desc "combine locales/en/*.yml to cwd/en.yml" + task :bundle do + en_yml = File.join(Rails.root, 'leap_web_en_US.yml') + Dir.chdir('config/locales/') do + if File.exists?(en_yml) + puts "File `#{en_yml}` already exists. Remove it first." + exit + end + File.open(en_yml, 'w') do |output| + output.write("en_US:\n\n ### Do NOT edit this file directly, as all changes will be overwritten by the bundle script. Instead, make changes in the appropriate file in config/locales/en and recreate this file with the i18n:bundle task.") + + Dir.glob('*.en.yml').sort.each do |file| + ## print separator to see where another file begins + output.write("\n\n" + '#' * 40 + "\n" + '### ' + file + "\n") + output.write( + # remove the toplevel "en" key + YAML.load_file(file)['en']. + to_yaml. + # prefix all lines with two spaces (we're nested below "en:") + lines.map {|line| " #{line}"}[ + 1..-1 # << skip the first line (it's "---" and freaks out the parser if it sees it multiple times in a file) + ].join) + end + end + puts "You can now find the bundled locale yml in: #{en_yml}" + end + end + + + # elijah: this does not actually work, but I think could be a starting point + # for something that will work. + desc "pull translations from transifex" + task :download do + Conf.enabled_languages.each do |lang| + next unless lang == 'en' + `curl -L --user #{Conf.transifex_user}:#{Conf.transifex_password} -X GET https://www.transifex.net/api/2/project/crabgrass/resource/master/translation/#{lang}/?file > config/locales/#{lang}.yml` + end + end +end |