Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/controllers/translator/translations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ def destroy
redirect_to :back unless request.xhr?
end

def locale
I18n.locale = params[:loc] || I18n.default_locale

keys = Translator.keys_for_strings
translations = Hash[keys.map { |key|
[
key,
begin I18n.t key; rescue; end
]
}]

render json: translations
end

private

def auth
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
collection do
get :export
post :import
get 'locale/:loc', to: 'translations#locale', as: :by_locale, defaults: { format: 'json' }
end
end
end
21 changes: 21 additions & 0 deletions spec/controller/translator/translations_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require_relative '../../spec_helper'

describe Translator::TranslationsController, type: :controller do

before :each do
Translator.current_store = Translator::RedisStore.new(Redis.new)
I18n.backend = Translator.setup_backend(I18n::Backend::Simple.new)
Translator.current_store.clear_database
end

describe 'by_locale' do
it "has endpoint returning translations in JSON format" do
get 'locale', loc: 'en', use_route: :translator
json = JSON.parse(response.body)
Translator.keys_for_strings.each do |key|
expect(json).to have_key(key)
end
end
end
end

1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# methods or matchers
require 'rspec/expectations'
config.include RSpec::Matchers
config.include Rails.application.routes.url_helpers

# == Mock Framework
config.mock_with :rspec
Expand Down