2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-03-03 23:54:20 +08:00
discourse/app/models/post_localization.rb
Keegan George 8b789c9306
FEATURE: Add support for uploads on translated posts (#35871)
## 🔍 Overview

This update allows for having uploads on localized posts. If no uploads
are made, translated posts will show the original uploaded image.
However, if a translator would like to upload a translated image, the
composer will now support an upload reference.

## 🔗 Relevant Links
As requested on Meta:

https://meta.discourse.org/t/translation-composer-missing-image-upload-support/386829


## 📹 Screen Recordings


https://github.com/user-attachments/assets/f01fdfde-c84b-46d8-a96d-a4641699b3b9
2025-11-12 08:55:21 -08:00

43 lines
1.2 KiB
Ruby

# frozen_string_literal: true
class PostLocalization < ActiveRecord::Base
include LocaleMatchable
include HasPostUploadReferences
belongs_to :post
has_many :upload_references, as: :target, dependent: :destroy
has_many :uploads, through: :upload_references
validates :post_version, presence: true
validates :locale, presence: true, length: { maximum: 20 }
validates :raw, presence: true
validates :cooked, presence: true
validates :localizer_user_id, presence: true
validates :locale, uniqueness: { scope: :post_id }
private
def access_control_post_id_for_upload
self.post_id
end
end
# == Schema Information
#
# Table name: post_localizations
#
# id :bigint not null, primary key
# post_id :integer not null
# post_version :integer not null
# locale :string(20) not null
# raw :text not null
# cooked :text not null
# localizer_user_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_post_localizations_on_post_id (post_id)
# index_post_localizations_on_post_id_and_locale (post_id,locale) UNIQUE
#