Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature | Support multi-lingual: UI Internationalization #228

Merged
merged 31 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1842ace
Support multi-lingual: UI Internationalization ( use cookies , auto-l…
haddadzineddine Mar 30, 2023
5978086
Delete Gemfile.lock
haddadzineddine Mar 30, 2023
d58ff0c
refacto
haddadzineddine Mar 31, 2023
8175154
Merge branch 'feature/support-multi-lingual' of github.com:ontoportal…
haddadzineddine Mar 31, 2023
f92a183
update cookie['locale'] when we detect language first time
haddadzineddine Apr 1, 2023
f56ded8
Remove unnecessary comments
haddadzineddine Apr 1, 2023
95fdcef
store cookie[:locale] as permanent
haddadzineddine Apr 1, 2023
18031e8
manage platform language changes using separate Stimulus controllers
haddadzineddine Apr 4, 2023
59e52ca
fix and refacto
haddadzineddine Apr 5, 2023
da96e85
translate the footer and refacto
haddadzineddine Apr 11, 2023
be50567
Translate Home page
haddadzineddine Apr 11, 2023
94338cf
Translate search page
haddadzineddine Apr 12, 2023
4149c0c
Translate annotator page
haddadzineddine Apr 12, 2023
2d1a522
translate ontology_picker and recommender
haddadzineddine Apr 14, 2023
d4082f6
translate mapping
haddadzineddine Apr 14, 2023
9c7920e
clean up pages ( search + ncbo anotator plus )
haddadzineddine Apr 19, 2023
565098a
translate projects page
haddadzineddine Apr 19, 2023
0fb03cd
Update index.html.haml
haddadzineddine Apr 19, 2023
4f262c3
tramslate landscape
haddadzineddine Apr 19, 2023
19d685e
clean up
haddadzineddine Apr 20, 2023
9b5ac8c
translate ontology page
haddadzineddine Apr 20, 2023
850121e
Update en.yml
haddadzineddine Apr 20, 2023
ecd4e50
wip (ontology/name page)
haddadzineddine Apr 22, 2023
70183a8
Update en.yml
haddadzineddine Apr 22, 2023
d460c08
add footer translation feature
haddadzineddine Apr 23, 2023
040e7b3
Auto stash before merge of "feature/support-multi-lingual" and "origi…
syphax-bouazzouni May 3, 2023
0ddcd57
update the $HOME_PAGE_LOGOS config variable to be internationalizable
syphax-bouazzouni May 8, 2023
b77c27f
rename 'set_locale' to 'set_locale_language' to prevent name conflicts
syphax-bouazzouni May 8, 2023
b65a241
Merge branch 'development' into feature/support-multi-lingual
syphax-bouazzouni May 8, 2023
6914388
add rails-i18n gem to add french dates localization
syphax-bouazzouni May 8, 2023
9644023
add location for the ontology_viewer header
syphax-bouazzouni May 8, 2023
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ gem 'flamegraph'
gem 'graphql-client'
gem 'haml', '~> 5.1'
gem 'i18n'
gem 'rails-i18n', '~> 7.0.0'
gem 'iconv'
gem 'multi_json'
gem 'mysql2', '0.5.3'
Expand Down
108 changes: 67 additions & 41 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/ontoportal-lirmm/ontologies_api_ruby_client.git
revision: 0c8cd2b377d88b66a979664d5b16e5068b6d4548
revision: ca20880499a737803120f18ce99c14d3f10bc071
branch: development
specs:
ontologies_api_client (2.2.0)
Expand Down Expand Up @@ -82,7 +82,7 @@ GEM
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
addressable (2.8.1)
addressable (2.8.4)
public_suffix (>= 2.0.2, < 6.0)
airbrussh (1.4.1)
sshkit (>= 1.6.1, != 1.7.0)
Expand Down Expand Up @@ -115,7 +115,7 @@ GEM
capistrano-bundler (>= 1.1, < 3)
capistrano-yarn (2.0.2)
capistrano (~> 3.0)
capybara (3.38.0)
capybara (3.39.0)
addressable
matrix
mini_mime (>= 0.1.3)
Expand All @@ -129,11 +129,13 @@ GEM
coderay (1.1.3)
concurrent-ruby (1.2.2)
crass (1.0.6)
css_parser (1.14.0)
addressable
cube-ruby (0.0.3)
daemons (1.4.1)
dalli (3.2.4)
date (3.3.3)
debug (1.7.1)
debug (1.7.2)
irb (>= 1.5.0)
reline (>= 0.3.1)
diff-lcs (1.5.0)
Expand All @@ -158,7 +160,7 @@ GEM
flamegraph (0.9.5)
globalid (1.1.0)
activesupport (>= 5.0)
graphql (2.0.19)
graphql (2.0.21)
graphql-client (0.18.0)
activesupport (>= 3.0)
graphql
Expand All @@ -170,17 +172,19 @@ GEM
haml (>= 4.0)
nokogiri (>= 1.6.0)
ruby_parser (~> 3.5)
htmlbeautifier (1.4.2)
htmlentities (4.3.4)
http-accept (1.7.0)
http-cookie (1.0.5)
domain_name (~> 0.5)
i18n (1.12.0)
i18n (1.13.0)
concurrent-ruby (~> 1.0)
iconv (1.0.8)
importmap-rails (1.1.5)
importmap-rails (1.1.6)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
io-console (0.6.0)
irb (1.6.3)
irb (1.6.4)
reline (>= 0.3.0)
jquery-rails (4.5.1)
rails-dom-testing (>= 1, < 3)
Expand All @@ -194,9 +198,22 @@ GEM
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
loofah (2.19.1)
loofah (2.20.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
lookbook (1.5.5)
actioncable
activemodel
css_parser
htmlbeautifier (~> 1.3)
htmlentities (~> 4.3.4)
listen (~> 3.0)
railties (>= 5.0)
redcarpet (~> 3.5)
rouge (>= 3.26, < 5.0)
view_component (> 2.0, < 4)
yard (~> 0.9.25)
zeitwerk (~> 2.5)
lz4-ruby (0.3.3)
mail (2.8.1)
mini_mime (>= 0.1.1)
Expand All @@ -210,8 +227,9 @@ GEM
mime-types-data (~> 3.2015)
mime-types-data (3.2023.0218.1)
mini_mime (1.1.2)
mini_portile2 (2.8.2)
minitest (5.18.0)
msgpack (1.6.1)
msgpack (1.7.0)
multi_json (1.15.0)
multipart-post (2.3.0)
mysql2 (0.5.3)
Expand All @@ -233,14 +251,15 @@ GEM
net-protocol
net-ssh (7.1.0)
netrc (0.11.0)
newrelic_rpm (9.0.0)
nio4r (2.5.8)
nokogiri (1.14.2-x86_64-linux)
newrelic_rpm (9.2.2)
nio4r (2.5.9)
nokogiri (1.14.3)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
oj (3.14.2)
oj (3.14.3)
open_uri_redirections (0.2.1)
parallel (1.22.1)
parser (3.2.1.1)
parallel (1.23.0)
parser (3.2.2.1)
ast (~> 2.4.1)
popper_js (1.16.1)
pry (0.14.2)
Expand All @@ -251,10 +270,10 @@ GEM
puma (5.6.5)
nio4r (~> 2.0)
racc (1.6.2)
rack (2.2.6.4)
rack (2.2.7)
rack-accept (0.4.5)
rack (>= 0.4)
rack-mini-profiler (3.0.0)
rack-mini-profiler (3.1.0)
rack (>= 1.2.0)
rack-test (2.1.0)
rack (>= 1.3)
Expand All @@ -277,6 +296,9 @@ GEM
nokogiri (>= 1.6)
rails-html-sanitizer (1.5.0)
loofah (~> 2.19, >= 2.19.1)
rails-i18n (7.0.6)
i18n (>= 0.7, < 2)
railties (>= 6.0.0, < 8)
rails_autolink (1.1.8)
actionview (> 3.1)
activesupport (> 3.1)
Expand All @@ -296,43 +318,45 @@ GEM
rdoc (6.3.3)
recaptcha (5.9.0)
json
regexp_parser (2.7.0)
reline (0.3.2)
redcarpet (3.6.0)
regexp_parser (2.8.0)
reline (0.3.3)
io-console (~> 0.5)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.2.5)
rspec-core (3.12.1)
rouge (4.1.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.2)
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.4)
rspec-mocks (3.12.5)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-rails (6.0.1)
rspec-rails (6.0.2)
actionpack (>= 6.1)
activesupport (>= 6.1)
railties (>= 6.1)
rspec-core (~> 3.11)
rspec-expectations (~> 3.11)
rspec-mocks (~> 3.11)
rspec-support (~> 3.11)
rspec-core (~> 3.12)
rspec-expectations (~> 3.12)
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
rspec-support (3.12.0)
rubocop (1.48.1)
rubocop (1.50.2)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.2.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.26.0, < 2.0)
rubocop-ast (>= 1.28.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.28.0)
rubocop-ast (1.28.1)
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
Expand All @@ -348,11 +372,11 @@ GEM
sprockets-rails
tilt
select2-rails (4.0.13)
selenium-webdriver (4.8.3)
selenium-webdriver (4.9.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
sexp_processor (4.16.1)
sexp_processor (4.17.0)
spawnling (2.1.5)
sprockets (4.2.0)
concurrent-ruby (~> 1.0)
Expand All @@ -364,19 +388,19 @@ GEM
sshkit (1.21.4)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
stackprof (0.2.24)
stackprof (0.2.25)
stimulus-rails (1.2.1)
railties (>= 6.0.0)
temple (0.10.0)
terser (1.1.14)
execjs (>= 0.3.0, < 3)
thin (1.8.1)
thin (1.8.2)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0, >= 1.0.4)
rack (>= 1, < 3)
thor (1.2.1)
tilt (2.1.0)
time (0.2.1)
time (0.2.2)
date
timeout (0.3.2)
turbo-rails (1.4.0)
Expand All @@ -394,7 +418,7 @@ GEM
unf_ext
unf_ext (0.0.8.2)
unicode-display_width (2.4.2)
uri (0.12.0)
uri (0.12.1)
view_component (2.82.0)
activesupport (>= 5.2.0, < 8.0)
concurrent-ruby (~> 1.0)
Expand All @@ -415,10 +439,11 @@ GEM
will_paginate (3.3.1)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.7)
yard (0.9.34)
zeitwerk (2.6.8)

