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: Show multiple languages #252

Merged
merged 55 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
3e1fde5
refactor ontology_viewer_page_name to support multiple languages
haddadzineddine May 23, 2023
0b9282c
refactor sort_by in collection and schemes to support multiple languges
haddadzineddine May 23, 2023
fc4d801
update ontology_viewer title
haddadzineddine May 23, 2023
24ad1b3
add all option in language selection
haddadzineddine May 23, 2023
52eed1f
show prefLabel with the specific language in case of all languages
haddadzineddine May 23, 2023
f26ac9f
Merge branch 'development' into feature/support-multilingual-part-2
haddadzineddine May 25, 2023
ce1a5eb
remove a forgotten debugger in the JS code of language change selector
syphax-bouazzouni May 25, 2023
2c8cb2e
revert concept details prefLabel multiple language display
syphax-bouazzouni May 25, 2023
06b25b1
show corresponding lang in the tree view
haddadzineddine Jun 1, 2023
ac88108
Show data in platform language when lang is equal to 'all'
haddadzineddine Jun 2, 2023
b44bc2f
fix sort_by in collections and schemes
haddadzineddine Jun 2, 2023
34560ff
make sub.publication iterable
haddadzineddine Jun 6, 2023
47844be
use tooltip to show language in concept tree links
haddadzineddine Jun 6, 2023
12b596e
Merge branch 'development' into feature/support-multilingual-part-2
haddadzineddine Jun 6, 2023
601d1a4
use display_in_multiple_languges methode to show properties in multip…
haddadzineddine Jun 8, 2023
358c741
add tooltips to show language in tree view
haddadzineddine Jun 8, 2023
c41181e
change 'process_concept' method name to 'language_hash'
haddadzineddine Jun 8, 2023
5c95ca5
define 'display_in_multiple_languages' method
haddadzineddine Jun 8, 2023
6a0c667
use 'langauge_hash' methode in collection instead of 'process_concept'
haddadzineddine Jun 8, 2023
a77722d
cls_id to string
haddadzineddine Jun 8, 2023
c5dd8df
use 'langauge_hash' methode in schemes instead of 'process_concept'
haddadzineddine Jun 8, 2023
6e453dd
update tooltip controller to support position
haddadzineddine Jun 8, 2023
600aafe
use 'langauge_hash' methode in _list_view instead of 'process_concept'
haddadzineddine Jun 8, 2023
b98c2ed
use 'display_in_multiple_languges' to display properties
haddadzineddine Jun 8, 2023
cf8749b
fix missing 'end' in application helper
haddadzineddine Jun 8, 2023
cf0db95
Merge branch 'development' into feature/support-multilingual-part-2
haddadzineddine Jun 8, 2023
460ba3d
display_in_multiple_languges in schemes
haddadzineddine Jun 8, 2023
26c44f8
fix language_hash method name typo
haddadzineddine Jun 8, 2023
f2842cc
check if prefLabel is nil
haddadzineddine Jun 8, 2023
53694c8
use tooltip to show preLabel lang in schemes
haddadzineddine Jun 8, 2023
712fa30
use tooltip to show preLabel lang in collections
haddadzineddine Jun 8, 2023
443dfd9
use tooltip in collection
haddadzineddine Jun 8, 2023
5d2761d
fix a typo display_in_multiple_languages function name
syphax-bouazzouni Jun 8, 2023
346830e
extract link_to_scheme helper for schemes tree view
syphax-bouazzouni Jun 8, 2023
e6bf7d9
extract helpers to display the collections list view
syphax-bouazzouni Jun 8, 2023
df63373
refactor language related helpers code in application_helper
syphax-bouazzouni Jun 8, 2023
feb3cd5
add language argument to scheme and collection tree links
syphax-bouazzouni Jun 8, 2023
8dd39bf
refactor scheme and collection helpers to make it work for mutli-langs
syphax-bouazzouni Jun 8, 2023
98f131a
fix sort in tree_link_to_concept and add return first in array on lan…
haddadzineddine Jun 12, 2023
a328e3e
extract multi language helpers into a file
syphax-bouazzouni Jul 5, 2023
bea6a18
make display_in_multiple_languages directly do the language_hash inside
syphax-bouazzouni Jul 5, 2023
048b15c
rename the helper get_concept_label to select_language_label
syphax-bouazzouni Jul 5, 2023
ced6cfc
Merge branch 'development' into feature/support-multilingual-part-2
syphax-bouazzouni Sep 3, 2023
510c5b7
move the not found prefLabel alert in the prefLabel row
syphax-bouazzouni Sep 4, 2023
2274ff6
catch concept list error when concept label is nil
syphax-bouazzouni Sep 4, 2023
7aec67c
add main_language_label helper to show the concept label main languag…
syphax-bouazzouni Sep 4, 2023
5709a22
fix loader showed in small state by default
syphax-bouazzouni Sep 4, 2023
71ad5cc
fix alert component text overflowing
syphax-bouazzouni Sep 4, 2023
0443f4b
reset turbo progress bar to blue
syphax-bouazzouni Sep 4, 2023
b57afde
add id to tabs container component
syphax-bouazzouni Sep 4, 2023
e5fe3ce
extract sorted_labels helpers for schemes and collections
syphax-bouazzouni Sep 4, 2023
01e032d
fix mappings new form not finding the ontology by id bu by acronym
syphax-bouazzouni Sep 4, 2023
74a4440
use main_language_label helper for build_tree
syphax-bouazzouni Sep 4, 2023
c9c8d2a
use main_language_label helper in ontology_viewer_page_name
syphax-bouazzouni Sep 4, 2023
ab83696
restore removed properties section content
syphax-bouazzouni Sep 4, 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
2 changes: 1 addition & 1 deletion app/assets/stylesheets/bioportal.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.turbo-progress-bar {
height: 5px;
background-color: var(--light-color);
background-color: var(--admin-color);
}

