2021-08-23 11:44:45 +00:00
|
|
|
class EventNewsCustomTitle
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
field :key
|
|
|
|
field :title, type: String, localize: true
|
2022-01-11 03:12:37 +00:00
|
|
|
KEYS = ['title','event_date','speaker','place','host']
|
2021-08-23 11:44:45 +00:00
|
|
|
def self.get_map
|
2021-09-16 09:16:20 +00:00
|
|
|
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("event_news.#{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("event_news.#{k}")}]}.to_h)
|
|
|
|
end
|
|
|
|
s
|
|
|
|
end
|
2021-08-23 11:44:45 +00:00
|
|
|
end
|
|
|
|
def default_title
|
|
|
|
I18n.t("event_news.#{self.key}")
|
|
|
|
end
|
|
|
|
def self.get_trans(key)
|
2021-09-16 09:16:20 +00:00
|
|
|
tmp = TitleMap[key][I18n.locale] rescue I18n.t("event_news.#{key}")
|
|
|
|
tmp.blank? ? I18n.t("event_news.#{key}") : tmp
|
2021-08-23 11:44:45 +00:00
|
|
|
end
|
|
|
|
TitleMap = self.get_map.map{|v| [v.key,v.title_translations]}.to_h
|
|
|
|
end
|