forked from ontoportal/ontoportal_web_ui
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Show multiple languages (#252)
* refactor ontology_viewer_page_name to support multiple languages * refactor sort_by in collection and schemes to support multiple languges * update ontology_viewer title * add all option in language selection * show prefLabel with the specific language in case of all languages * remove a forgotten debugger in the JS code of language change selector * revert concept details prefLabel multiple language display * show corresponding lang in the tree view * Show data in platform language when lang is equal to 'all' * fix sort_by in collections and schemes * make sub.publication iterable * use tooltip to show language in concept tree links * use display_in_multiple_languges methode to show properties in multiple langs * add tooltips to show language in tree view * change 'process_concept' method name to 'language_hash' * define 'display_in_multiple_languages' method * use 'langauge_hash' methode in collection instead of 'process_concept' * cls_id to string * use 'langauge_hash' methode in schemes instead of 'process_concept' * update tooltip controller to support position * use 'langauge_hash' methode in _list_view instead of 'process_concept' * use 'display_in_multiple_languges' to display properties * fix missing 'end' in application helper * display_in_multiple_languges in schemes * fix language_hash method name typo * check if prefLabel is nil * use tooltip to show preLabel lang in schemes * use tooltip to show preLabel lang in collections * use tooltip in collection * fix a typo display_in_multiple_languages function name * extract link_to_scheme helper for schemes tree view * extract helpers to display the collections list view * refactor language related helpers code in application_helper * add language argument to scheme and collection tree links * refactor scheme and collection helpers to make it work for mutli-langs * fix sort in tree_link_to_concept and add return first in array on language_hash methode * extract multi language helpers into a file * make display_in_multiple_languages directly do the language_hash inside * rename the helper get_concept_label to select_language_label * move the not found prefLabel alert in the prefLabel row * catch concept list error when concept label is nil * add main_language_label helper to show the concept label main language label * fix loader showed in small state by default * fix alert component text overflowing * reset turbo progress bar to blue * add id to tabs container component * extract sorted_labels helpers for schemes and collections * fix mappings new form not finding the ontology by id bu by acronym * use main_language_label helper for build_tree * use main_language_label helper in ontology_viewer_page_name * restore removed properties section content --------- Co-authored-by: Syphax Bouazzouni <gs_bouazzouni@esi.dz>
- Loading branch information
1 parent
9c2bb25
commit 421f5a0
Showing
27 changed files
with
258 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,4 @@ def call | |
end | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.