a{
Expand Down
13 changes: 11 additions & 2 deletions app/components/concept_details_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class ConceptDetailsComponent < ViewComponent::Base
include ApplicationHelper
include MultiLanguagesHelper

renders_one :header, TableComponent
renders_many :sections, TableRowComponent
Expand Down Expand Up @@ -43,7 +44,11 @@ def row_hash_properties(properties_set, ontology_acronym, &block)
if block_given?
block.call(v)
else
get_link_for_cls_ajax(v, ontology_acronym, '_blank')
if v.is_a?(String)
get_link_for_cls_ajax(v, ontology_acronym, '_blank')
else
display_in_multiple_languages([v].to_h)
end
end
end

Expand Down Expand Up @@ -120,7 +125,11 @@ def concept_properties2hash(properties)
end
begin
# Try to simplify the property values, when they are a struct.
values = properties[key].map { |v| v.string }
if properties[key].is_a?(OpenStruct)
values = language_hash(properties[key])
else
values = properties[key].map { |v| v.string }
end
rescue
# Each value is probably a simple datatype already.
values = properties[key]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'alert-component-auto-close-value': auto_close?,
'alert-component-auto-close-after-value': @auto_close_delay,
},
class: alert_type_class}
class: alert_type_class, style: 'white-space: normal;'}
.alert-icon{class: alert_type_class}
= inline_svg_tag alert_icon
.alert-message{class: alert_type_class}
Expand Down
8 changes: 0 additions & 8 deletions app/components/loader_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,4 @@ def call
end
end
end

def small?
@small
end
def small_class
"spinner-border-sm"
end

end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%div{data: {controller:'tabs-container'}, class: container_class}
%div{data: {controller:'tabs-container'}, class: container_class, id: @id}
%div
.tab-items.nav
- items.each do |item|
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def show_label
collection_label = collection['prefLabel'] if collection
collection_label = params[:id] if collection_label.nil? || collection_label.empty?

render LabelLinkComponent.inline(params[:id], collection_label)
render LabelLinkComponent.inline(params[:id], helpers.main_language_label(collection_label))
end

def show_members
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concepts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def show_label
return
end

render LabelLinkComponent.inline(cls_id, concept_label(ont_id, cls_id))
render LabelLinkComponent.inline(cls_id, helpers.main_language_label(concept_label(ont_id, cls_id)))
end

def show_definition
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/label_xl_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def show_label
label_xl_label = label_xl ? label_xl['literalForm'] : nil
label_xl_label = params[:id] if label_xl_label.nil? || label_xl_label.empty?

render LabelLinkComponent.inline(params[:id], label_xl_label)
render LabelLinkComponent.inline(params[:id], helpers.main_language_label(label_xl_label))
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/mappings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ def mapping_form(mapping: nil)
end
else
mapping = LinkedData::Client::Models::Mapping.new
@ontology_from = LinkedData::Client::Models::Ontology.find(params[:ontology_from])
@ontology_to = LinkedData::Client::Models::Ontology.find(params[:ontology_to])
@ontology_from = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology_from].split('/').last).first
@ontology_to = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology_to]&.split('/')&.last).first
@concept_from = @ontology_from.explore.single_class({ full: true }, params[:conceptid_from]) if @ontology_from
if @ontology_to
@concept_to = @ontology_to.explore.single_class({ full: true }, params[:conceptid_to])
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/schemes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def show_label
scheme_label = scheme ? scheme['prefLabel'] : params[:id]
scheme_label = scheme_label.nil? || scheme_label.empty? ? params[:id] : scheme_label

