module GettextI18nRailsJs::Task
Public Instance Methods
po_to_json()
click to toggle source
# File lib/gettext_i18n_rails_js/task.rb, line 31 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 44 def destination(lang) path = output_path.join(lang) path.mkpath path.join("#{domain}.js").open("w") do |f| f.rewind f.write yield end puts "Created #{domain}.js in #{path}" end
domain()
click to toggle source
# File lib/gettext_i18n_rails_js/task.rb, line 115 def domain GettextI18nRailsJs.config.domain end
engine_root()
click to toggle source
# File lib/gettext_i18n_rails_js/task.rb, line 111 def engine_root GettextI18nRailsJs.config.rails_engine.root end
files_iterate()
click to toggle source
# File lib/gettext_i18n_rails_js/task.rb, line 77 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 93 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 60 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 56 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 105 def output_path engine_root.join( GettextI18nRailsJs.config.output_path ) end
set_config()
click to toggle source
# File lib/gettext_i18n_rails_js/task.rb, line 69 def set_config GettextI18nRailsJs::Parser::Javascript .gettext_function = GettextI18nRailsJs.config.javascript_function GettextI18nRailsJs::Parser::Handlebars .gettext_function = GettextI18nRailsJs.config.handlebars_function end