PLATFORMS
x86_64-linux
ruby

DEPENDENCIES
bcrypt_pbkdf (>= 1.0, < 2.0)
Expand Down Expand Up @@ -448,6 +473,7 @@ DEPENDENCIES
jquery-ui-rails
jsbundling-rails
listen
lookbook (~> 1.5.5)
multi_json
mysql2 (= 0.5.3)
net-ftp (~> 0.2.0)
Expand All @@ -461,6 +487,7 @@ DEPENDENCIES
puma (~> 5.0)
rack-mini-profiler
rails (= 7.0.3)
rails-i18n (~> 7.0.0)
rails_autolink
rdoc
recaptcha (~> 5.9.0)
Expand All @@ -484,5 +511,4 @@ DEPENDENCIES
will_paginate (~> 3.0)

BUNDLED WITH
2.3.23

2.4.12
23 changes: 23 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,29 @@
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base

before_action :set_locale

# Sets the locale based on the locale cookie or the value returned by detect_locale.
def set_locale
syphax-bouazzouni marked this conversation as resolved.
Show resolved Hide resolved
I18n.locale = cookies[:locale] || detect_locale
cookies.permanent[:locale] = I18n.locale if cookies[:locale].nil?
end

# Returns detedted locale based on the Accept-Language header of the request or the default locale if none is found.
def detect_locale
languages = request.headers['Accept-Language']&.split(',')
supported_languages = I18n.available_locales