render LabelLinkComponent.inline(params[:id], scheme_label)
render LabelLinkComponent.inline(params[:id], helpers.main_language_label(scheme_label))
end

private
Expand Down
38 changes: 26 additions & 12 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module ApplicationHelper
REST_URI = $REST_URL
API_KEY = $API_KEY

include ModalHelper
include ModalHelper, MultiLanguagesHelper

RESOLVE_NAMESPACE = {:omv => "http://omv.ontoware.org/2005/05/ontology#", :skos => "http://www.w3.org/2004/02/skos/core#", :owl => "http://www.w3.org/2002/07/owl#",
:rdf => "http://www.w3.org/1999/02/22-rdf-syntax-ns#", :rdfs => "http://www.w3.org/2000/01/rdf-schema#", :metadata => "http://data.bioontology.org/metadata/",
Expand All @@ -23,6 +23,7 @@ module ApplicationHelper
:oboInOwl => "http://www.geneontology.org/formats/oboInOwl#", :idot => "http://identifiers.org/idot/", :sd => "http://www.w3.org/ns/sparql-service-description#",
:cclicense => "http://creativecommons.org/licenses/"}


def get_apikey
unless session[:user].nil?
return session[:user].apikey
Expand Down Expand Up @@ -186,8 +187,8 @@ def draw_tree(root, id = nil, concept_schemes = [])
def build_tree(node, string, id, concept_schemes: [])

return string if node.children.nil? || node.children.empty?

node.children.sort! { |a, b| (a.prefLabel || a.id).downcase <=> (b.prefLabel || b.id).downcase }
node.children.sort! { |a, b| (main_language_label(a.prefLabel) || a.id).downcase <=> (main_language_label(a.prefLabel) || b.id).downcase }
node.children.each do |child|
active_style = child.id.eql?(id) ? "active" : ''

Expand Down Expand Up @@ -219,14 +220,27 @@ def tree_link_to_concept(child:, ontology_acronym:, active_style:, node: nil)
icons = child.relation_icon(node)
muted_style = child.isInActiveScheme&.empty? ? 'text-muted' : ''
href = ontology_acronym.blank? ? '#' : "/ontologies/#{child.explore.ontology.acronym}/concepts/?id=#{CGI.escape(child.id)}&language=#{language}"

if child.prefLabel.nil?
prefLabelHTML = child.id.split('/').last
else
prefLabelLang, prefLabelHTML = select_language_label(child.prefLabel)
prefLabelLang = prefLabelLang.to_s.upcase
tooltip = prefLabelLang.eql?("@NONE") ? "" : "data-controller='tooltip' data-tooltip-position-value='right' title='#{prefLabelLang}'";
end

link = <<-EOS
<a id='#{child.id}' data-conceptid='#{child.id}'
data-turbo=true data-turbo-frame='concept_show' href='#{href}'
data-collections-value='#{child.memberOf || []}'
data-active-collections-value='#{child.isInActiveCollection || []}'
data-skos-collection-colors-target='collection'
class='#{muted_style} #{active_style}'>
#{child.prefLabel ? child.prefLabel({ use_html: true }) : child.id.split('/').last}
<a id='#{child.id}'
data-conceptid='#{child.id}'
data-turbo=true data-turbo-frame='concept_show' href='#{href}'
data-collections-value='#{child.memberOf || []}'
data-active-collections-value='#{child.isInActiveCollection || []}'
data-skos-collection-colors-target='collection'
class='#{muted_style} #{active_style}'
#{tooltip}
>
#{ prefLabelHTML }

</a>
EOS

Expand Down Expand Up @@ -604,8 +618,8 @@ def get_link_for_label_xl_ajax(label_xl, ont_acronym, cls_id)
end

###END ruby equivalent of JS code in bp_ajax_controller.
def ontology_viewer_page_name(ontology_name, concept_name_title , page)
ontology_name + " | " +concept_name_title + " - #{page.capitalize}"
def ontology_viewer_page_name(ontology_name, concept_label, page)
ontology_name + " | " + main_language_label(concept_label) + " - #{page.capitalize}"
end


