2019-01-16 16:28:25 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# API Controller for managing front-end translations
|
2023-02-24 17:26:55 +01:00
|
|
|
class API::TranslationsController < API::APIController
|
2016-03-23 18:39:41 +01:00
|
|
|
before_action :set_locale
|
|
|
|
|
|
|
|
def show
|
2019-12-16 16:54:40 +01:00
|
|
|
translations = I18n.t params[:state]
|
2023-02-24 17:26:55 +01:00
|
|
|
if translations.instance_of?(String) && translations.start_with?('translation missing')
|
2019-12-16 16:54:40 +01:00
|
|
|
render json: { error: translations }, status: :unprocessable_entity
|
2016-03-23 18:39:41 +01:00
|
|
|
else
|
2019-12-16 16:54:40 +01:00
|
|
|
path = params[:state]
|
|
|
|
res = path.split('.').reverse.reduce(translations) { |r, e| { e.to_sym => r } }
|
|
|
|
render json: res, status: :ok
|
2016-03-23 18:39:41 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-12 16:58:39 +02:00
|
|
|
private
|
|
|
|
|
2016-03-23 18:39:41 +01:00
|
|
|
def set_locale
|
|
|
|
I18n.locale = params[:locale] || I18n.default_locale
|
|
|
|
end
|
2019-01-07 12:48:22 +01:00
|
|
|
end
|