Manage the remote translation button display

- Add remote_translation_button partial to layout
- Only display button when we have remote_translations and if current
  locale is include on available locales from remote translations service.
- Recover available locales from remote translations service.
  Use daily_cache to detect every day if remote translation service has
  added new available locale.

Co-Authored-By: alessandro <agileontheweb@gmail.com>
This commit is contained in:
taitus
2019-01-25 16:32:46 +01:00
committed by voodoorai2000
parent cbd7ab7179
commit 72d1893703
4 changed files with 104 additions and 2 deletions

View File

@@ -5,8 +5,10 @@ require "json"
module RemoteTranslations::Microsoft::AvailableLocales
def load_remote_locales
remote_available_locales.map { |locale| locale.first }
def available_locales
daily_cache("locales") do
remote_available_locales.map { |locale| locale.first }
end
end
def parse_locale(locale)
@@ -22,6 +24,10 @@ module RemoteTranslations::Microsoft::AvailableLocales
end
end
def include_locale?(locale)
available_locales.include?(parse_locale(locale).to_s)
end
private
def remote_available_locales
@@ -42,4 +48,8 @@ module RemoteTranslations::Microsoft::AvailableLocales
JSON.parse(result)["translation"]
end
def daily_cache(key, &block)
Rails.cache.fetch("remote_available_locales/#{Time.current.strftime('%Y-%m-%d')}/#{key}", &block)
end
end