module GettextI18nRailsJs::Task
Public Instance Methods
po_to_json()
click to toggle source
# File lib/gettext_i18n_rails_js/task.rb, line 29 def po_to_json set_config if files_list.empty? puts "Couldn't find PO files in #{locale_path}, run 'rake gettext:find'" else files_iterate print_footer end end
Protected Instance Methods
destination(lang) { || ... }
click to toggle source
# File lib/gettext_i18n_rails_js/task.rb, line 42 def destination(lang) path = output_path.join(lang) path.mkpath path.join("app.js").open("w") do |f| f.rewind f.write yield end puts "Created app.js in #{path}" end
files_iterate()
click to toggle source
# File lib/gettext_i18n_rails_js/task.rb, line 75 def files_iterate files_list.each do |input| # Language is used for filenames, while language code is used as the # in-app language code. So for instance, simplified chinese will live # in app/assets/locale/zh_CN/app.js but inside the file the language # will be referred to as locales['zh-CN']. This is to adapt to the # existing gettext_rails convention. destination( lang_for(input) ) do json_for(input) end end end
files_list()
click to toggle source
# File lib/gettext_i18n_rails_js/task.rb, line 91 def files_list require "gettext_i18n_rails/tasks" ::Pathname.glob( ::File.join( locale_path, "**", "*.po" ) ) end
json_for(file)
click to toggle source
# File lib/gettext_i18n_rails_js/task.rb, line 58 def json_for(file) PoToJson.new( file.to_s ).generate_for_jed( lang_for(file), GettextI18nRailsJs.config.jed_options ) end
lang_for(file)
click to toggle source
# File lib/gettext_i18n_rails_js/task.rb, line 54 def lang_for(file) file.dirname.basename.to_s end
output_path()
click to toggle source
# File lib/gettext_i18n_rails_js/task.rb, line 103 def output_path ::Rails.root.join( GettextI18nRailsJs.config.output_path ) end
set_config()
click to toggle source
# File lib/gettext_i18n_rails_js/task.rb, line 67 def set_config GettextI18nRailsJs::Parser::Javascript .gettext_function = GettextI18nRailsJs.config.javascript_function GettextI18nRailsJs::Parser::Handlebars .gettext_function = GettextI18nRailsJs.config.handlebars_function end