Class: RailsI18nOnair::Api::LiveTranslationsController

Inherits:
RailsI18nOnair::ApplicationController show all
Defined in:
app/controllers/rails_i18n_onair/api/live_translations_controller.rb

Instance Method Summary collapse

Instance Method Details

#updateObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/rails_i18n_onair/api/live_translations_controller.rb', line 6

def update
  locale = normalize_locale(params[:locale])
  key    = params[:key]
  value  = params[:value]

  if key.blank?
    return render json: { error: "key is required" }, status: :unprocessable_entity
  end

  # Build the full key path including locale prefix
  # (DB stores data as { "en" => { "user" => { "name" => "..." } } })
  full_key = "#{locale}.#{key}"

  @save_error = nil
  success = if RailsI18nOnair.configuration.database_mode?
              update_database_translation(locale, full_key, value)
            else
              update_file_translation(locale, full_key, value)
            end

  if success
    render json: { status: "ok", key: key, locale: locale, value: value }
  else
    render json: { error: @save_error || "Failed to save translation" }, status: :unprocessable_entity
  end
end