Skip to content

Commit

Permalink
Merge pull request #32 from ontoportal-lirmm/feature/support-multilin…
Browse files Browse the repository at this point in the history
…gual-read-one-language-from-request-parameter

Feature: Support multilingual - Add request_lang middleware
  • Loading branch information
syphax-bouazzouni committed Sep 5, 2023
1 parent 9152756 commit c0c5e0e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ gem 'rake', '~> 10.0'
gem 'sinatra', '~> 1.0'
gem 'sinatra-advanced-routes'
gem 'sinatra-contrib', '~> 1.0'
gem 'request_store'

# Rack middleware
gem 'ffi'
Expand All @@ -26,7 +27,7 @@ gem 'rack-timeout'
gem 'redis-rack-cache', '~> 2.0'

# Data access (caching)
gem 'redis'
gem 'redis', '~> 4.8.1'
gem 'redis-activesupport'

# Monitoring
Expand Down
31 changes: 17 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/goo.git
revision: c3456c45c12ed92d4a3ae43cac7c1d4cdbf290b6
revision: b769c165906163e30a026dba511ae1069c4eed3d
branch: development
specs:
goo (0.0.2)
Expand Down Expand Up @@ -53,7 +53,7 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git
revision: 4ac9873f3d016259196a17cfc9c6ab8149468ec9
revision: 69756f8a7cff39d283065217559c68820d6d95e3
branch: development
specs:
ontologies_linked_data (0.0.1)
Expand Down Expand Up @@ -112,7 +112,7 @@ GEM
bcrypt_pbkdf (1.1.0)
bigdecimal (1.4.2)
builder (3.2.4)
capistrano (3.17.1)
capistrano (3.17.2)
airbrussh (>= 1.0.0)
i18n
rake (>= 10.0.0)
Expand All @@ -125,7 +125,7 @@ GEM
capistrano (~> 3.1)
sshkit (~> 1.3)
coderay (1.1.3)
concurrent-ruby (1.2.0)
concurrent-ruby (1.2.2)
cube-ruby (0.0.3)
dante (0.2.0)
date (3.3.3)
Expand Down Expand Up @@ -160,8 +160,8 @@ GEM
ffi (1.15.5)
get_process_mem (0.2.7)
ffi (~> 1.0)
google-apis-analytics_v3 (0.12.0)
google-apis-core (>= 0.9.1, < 2.a)
google-apis-analytics_v3 (0.13.0)
google-apis-core (>= 0.11.0, < 2.a)
google-apis-core (0.11.0)
addressable (~> 2.5, >= 2.5.1)
googleauth (>= 0.16.2, < 2.a)
Expand Down Expand Up @@ -206,7 +206,7 @@ GEM
method_source (1.0.0)
mime-types (3.4.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2022.0105)
mime-types-data (3.2023.0218.1)
mini_mime (1.1.2)
minitest (4.7.5)
minitest-stub_any_instance (1.0.3)
Expand All @@ -228,7 +228,7 @@ GEM
net-protocol
net-ssh (7.0.1)
netrc (0.11.0)
newrelic_rpm (9.2.1)
newrelic_rpm (9.0.0)
oj (2.18.5)
omni_logger (0.1.4)
logger
Expand Down Expand Up @@ -256,7 +256,7 @@ GEM
rack-test (2.0.2)
rack (>= 1.3)
rack-timeout (0.6.3)
raindrops (0.20.0)
raindrops (0.20.1)
rake (10.5.0)
rdf (1.0.8)
addressable (>= 2.2)
Expand All @@ -268,12 +268,14 @@ GEM
redis-rack-cache (2.2.1)
rack-cache (>= 1.10, < 2)
redis-store (>= 1.6, < 2)
redis-store (1.9.1)
redis (>= 4, < 5)
redis-store (1.9.2)
redis (>= 4, < 6)
representable (3.2.0)
declarative (< 0.1.0)
trailblazer-option (>= 0.1.1, < 0.2.0)
uber (< 0.2.0)
request_store (1.5.1)
rack (>= 1.4)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
Expand Down Expand Up @@ -316,12 +318,12 @@ GEM
rack-test
sinatra (~> 1.4.0)
tilt (>= 1.3, < 3)
sshkit (1.21.3)
sshkit (1.21.4)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
systemu (2.6.5)
temple (0.10.0)
tilt (2.0.11)
tilt (2.1.0)
timeout (0.3.2)
trailblazer-option (0.1.2)
tzinfo (2.0.6)
Expand Down Expand Up @@ -382,9 +384,10 @@ DEPENDENCIES
rack-timeout
rake (~> 10.0)
redcarpet
redis
redis (~> 4.8.1)
redis-activesupport
redis-rack-cache (~> 2.0)
request_store
shotgun!
simplecov
simplecov-cobertura
Expand Down
6 changes: 6 additions & 0 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@
require_relative 'lib/rack/cube_reporter'
require_relative 'lib/rack/param_translator'
require_relative 'lib/rack/slice_detection'
require_relative 'lib/rack/request_lang'

# Logging setup
require_relative "config/logging"

# Inflector setup
require_relative "config/inflections"

require 'request_store'

# Protection settings
set :protection, :except => :path_traversal

Expand Down Expand Up @@ -143,6 +146,9 @@
use Rack::PostBodyToParams
use Rack::ParamTranslator

use RequestStore::Middleware
use Rack::RequestLang

use LinkedData::Security::Authorization
use LinkedData::Security::AccessDenied

Expand Down
16 changes: 16 additions & 0 deletions lib/rack/request_lang.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Rack
class RequestLang

def initialize(app = nil, options = {})
@app = app
end

def call(env)
r = Rack::Request.new(env)
lang = r.params["lang"] || r.params["language"]
lang = lang.upcase.to_sym if lang
RequestStore.store[:requested_lang] = lang
@app.call(env)
end
end
end

0 comments on commit c0c5e0e

Please sign in to comment.