1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-13 23:48:55 +01:00
fab-manager/app/controllers/api/translations_controller.rb
2023-03-22 10:58:22 +01:00

24 lines
655 B
Ruby

# frozen_string_literal: true
# API Controller for managing front-end translations
class API::TranslationsController < API::APIController
before_action :set_locale
def show
translations = I18n.t params[:state]
if translations.instance_of?(String) && translations.start_with?('translation missing')
render json: { error: translations }, status: :unprocessable_entity
else
path = params[:state]
res = path.split('.').reverse.reduce(translations) { |r, e| { e.to_sym => r } }
render json: res, status: :ok
end
end
private
def set_locale
I18n.locale = params[:locale] || I18n.default_locale
end
end