diff options
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/page.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/app/models/page.rb b/app/models/page.rb index db5b688..f796228 100644 --- a/app/models/page.rb +++ b/app/models/page.rb | |||
| @@ -87,6 +87,27 @@ class Page < ApplicationRecord | |||
| 87 | end | 87 | end |
| 88 | end | 88 | end |
| 89 | 89 | ||
| 90 | def self.non_default_locales | ||
| 91 | I18n.available_locales - [:root, I18n.default_locale] | ||
| 92 | end | ||
| 93 | |||
| 94 | # One row per non-default locale, read from the actual translation | ||
| 95 | # row -- never through the locale-dependent accessor, so a locale | ||
| 96 | # with no real translation yet reports as absent rather than quietly | ||
| 97 | # showing a fallback value borrowed from another locale. | ||
| 98 | def translation_summary | ||
| 99 | Page.non_default_locales.map do |locale| | ||
| 100 | translation = translations.find_by(:locale => locale) | ||
| 101 | { | ||
| 102 | :locale => locale, | ||
| 103 | :exists => translation.present?, | ||
| 104 | :title => translation&.title, | ||
| 105 | :updated_at => translation&.updated_at, | ||
| 106 | :outdated => translation.present? && outdated_translations?(:locale => locale) | ||
| 107 | } | ||
| 108 | end | ||
| 109 | end | ||
| 110 | |||
| 90 | def self.untranslated(options = {:locale => :de}) | 111 | def self.untranslated(options = {:locale => :de}) |
| 91 | PageTranslation.all.group_by(&:page_id).select do |k,v| | 112 | PageTranslation.all.group_by(&:page_id).select do |k,v| |
| 92 | v.size == 1 && v.map{|x| x.locale}.include?(options[:locale]) | 113 | v.size == 1 && v.map{|x| x.locale}.include?(options[:locale]) |
