mirror of
https://github.com/discourse/discourse.git
synced 2025-06-19 14:31:41 +08:00

This PR adds category localization support to core. - Depends on https://github.com/discourse/discourse/pull/32378 - Creates the required table `category_localizations` - Makes use of the site category cache to display localized categories - Supports name and description - This does not yet include /categories page. (coming in a next PR) ## Before <img width="1089" alt="Screenshot 2025-04-21 at 4 31 43 PM" src="https://github.com/user-attachments/assets/9e49b21b-b16a-43d2-9b16-0fd0324a21ca" /> ## After <img width="1085" alt="Screenshot 2025-04-21 at 4 32 42 PM" src="https://github.com/user-attachments/assets/7bfa21a2-6df2-4cdf-a00a-d044c3526a40" />
34 lines
936 B
Ruby
34 lines
936 B
Ruby
# frozen_string_literal: true
|
|
|
|
class CategoryLocalization < ActiveRecord::Base
|
|
belongs_to :category
|
|
|
|
validates :locale, presence: true, length: { maximum: 20 }
|
|
validates :name, presence: true, length: { maximum: 50 }
|
|
validates :category_id, uniqueness: { scope: :locale }
|
|
|
|
after_commit :invalidate_site_cache
|
|
|
|
def invalidate_site_cache
|
|
I18n.with_locale(locale) { Site.clear_cache }
|
|
end
|
|
end
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: category_localizations
|
|
#
|
|
# id :bigint not null, primary key
|
|
# category_id :bigint not null
|
|
# locale :string(20) not null
|
|
# name :string(50) not null
|
|
# description :text
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_category_localizations_on_category_id (category_id)
|
|
# index_category_localizations_on_category_id_and_locale (category_id,locale) UNIQUE
|
|
#
|