mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-01 12:24:28 +01:00
7ac119d4cf
Eg. If locale is fr-CA, it was crashing. If locale was only fr, is was working. Now, composed locales print the watermark using the base locale and hour_minute format is fetched from the base locale
25 lines
661 B
Ruby
25 lines
661 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.class.name == String.name && 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
|