recruitment_mod/app/models/recruitment_custom_title.rb

25 lines
1.1 KiB
Ruby

class RecruitmentCustomTitle
include Mongoid::Document
include Mongoid::Timestamps
field :key
field :title, type: String, localize: true
KEYS = ['category', 'title', 'event_date', 'education_requirement', 'experience_requirement', 'skills_requirement', 'language', 'salary_info', 'notes', 'contact_info']
def self.get_map
KEYS.map do |k|
s = self.where(key: k).first || self.create(key: k,title_translations: I18n.available_locales.map{|l| [l,I18n.with_locale(l){I18n.t("recruitment.#{k}")}]}.to_h)
if s.title_translations.select{|k,v| v.include?("translation missing")}.length>0
s.update_attributes(title_translations: I18n.available_locales.map{|l| [l,I18n.with_locale(l){I18n.t("recruitment.#{k}")}]}.to_h)
end
s
end
end
def default_title
I18n.t("recruitment.#{self.key}")
end
def self.get_trans(key)
tmp = TitleMap[key][I18n.locale] rescue I18n.t("recruitment.#{key}")
tmp.blank? ? I18n.t("recruitment.#{key}") : tmp
end
TitleMap = self.get_map.map{|v| [v.key,v.title_translations]}.to_h
end