Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 38 additions & 15 deletions plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,41 +202,61 @@
object.slug_path
end

find_locale = -> (scope) {
if (scope && scope.current_user && scope.current_user.locale)
scope.current_user.locale
else
I18n.locale_available?(I18n.locale) ? I18n.locale : SiteSetting.default_locale
end
}

add_to_serializer(:basic_category, :name, respect_plugin_enabled: false) do
if object.uncategorized?
I18n.t('uncategorized_category_name', locale: SiteSetting.default_locale)
elsif !(scope && scope.current_user && scope.current_user.locale && object.slug_path && Multilingual::Translation.get("category_name", object.slug_path)).blank?
Multilingual::Translation.get("category_name", object.slug_path)[scope.current_user.locale.to_sym] || object.name
I18n.t(
'uncategorized_category_name',
locale: I18n.locale_available?(I18n.locale) ? I18n.locale : SiteSetting.default_locale
)
elsif !(object.slug_path && Multilingual::Translation.get("category_name", object.slug_path)).blank?
Multilingual::Translation.get("category_name", object.slug_path)[find_locale.call(scope).to_sym] || object.name
else
object.name
end
end

add_to_serializer(:basic_category, :description_text, respect_plugin_enabled: false) do
if object.uncategorized?
I18n.t('category.uncategorized_description', locale: SiteSetting.default_locale)
elsif !(scope && scope.current_user && scope.current_user.locale && object.slug_path && Multilingual::Translation.get("category_description", object.slug_path)).blank?
Multilingual::Translation.get("category_description", object.slug_path)[scope.current_user.locale.to_sym] || object.description_text
I18n.t(
'category.uncategorized_description',
locale: I18n.locale_available?(I18n.locale) ? I18n.locale : SiteSetting.default_locale
)
elsif !(object.slug_path && Multilingual::Translation.get("category_description", object.slug_path)).blank?
Multilingual::Translation.get("category_description", object.slug_path)[find_locale.call(scope).to_sym] || object.description_text
else
object.description_text
end
end

add_to_serializer(:basic_category, :description, respect_plugin_enabled: false) do
if object.uncategorized?
I18n.t('category.uncategorized_description', locale: SiteSetting.default_locale)
elsif !(scope && scope.current_user && scope.current_user.locale && object.slug_path && Multilingual::Translation.get("category_description", object.slug_path)).blank?
Multilingual::Translation.get("category_description", object.slug_path)[scope.current_user.locale.to_sym] || object.description
I18n.t(
'category.uncategorized_description',
locale: I18n.locale_available?(I18n.locale) ? I18n.locale : SiteSetting.default_locale
)
elsif !(object.slug_path && Multilingual::Translation.get("category_description", object.slug_path)).blank?
Multilingual::Translation.get("category_description", object.slug_path)[find_locale.call(scope).to_sym] || object.description
else
object.description
end
end

add_to_serializer(:basic_category, :description_excerpt, respect_plugin_enabled: false) do
if object.uncategorized?
I18n.t('category.uncategorized_description', locale: SiteSetting.default_locale)
elsif !(scope && scope.current_user && scope.current_user.locale && object.slug_path && Multilingual::Translation.get("category_description", object.slug_path)).blank?
Multilingual::Translation.get("category_description", object.slug_path)[scope.current_user.locale.to_sym] || object.description_excerpt
I18n.t(
'category.uncategorized_description',
locale: I18n.locale_available?(I18n.locale) ? I18n.locale : SiteSetting.default_locale
)
elsif !(object.slug_path && Multilingual::Translation.get("category_description", object.slug_path)).blank?
Multilingual::Translation.get("category_description", object.slug_path)[find_locale.call(scope).to_sym] || object.description_excerpt
else
object.description_excerpt
end
Expand All @@ -245,9 +265,12 @@
add_to_serializer(:site, :categories, respect_plugin_enabled: false) do
object.categories.map do |c|
if c[:slug] == "uncategorized"
c[:name] = I18n.t('uncategorized_category_name', locale: SiteSetting.default_locale)
elsif SiteSetting.multilingual_enabled && !(scope && scope.current_user && scope.current_user.locale && c[:slug_path] && Multilingual::Translation.get("category_name", c[:slug_path])).blank?
c[:name] = Multilingual::Translation.get("category_name", c[:slug_path])[scope.current_user.locale.to_sym] || c[:name]
c[:name] = I18n.t(
'uncategorized_category_name',
locale: I18n.locale_available?(I18n.locale) ? I18n.locale : SiteSetting.default_locale
)
elsif SiteSetting.multilingual_enabled && !(c[:slug_path] && Multilingual::Translation.get("category_name", c[:slug_path])).blank?
c[:name] = Multilingual::Translation.get("category_name", c[:slug_path])[find_locale.call(scope).to_sym] || c[:name]
end
c.to_h
end
Expand Down