languages.each do |language|
language_code = language.split(/[-;]/).first.downcase.to_sym
return language_code if supported_languages.include?(language_code)
end

return I18n.default_locale
end


helper :all # include all helpers, all the time
helper_method :bp_config_json, :current_license, :using_captcha?
rescue_from ActiveRecord::RecordNotFound, with: :not_found_record
Expand Down
21 changes: 21 additions & 0 deletions app/controllers/language_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class LanguageController < ApplicationController

# set locale to the language selected by the user
def set_locale_language
language = params[:language].strip.downcase.to_sym
supported_languages = I18n.available_locales

if language
if supported_languages.include?(language)
cookies.permanent[:locale] = language
else
# in case we want to show a message if the language is not available
flash.now[:notice] = "#{language} translation not available"
logger.error flash.now[:notice]
end
end

redirect_to request.referer || root_path
end

end
15 changes: 6 additions & 9 deletions app/helpers/home_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
module HomeHelper

def render_footer_link(options = {})

link_content = options[:text].presence
link_content ||= image_tag(options[:img_src]) if options[:img_src].present?
link_content ||= content_tag(:i, '', class: options[:icon]) if options[:icon].present?

unless link_content.blank?
link_to(link_content, options[:url], target: options[:target], class: options[:css_class].to_s, style: options[:text].blank? ? 'text-decoration: none' : '')
end.to_s.html_safe

link_content = options[:text][I18n.locale] || options[:text][:en] if options[:text]
link_content ||= image_tag(options[:img_src]) if options[:img_src]
link_content ||= content_tag(:i, '', class: options[:icon]) if options[:icon]

link_to(link_content, options[:url], target: options[:target], class: options[:css_class].to_s, style: options[:text].blank? ? 'text-decoration: none' : '').html_safe if link_content
end

end
10 changes: 4 additions & 6 deletions app/helpers/schemes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ def get_schemes_labels(schemes, main_uri)
end

def concept_label_to_show(submission: @submission_latest)
submission&.hasOntologyLanguage == 'SKOS' ? 'Concepts' : 'Classes'
submission&.hasOntologyLanguage == 'SKOS' ? 'concepts' : 'classes'
end

def section_name(section)
if section.eql?('classes')
concept_label_to_show(submission: @submission_latest || @submission)
else
section.capitalize
end
section = concept_label_to_show(submission: @submission_latest || @submission) if section.eql?('classes')

t("ontology_details.sections.#{section}")
end

def scheme_path(scheme_id = '')
Expand Down
Loading