84 lines
3.2 KiB
Ruby
84 lines
3.2 KiB
Ruby
|
# encoding: utf-8
|
||
|
|
||
|
namespace :migrate do
|
||
|
|
||
|
task :i18n => :environment do
|
||
|
|
||
|
p 'Start Bulletin'
|
||
|
bulletins = Bulletin.admin_manager_all
|
||
|
i = 1
|
||
|
bulletins.each do |bulletin|
|
||
|
p "#{i}/#{bulletins.size} - #{bulletin.id}"
|
||
|
title = I18nVariable.first(:conditions => {:key => 'title', :language_value_id => bulletin.id, :language_value_type => bulletin.class})
|
||
|
bulletin.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
|
||
|
subtitle = I18nVariable.first(:conditions => {:key => 'subtitle', :language_value_id => bulletin.id, :language_value_type => bulletin.class})
|
||
|
bulletin.subtitle_translations = {'en' => subtitle['en'], 'zh_tw' => subtitle['zh_tw']} if subtitle
|
||
|
text = I18nVariable.first(:conditions => {:key => 'text', :language_value_id => bulletin.id, :language_value_type => bulletin.class})
|
||
|
bulletin.text_translations = {'en' => text['en'], 'zh_tw' => text['zh_tw']} if text
|
||
|
bulletin.save(:validate => false)
|
||
|
i += 1
|
||
|
end
|
||
|
p 'End Bulletin'
|
||
|
|
||
|
p '====================================================='
|
||
|
|
||
|
p 'Start BulletinCategory'
|
||
|
categories = BulletinCategory.admin_manager_all
|
||
|
i = 1
|
||
|
categories.each do |category|
|
||
|
p "#{i}/#{categories.size} - #{category.id}"
|
||
|
title = I18nVariable.first(:conditions => {:language_value_id => category.id, :language_value_type => category.class})
|
||
|
category.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
|
||
|
category.save(:validate => false)
|
||
|
i += 1
|
||
|
end
|
||
|
p 'End BulletinCategory'
|
||
|
|
||
|
p '====================================================='
|
||
|
|
||
|
p 'Start BulletinFile'
|
||
|
files = BulletinFile.all
|
||
|
i = 1
|
||
|
files.each do |file|
|
||
|
p "#{i}/#{files.size} - #{file.id}"
|
||
|
description = I18nVariable.first(:conditions => {:language_value_id => file.id, :language_value_type => file.class})
|
||
|
file.description_translations = {'en' => description['en'], 'zh_tw' => description['zh_tw']} if description
|
||
|
title = I18nVariable.first(:conditions => {:language_value_id => file.id, :language_value_type => file.class})
|
||
|
file.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
|
||
|
file.save(:validate => false)
|
||
|
i += 1
|
||
|
end
|
||
|
p 'End BulletinFile'
|
||
|
|
||
|
p '====================================================='
|
||
|
|
||
|
p 'Start BulletinLink'
|
||
|
links = BulletinLink.all
|
||
|
i = 1
|
||
|
links.each do |link|
|
||
|
p "#{i}/#{links.size} - #{link.id}"
|
||
|
title = I18nVariable.first(:conditions => {:language_value_id => link.id, :language_value_type => link.class})
|
||
|
link.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
|
||
|
link.save(:validate => false)
|
||
|
i += 1
|
||
|
end
|
||
|
p 'End BulletinLink'
|
||
|
|
||
|
p '====================================================='
|
||
|
|
||
|
p 'Start UnitListForAnc'
|
||
|
units = UnitListForAnc.all
|
||
|
i = 1
|
||
|
units.each do |unit|
|
||
|
p "#{i}/#{units.size} - #{unit.id}"
|
||
|
title = I18nVariable.first(:conditions => {:language_value_id => unit.id, :language_value_type => unit.class})
|
||
|
unit.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title
|
||
|
unit.save(:validate => false)
|
||
|
i += 1
|
||
|
end
|
||
|
p 'End UnitListForAnc'
|
||
|
|
||
|
end
|
||
|
|
||
|
end
|