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

Fix: Some bugs in the pre-release 2.7.4 including internationalisation and code cleaning #554

Merged
merged 19 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6fffb76
remove old no more used controller
syphax-bouazzouni Mar 26, 2024
c88887c
correct the casing of the imported stimulus controller
syphax-bouazzouni Mar 26, 2024
9ed3870
remove the internationalization of template string the search components
syphax-bouazzouni Mar 26, 2024
c09ca03
update internationilaztion helper to add the class method version
syphax-bouazzouni Mar 26, 2024
4cc59dd
clean the include of internationalisation helper in some files
syphax-bouazzouni Mar 26, 2024
4da8ef2
remove unused helper
syphax-bouazzouni Mar 26, 2024
a68e17a
remove the switch from the metadata curator
syphax-bouazzouni Mar 26, 2024
d5e2cf2
update the search input stimulus controller to add searchEndpoint value
syphax-bouazzouni Mar 26, 2024
fdabcfc
clean some old usage to jquery chosen to prepare its total removal
syphax-bouazzouni Mar 27, 2024
6ecda6d
fix project index edit button translation missing
syphax-bouazzouni Mar 27, 2024
03a5e6b
handle the case of corrupted agents in the landscape
syphax-bouazzouni Mar 27, 2024
6a77f5d
catch the missing translation in the overided internationalization
syphax-bouazzouni Mar 27, 2024
e99d29b
fix duplicated translations
syphax-bouazzouni Mar 27, 2024
0fb44df
complete missing translations and clean the en.yml file
syphax-bouazzouni Mar 27, 2024
5626a12
complete and clean the fr.yml file
syphax-bouazzouni Mar 27, 2024
665e8c0
fix translation upcasing
syphax-bouazzouni Mar 28, 2024
39fce38
fix internationlization not displayed well as sanitized
syphax-bouazzouni Mar 28, 2024
eb608b1
re-write the french translations
syphax-bouazzouni Mar 28, 2024
f42ef43
add edit submission french translations
syphax-bouazzouni Mar 29, 2024
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
7 changes: 0 additions & 7 deletions app/assets/javascripts/bp_landscape.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,6 @@ $(document).mouseup(function (e)
}
});

jQuery(document).ready(function() {
"use strict";
// enable selected search
jQuery("#selected_relations").chosen({
search_contains: true
});
})

