Class: Blocks::Sdk::Rails::Controllers::Api::TranslationsController

Inherits:
ActionController::API
  • Object
show all
Defined in:
lib/blocks/sdk/rails/controllers/api/translations_controller.rb

Overview

API controller for fetching translations

Instance Method Summary collapse

Instance Method Details

#indexObject

GET /blocks/api/translations Query params: module_name, language (optional, defaults to “en”)



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/blocks/sdk/rails/controllers/api/translations_controller.rb', line 12

def index
  module_name = params[:module_name] || params[:moduleName]
  language    = params[:language] || params[:Language] || "en"

  unless module_name
    return render json: { error: "module_name is required" }, status: :bad_request
  end

  result = @service_manager.fetch(
    service_name: "translations",
    params: { module_name: module_name, language: language },
    config: client_config
  )

  if result[:error]
    status = result[:status] == :connection_error ? :service_unavailable : :bad_gateway
    render json: result, status: status
  else
    render json: result[:translations] || result, status: :ok
  end
end