rake fixes for multilingual

This commit is contained in:
Harry Bomrah 2014-11-04 17:28:43 +08:00
parent e3cf299843
commit 2a5cc3e31c
2 changed files with 9 additions and 6 deletions

View File

@ -13,7 +13,7 @@ class AnnouncementLinkWidgetsController < ApplicationController
"heading-links" => "Links" "heading-links" => "Links"
} }
} }
f = File.join(Rails.root, "public" , "announcement_link_widget.json") f = File.join(Rails.root, "public" , "announcement_link_widget_#{I18n.locale.to_s}.json")
if File.exists?(f) if File.exists?(f)
contents = File.read(f) contents = File.read(f)
data = JSON.parse(contents) data = JSON.parse(contents)

View File

@ -1,7 +1,9 @@
namespace :announcement_link_widget do namespace :announcement_link_widget do
desc "Combination of widgets" desc "Combination of widgets"
task :make_cache,[:url] => :environment do |task,args| task :make_cache,[:url] => :environment do |task,args|
announcement_app = ModuleApp.find_by_key("announcement") I18n.available_locales.each do |locale|
OrbitHelper.set_site_locale locale
announcement_app = ModuleApp.find_by_key("announcement")
link_app = ModuleApp.find_by_key("web_resource") link_app = ModuleApp.find_by_key("web_resource")
OrbitHelper.override_widget_module_app("announcement") OrbitHelper.override_widget_module_app("announcement")
link_app_tags = link_app.tags link_app_tags = link_app.tags
@ -20,7 +22,7 @@ namespace :announcement_link_widget do
end end
common_tags_frontend = common_tags.collect do |ct| common_tags_frontend = common_tags.collect do |ct|
{ {
"tag-name" => ct.name, "tag-name" => ct.name_translations[locale.to_s],
"tag-id" => ct.name.downcase.gsub(" ", "_"), "tag-id" => ct.name.downcase.gsub(" ", "_"),
"announcements" => [], "announcements" => [],
"links" => [] "links" => []
@ -35,7 +37,7 @@ namespace :announcement_link_widget do
name = t.name.downcase.gsub(" ", "_") name = t.name.downcase.gsub(" ", "_")
index = common_tags_frontend.index{|t| t["tag-id"] == name} index = common_tags_frontend.index{|t| t["tag-id"] == name}
ctf = common_tags_frontend[index] ctf = common_tags_frontend[index]
ctf["announcements"] << {"title" => ann.title,"link"=>OrbitHelper.widget_item_url(ann.to_param)} ctf["announcements"] << {"title" => ann.title_translations[locale.to_s],"link"=>OrbitHelper.widget_item_url(ann.to_param)}
end end
end end
end end
@ -48,7 +50,7 @@ namespace :announcement_link_widget do
name = t.name.downcase.gsub(" ", "_") name = t.name.downcase.gsub(" ", "_")
index = common_tags_frontend.index{|t| t["tag-id"] == name} index = common_tags_frontend.index{|t| t["tag-id"] == name}
ctf = common_tags_frontend[index] ctf = common_tags_frontend[index]
ctf["links"] << {"title" => wl.title,"url" => wl.url} ctf["links"] << {"title" => wl.title_translations[locale.to_s],"url" => wl.url_translations[locale.to_s]}
end end
end end
end end
@ -63,9 +65,10 @@ namespace :announcement_link_widget do
"heading-links" => "Links" "heading-links" => "Links"
} }
} }
file = File.join(Rails.root, "public" , "announcement_link_widget.json") file = File.join(Rails.root, "public" , "announcement_link_widget_#{locale.to_s}.json")
File.open(file,"w") do |f| File.open(file,"w") do |f|
f.write(@data.to_json) f.write(@data.to_json)
end end
end
end end
end end