Expand Down
26 changes: 22 additions & 4 deletions app/helpers/collections_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ def get_collections_labels(collections, main_uri = '')
collections_labels = []
collections.each do |x|
id = x['@id']
label = get_collection_label(x)
label = select_language_label(get_collection_label(x))
if id.eql? main_uri
selected_label = { 'prefLabel' => label, '@id' => id }
else
collections_labels.append( { 'prefLabel' => label, '@id' => id , 'color' => x['color'] })
end
end
collections_labels.sort_by! { |s| s['prefLabel']}

collections_labels = sorted_labels(collections_labels)
collections_labels.unshift selected_label if selected_label
[collections_labels, selected_label]
end
Expand All @@ -47,14 +48,31 @@ def no_collections_alert
end
end

def collection_path(collection_id = '')
"/ontologies/#{@ontology.acronym}/collections/show?id=#{escape(collection_id)}"
def collection_path(collection_id = '', language = '')
"/ontologies/#{@ontology.acronym}/collections/show?id=#{escape(collection_id)}&language=#{language}"
end

def request_collection_id
params[:id] || params[:collection_id] || params[:concept_collection]
end

def sort_collections_label(collections_labels)
sorted_labels(collections_labels)
end

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)}"
data-turbo="true" data-turbo-frame="collection" data-collectionid="#{collection['@id']}"
#{tooltip}
class="#{selected_collection_id.eql?(collection['@id']) ? 'active' : nil}">
#{pref_label_html}
</a>
EOS
end

private

def generate_collections_colors(collections)
Expand Down
63 changes: 63 additions & 0 deletions app/helpers/multi_languages_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
module MultiLanguagesHelper

def language_hash(concept_label)

return concept_label.first if concept_label.is_a?(Array)
return concept_label.to_h.reject { |key, _| %i[links context].include?(key) } if concept_label.is_a?(OpenStruct)

concept_label
end

def sorted_labels(labels)
Array(labels).sort_by { |label| label['prefLabel'].is_a?(String) ? label['prefLabel'] : label['prefLabel'].last }
end

def select_language_label(concept_label, platform_languages = %i[en fr])
concept_value = nil

concept = language_hash(concept_label)

return ['@none', concept] if concept.is_a?(String)

concept = concept.to_h

platform_languages.each do |lang|
if concept[lang]
concept_value = [lang, concept[lang]]
break
end
end

concept_value || concept.to_a.first
end

def main_language_label(label)
select_language_label(label)&.last
end

def display_in_multiple_languages(label)
label = language_hash(label)

if label.nil?
return render Display::AlertComponent.new(message: t('ontology_details.concept.no_preferred_name_for_selected_language'),
type: "warning",
closable: true)
end

return content_tag(:p, label) if label.is_a?(String)

raw(label.map do |key, value|
content_tag(:div, class: 'd-flex align-items-center') do
concat content_tag(:p, Array(value).join(', '), class: 'm-0')

unless key.to_s.upcase.eql?('NONE') || key.to_s.upcase.eql?('@NONE')
concat content_tag(:span, key.upcase, class: 'badge badge-secondary ml-1')
end
end
end.join)
end

def selected_language_label(label)
language_hash(label).values.first
end
end
12 changes: 9 additions & 3 deletions app/helpers/ontologies_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,24 +311,30 @@ def language_selector_hidden_tag(section)
data: { controller: "language-change", 'language-change-section-value': section, action: "change->language-change#dispatchLangChangeEvent" }
end

def languages_options(submission = @submission || @submission_latest)
current_lang = request_lang
syphax-bouazzouni marked this conversation as resolved.
Show resolved Hide resolved
def languages_options(submission = @submission || @submission_latest)
current_lang = request_lang.downcase
submission_lang = submission_languages(submission)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here handle the case, where submission_languages is empty.

# Transform each language into a select option
submission_lang = submission_lang.map do |lang|
lang = lang.split('/').last.upcase
[lang, lang, { selected: lang.eql?(current_lang) }]
end

# Add the option to select all language
submission_lang.push(['All', 'all', { selected: current_lang.eql?('all') }])

options_for_select(submission_lang)
end

def dispaly_complex_text(definitions)
def display_complex_text(definitions)
html = ""
definitions.each do |definition|
if definition.is_a?(String)
html += '<p class="prefLabel">' + definition + '</p>'
elsif definition.respond_to?(:uri) && definition.uri
html += render LinkFieldComponent.new(value: definition.uri)
else
html += display_in_multiple_languages(definition)
end
end
return html.html_safe
Expand Down
Loading