// Hide more properties pie div on load to let the pie lib the time to get the parent div size (to size the pie chart)
window.onload = function() {
Expand Down
2 changes: 0 additions & 2 deletions app/assets/javascripts/bp_mappings.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ jQuery(document).ready(function(){
updateMappingCount();
updateMappingDeletePermissions();

jQuery("#search_ontologies").chosen({search_contains: true, width:"100%"});

// Handle visualization changes
jQuery("#display_options input").on("click", function(e, button){
var selectedOnt = jQuery("#search_ontologies").val();
Expand Down
6 changes: 0 additions & 6 deletions app/assets/stylesheets/components/input_field.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,3 @@
margin-top: 5px;
}


.chosen-container {
padding: 0;
border-radius: 5px;
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
- s.template do
%a{href: "LINK", class: "search-content", 'data-turbo-frame': '_self'}
%p.search-element.home-searched-ontology
= t('components.name_identifiers')
NAME(ACRONYM)
%p.home-result-type
= t('components.type')
TYPE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
- s.template do
%a{href: "LINK", class: "search-content", 'data-turbo-frame': '_top'}
%p.search-element.home-searched-ontology
= t('components.name_acronym')
NAME(ACRONYM)
%p.home-result-type
= t('components.type')
TYPE
2 changes: 1 addition & 1 deletion app/components/ontology_subscribe_button_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class OntologySubscribeButtonComponent < ViewComponent::Base
include ApplicationHelper
include InternationalisationHelper
def initialize(id: '', ontology_id:, subscribed:, user_id:, count: 0, link: 'javascript:void(0);')
super
@id = id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export default class extends Controller {
itemLinkBase: String,
idKey: String,
cache: {type: Boolean, default: true},
selectedItem: Number
selectedItem: Number,
searchEndpoint: {type: String, default: '/search'}
}

connect() {
Expand Down Expand Up @@ -91,7 +92,7 @@ export default class extends Controller {
const inputValue = this.#inputValue();
let results_list = []
if (inputValue.length > 0) {
this.buttonTarget.href = `/search?q=${inputValue}`;
this.buttonTarget.href = `${this.searchEndpointValue}?q=${inputValue}`;
this.actionLinks.forEach(action => {
const content = action.querySelector('p')
content.innerHTML = inputValue
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/annotator_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ def annotator_results(uri)
@json_link = json_link(uri, api_params)
@rdf_link = "#{@json_link}&format=rdf"
@results_table_header = [
"Class", "Ontology", "Contexts"
t('annotator.class'), t('annotator.ontology'), t('annotator.context')
]
if params[:fast_context]
@results_table_header += ['Negation', 'Experiencer', 'Temporality', 'Certainty']
@results_table_header += [t('annotator.negation'), t('annotator.experiencer'), t('annotator.temporality'), t('annotator.certainty')]
end
@direct_results = 0
@parents_results = 0
if params[:score].nil? || params[:score].eql?('none')
params[:score] = nil
else
@results_table_header.push('Score')
@results_table_header.push(t('annotator.score'))
end
annotations = LinkedData::Client::HTTP.get(uri, api_params)
@ontologies = get_simplified_ontologies_hash
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ class ApplicationController < ActionController::Base
include InternationalisationHelper

before_action :set_locale


def self.t(*args)
InternationalisationHelper.t(*args)
end

# Sets the locale based on the locale cookie or the value returned by detect_locale.
def set_locale
I18n.locale = cookies[:locale] || detect_locale
Expand Down Expand Up @@ -714,10 +718,6 @@ def request_lang
helpers.request_lang
end

def self.t(*args)
I18n.t(*args)
end

private
def not_found_record(exception)
@error_message = exception.message
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 @@ -166,7 +166,7 @@ def details
ontology_not_found(params[:ontology]) if @ontology.nil?

@concept = @ontology.explore.single_class({full: true}, CGI.unescape(params[:conceptid]))
concept_not_found(CGI.unescape(params[:conceptid])) if @concept.nil?
concept_not_found(CGI.unescape(params[:conceptid])) if @concept.nil? || @concept.errors
@container_id = params[:modal] ? 'application_modal_content' : 'concept_details'

if params[:styled].eql?("true")
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/landscape_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def index
organizations_list = Array(sub.send(org_attr.to_s))

organizations_list.each do |org|
org_str = org.name || org.to_s
org_str = org.name || org.to_s rescue org.to_s
org_uri = nil
# Check if the organization is actually an URL
if org_str =~ /\A#{URI::regexp}\z/
Expand Down
96 changes: 0 additions & 96 deletions app/controllers/precache_controller.rb

This file was deleted.

5 changes: 3 additions & 2 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ def destroy
def project_params
p = params.require(:project).permit(:name, :acronym, :institution, :contacts, { creator:[] }, :homePage,
:description, { ontologyUsed:[] })
p[:creator].reject!(&:blank?)
p[:ontologyUsed].reject!(&:blank?)

p[:creator]&.reject!(&:blank?)
p[:ontologyUsed]&.reject!(&:blank?)
p.to_h
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/recommender_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class RecommenderController < ApplicationController
layout :determine_layout
include ApplicationHelper
include InternationalisationHelper

# REST_URI is defined in application_controller.rb
RECOMMENDER_URI = "/recommender"

Expand Down
5 changes: 2 additions & 3 deletions app/helpers/admin/licenses_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ module Admin::LicensesHelper

def license_notification(license)
days = license.days_remaining

if (days == 0)
msg = (t(".license_expired") << " " << t(".license_contact")).html_safe
msg = (t("admin.licenses.license_notification.license_expired") << " " << t("admin.licenses.license_notification.license_contact")).html_safe
notification = tag.div msg, class: "alert alert-danger mt-3", role: "alert"
elsif license.is_trial?
msg = (t(".license_trial", count: days) << " " << t(".license_obtain") << " " << t(".license_contact")).html_safe
msg = (t("admin.licenses.license_notification.license_trial", count: days) << " " << t("admin.licenses.license_notification.license_obtain") << " " << t("admin.licenses.license_notification.license_contact")).html_safe
notification = tag.div msg, class: "alert alert-info mt-3", role: "alert"
end

Expand Down
7 changes: 2 additions & 5 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def attribute_enforced_values(attr)
def prefix_properties(concept_properties)
modified_properties = {}

concept_properties.each do |key, value|
concept_properties&.each do |key, value|
if value.is_a?(Hash) && value.key?(:key)
key_string = value[:key].to_s
next if key_string.include?('metadata')
Expand Down Expand Up @@ -582,7 +582,7 @@ def hide_advanced_options_button(text: nil, init: nil)

def insert_sample_text_button(text)
content_tag(:div, class:'insert-sample-text-button') do
content_tag(:div, class: 'button', 'data-action': 'click->sample-text#annotator_recommender', 'data-sample-text': t("sample_text")) do
content_tag(:div, class: 'button', 'data-action': 'click->sample-text#annotator_recommender', 'data-sample-text': t("annotator.sample_text")) do
content_tag(:div, text, class: 'text') +
inline_svg_tag('icons/arrow-curved-up.svg')
end
Expand All @@ -596,9 +596,6 @@ def empty_state(text)
end
end

def list_to_string(list)
list&.join(',') || ''
end

def ontologies_selector(id:, label: nil, name: nil, selected: nil)
content_tag(:div) do
Expand Down
5 changes: 4 additions & 1 deletion app/helpers/inputs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ def text_input(name:, value:nil, label: nil, disabled: false, help: nil, error_m
data: data)
end

def select_input(name:, values:, id: nil, label: nil, selected: nil, multiple: false, help: nil, open_to_add: false, required: false, data: {})
def select_input(name:, values:, id: nil, label: nil, selected: nil, multiple: false, help: nil, open_to_add: false, required: false,
placeholder: nil,
data: {})
render Input::SelectComponent.new(label: input_label(label, name), id: id || name, name: name, value: values,
selected: selected,
multiple: multiple,
helper_text: help,
open_to_add_values: open_to_add,
required: required,
placeholder: placeholder,
data: data)
end

Expand Down
34 changes: 23 additions & 11 deletions app/helpers/internationalisation_helper.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
module InternationalisationHelper

#Implement logic to make the term 'ontology' configurable throughout the portal, allowing it to be replaced with the variable $RESOURCE_TERM
def t(*args)
translation = I18n.t(*args).downcase
# Implement logic to make the term 'ontology' configurable throughout the portal,
# allowing it to be replaced with the variable $RESOURCE_TERM
def self.t(*args)
return I18n.t(*args) unless $RESOURCE_TERM

begin
original_translation = I18n.t(*args)
downcase_translation = original_translation.downcase
rescue StandardError => e
return e.message
end

term = I18n.t("resource_term.ontology")
plural_term = I18n.t("resource_term.ontology_plural")
single_term = I18n.t("resource_term.ontology_single")
resource = I18n.t("resource_term.#{$RESOURCE_TERM}")
resources = I18n.t("resource_term.#{$RESOURCE_TERM}_plural")
a_resource = I18n.t("resource_term.#{$RESOURCE_TERM}_single")

if translation.include?(term) && resource
if downcase_translation.include?(term) && resource
replacement = resource.capitalize
replacement = resource if translation.include?(term)
if translation.include?(single_term)
replacement = resource if downcase_translation.include?(term)
if downcase_translation.include?(single_term)
term = single_term
replacement = a_resource
end
translation.gsub(term, replacement)

elsif translation.include?(plural_term) && resources
original_translation.gsub(term, replacement)
elsif downcase_translation.include?(plural_term) && resources
replacement = resources.capitalize
replacement = resources if translation.include?(plural_term)
translation.gsub(plural_term, replacement)
replacement = resources if downcase_translation.include?(plural_term)
original_translation.gsub(plural_term, replacement)
else
I18n.t(*args)
end
end

def t(*args)
InternationalisationHelper.t(*args)
end

end
2 changes: 2 additions & 0 deletions app/helpers/ontologies_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def private_ontology_icon(is_private)
end
def browse_filter_section_label(key)
labels = {
categories: t('ontologies.categories'),
groups: t('ontologies.groups'),
hasFormalityLevel: t('ontologies.formality_levels'),
isOfType: t('ontologies.ontology_types'),
naturalLanguage: t('ontologies.natural_languages')
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/submission_inputs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def contact_input(label: '', name: t('submission_inputs.contact'), show_help: tr

render NestedFormInputsComponent.new(object_name: 'contact', default_empty_row: true) do |c|
c.header do
content_tag(:div, label: t('submission_inputs.contact_name', name: name), class: 'w-50') + content_tag(:div, t('submission_inputs.contact_email', name: name), class: 'w-50')
content_tag(:div, name.blank? ? '' : t('submission_inputs.contact_name', name: name), class: 'w-50') + content_tag(:div, name.blank? ? '' : t('submission_inputs.contact_email', name: name), class: 'w-50')
end

c.template do
Expand Down
Loading
Loading