Skip to content

Commit

Permalink
Merge branch 'master' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni authored Oct 26, 2024
2 parents 817c1f5 + c5826d3 commit 45cdb79
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 17 deletions.
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ gem 'string-similarity'
gem 'inline_svg'

# ISO language codes and flags
gem "iso-639", "~> 0.3.6"
gem "flag-icons-rails", "~> 3.4"
gem 'flag-icons-rails', '~> 3.4'
gem 'iso-639', '~> 0.3.6'
gem 'countries', '~> 5.7'

# Custom API client
gem 'ontologies_api_client', git: 'https://github.com/ontoportal-lirmm/ontologies_api_ruby_client.git', branch: 'development'
Expand Down
6 changes: 5 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ GEM
coderay (1.1.3)
color (1.8)
concurrent-ruby (1.3.4)
countries (5.7.2)
unaccent (~> 0.3)
crack (1.0.0)
bigdecimal
rexml
Expand Down Expand Up @@ -530,7 +532,8 @@ GEM
railties (>= 6.0.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.6.0)
unaccent (0.4.0)
unicode-display_width (2.5.0)
uri (0.13.1)
version_gem (1.1.4)
view_component (2.83.0)
Expand Down Expand Up @@ -575,6 +578,7 @@ DEPENDENCIES
capybara
chart-js-rails
color (~> 1.8)
countries (~> 5.7)
dalli
debug
deepl-rb
Expand Down
11 changes: 4 additions & 7 deletions app/components/language_field_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@

class LanguageFieldComponent < ViewComponent::Base

include FlagIconsRails::Rails::ViewHelpers
include FlagIconsRails::Rails::ViewHelpers, MultiLanguagesHelper

def initialize(value:, label: nil, auto_label: false, icon: nil)
super
@value = value
@lang_code = nil
@label = label
@icon = icon

iso = ISO_639.find(value.to_s.split('/').last)
if iso
@lang_code = iso.alpha2
@label ||= iso.english_name if auto_label
end
@lang_code, label = find_language_code_name(value)
@label ||= label if auto_label
@lang_code = @lang_code.split('-').last if @lang_code
end

def lang_code
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class UsersController < ApplicationController

before_action :verify_owner, only: [:edit, :show, :subscribe, :un_subscribe]
before_action :verify_owner, only: [:edit, :subscribe, :un_subscribe]
before_action :authorize_admin, only: [:index,:subscribe, :un_subscribe]
layout :determine_layout

Expand Down
3 changes: 1 addition & 2 deletions app/helpers/collections_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def link_to_collection(collection, selected_collection_id)
pref_label_lang, pref_label_html = get_collection_label(collection)
tooltip = pref_label_lang.to_s.eql?('@none') ? '' : "data-controller='tooltip' data-tooltip-position-value='right' title='#{pref_label_lang.upcase}'"
<<-EOS
<a id="#{collection['@id']}" href="#{collection_path(collection['@id'], request_lang)}"
<a id="#{collection['@id']}" href="#{collection_path(collection['@id'], request_lang)}"
data-turbo="true" data-turbo-frame="collection" data-collectionid="#{collection['@id']}"
#{tooltip}
class="#{selected_collection_id.eql?(collection['@id']) ? 'active' : nil}">
Expand All @@ -91,4 +91,3 @@ def generate_collections_colors(collections)
end
end
end

24 changes: 20 additions & 4 deletions app/helpers/multi_languages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,31 @@ def content_languages(submission = @submission || @submission_latest)

# Transform each language into a select option
submission_lang = submission_lang.map do |lang|
lang = lang.split('/').last.upcase
lang = ISO_639.find(lang.to_s.downcase)
next nil unless lang
[lang.alpha2, lang.english_name]
code, name = find_language_code_name(lang)
next nil unless code
[code, name]
end.compact

[submission_lang, current_lang]
end

def find_language_code_name(language)
original_lang = language.to_s.split('/').last.upcase
lang, country = original_lang.split('-')

if country
lang = ISO3166::Country.find_country_by_alpha2(country)
return nil unless lang

[original_lang, lang.nationality]
else
lang = ISO_639.find(lang.to_s.downcase)
return nil unless lang

[lang.alpha2, lang.english_name]
end
end

def content_language_help_text
content_tag(:div, style: 'width: 350px;') do
concat content_tag(:div, t('language.content_language_help_text_1'))
Expand Down

0 comments on commit 45cdb79

Please sign in to comment.