mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-13 10:26:53 +08:00
## 🔍 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  
61 lines
1.5 KiB
Ruby
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
|