discourse/app/controllers/topic_localizations_controller.rb
Natalie Tay 3146142c2e
DEV: Create topic and post localization resources (#32440)
This commit adds

- `topic_localization` containing its topic, a locale, title, and
fancy_title
- `post_localization` containing its post, a locale, raw, cooked, the
associated post's version
- and also APIs to add them

Reviewer note: We may ask ourselves "why create separate models instead
of one that is generic?" but the different localizable models may be
vastly different. For example in posts we only have raw that we need to
translate, and topics we have only title, but for categories we have
name and description. Then, we may ask ourselves "why not create a
polymorphic one that takes in model and column name?" and then we end up
with the same thing as what we have currently which is custom fields
(which is a mess in itself). Also, when replacing the untranslated
content to the translated one, we may find it easier to just `join` +
`coalesce` on the dedicated table - it would be a much simpler query
than polymorphism.
2025-04-28 12:16:14 +08:00

43 lines
1 KiB
Ruby
Vendored

# frozen_string_literal: true
class TopicLocalizationsController < ApplicationController
before_action :ensure_logged_in
def create
guardian.ensure_can_localize_content!
params.require(%i[topic_id locale title])
TopicLocalizationCreator.create(
topic_id: params[:topic_id],
locale: params[:locale],
title: params[:title],
user: current_user,
)
render json: success_json, status: :created
end
def update
guardian.ensure_can_localize_content!
params.require(%i[topic_id locale title])
TopicLocalizationUpdater.update(
topic_id: params[:topic_id],
locale: params[:locale],
title: params[:title],
user: current_user,
)
render json: success_json, status: :ok
end
def destroy
guardian.ensure_can_localize_content!
params.require(%i[topic_id locale])
TopicLocalizationDestroyer.destroy(
topic_id: params[:topic_id],
locale: params[:locale],
acting_user: current_user,
)
head :no_content
end
end