translation_languages_controller.rb 589 B

123456789101112131415161718192021
  1. # frozen_string_literal: true
  2. class Api::V1::Instances::TranslationLanguagesController < Api::V1::Instances::BaseController
  3. before_action :set_languages
  4. def show
  5. cache_even_if_authenticated!
  6. render json: @languages
  7. end
  8. private
  9. def set_languages
  10. if TranslationService.configured?
  11. @languages = Rails.cache.fetch('translation_service/languages', expires_in: 7.days, race_condition_ttl: 1.hour) { TranslationService.configured.languages }
  12. @languages['und'] = @languages.delete(nil) if @languages.key?(nil)
  13. else
  14. @languages = {}
  15. end
  16. end
  17. end