discourse/app/controllers/post_localizations_controller.rb
Keegan George af91b0433f
DEV: Post localization improvements (#32869)
## 🔍 Overview
This update includes some small improvements to post localizations. In
particular:
- we only show add translation button if user is part of
`experimental_content_localization_allowed_groups` and
`SiteSetting.experimental_content_localization` is `true`
- we no longer load `post_localizations` on every post until the post
localization globe is clicked
- we move the post localization indicator to be an menu item in the
post-action-buttons instead of being in the post meta data
- we remove the `SiteSetting.content_localization_debug_allowed_groups`
in favor of using a single setting:
`experimental_content_localization_allowed_groups_map`

## 📷 Screenshots

![image](https://github.com/user-attachments/assets/fa239501-0dbc-43ba-8b70-d6899dd1554c)


![image](https://github.com/user-attachments/assets/8b3272b3-7483-4bb1-af36-8c8ad5d55d03)
2025-05-27 08:49:53 -07:00

61 lines
1.5 KiB
Ruby

# frozen_string_literal: true
class PostLocalizationsController < ApplicationController
before_action :ensure_logged_in
def show
guardian.ensure_can_localize_content!
params.require(%i[post_id])
localizations = PostLocalization.where(post_id: params[:post_id])
if localizations
render json:
ActiveModel::ArraySerializer.new(
localizations,
each_serializer: PostLocalizationSerializer,
root: false,
).as_json,
status: :ok
else
render json_error I18n.t("not_found"), status: :not_found
end
end
def create_or_update
guardian.ensure_can_localize_content!
params.require(%i[post_id locale raw])
localization = PostLocalization.find_by(post_id: params[:post_id], locale: params[:locale])
if localization
PostLocalizationUpdater.update(
post_id: params[:post_id],
locale: params[:locale],
raw: params[:raw],
user: current_user,
)
render json: success_json, status: :ok
else
PostLocalizationCreator.create(
post_id: params[:post_id],
locale: params[:locale],
raw: params[:raw],
user: current_user,
)
render json: success_json, status: :created
end
end
def destroy
guardian.ensure_can_localize_content!
params.require(%i[post_id locale])
PostLocalizationDestroyer.destroy(
post_id: params[:post_id],
locale: params[:locale],
acting_user: current_user,
)
head :no_content
end
end