From a88898cc050d2ae3a4d062bb2c264c08e5a3d5c7 Mon Sep 17 00:00:00 2001 From: SirineMhedhbi <31127782+SirineMhedhbi@users.noreply.github.com> Date: Wed, 28 Feb 2024 01:19:55 +0100 Subject: [PATCH] Feature : internationalization part 21 - Controllers: language, login, mappings, notes and ncbo annotator plus + MultiLanguages helper (#501) * internationalization of mappings controller * internationalization of notes controller * internationalization of login controller * internationalization of language controller * internationalization of ncbo annotator plus controller * update of en.yml file * internationalization of MultiLanguages helper * skip annotator page weird test * put back annotator page test * include translation helper in notes controller * create a class function for controllers translating * remove binding.pry in notes_controller.rb --------- Co-authored-by: Bilel KIHAL Co-authored-by: Syphax bouazzouni --- app/controllers/application_controller.rb | 7 ++++- app/controllers/language_controller.rb | 2 +- app/controllers/login_controller.rb | 20 ++++++------- app/controllers/mappings_controller.rb | 22 +++++++------- app/controllers/notes_controller.rb | 13 ++++---- app/helpers/multi_languages_helper.rb | 8 ++--- config/locales/en.yml | 36 ++++++++++++++++++++++- 7 files changed, 74 insertions(+), 34 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ef4d7049b..9b3191173 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -15,7 +15,7 @@ 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 I18n.locale = cookies[:locale] || detect_locale @@ -712,6 +712,11 @@ def submission_metadata 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 diff --git a/app/controllers/language_controller.rb b/app/controllers/language_controller.rb index ed1ec7c79..0ccf6b59c 100644 --- a/app/controllers/language_controller.rb +++ b/app/controllers/language_controller.rb @@ -10,7 +10,7 @@ def set_locale_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" + flash.now[:notice] = t('language.translation_not_available', language: language) logger.error flash.now[:notice] end end diff --git a/app/controllers/login_controller.rb b/app/controllers/login_controller.rb index 2aa4af6e6..81feb68a9 100755 --- a/app/controllers/login_controller.rb +++ b/app/controllers/login_controller.rb @@ -34,7 +34,7 @@ def create redirect_to redirect, allow_other_host: true else - @errors << "Invalid account name/password combination" + @errors << t('login.invalid_account_combination') render :action => 'index' end else @@ -59,7 +59,7 @@ def create_omniauth redirect_to redirect else - @errors = ["#{params[:provider]} authentication failed"] + @errors = [t('login.authentication_failed', provider: params[:provider])] render :action => 'index' end end @@ -90,10 +90,10 @@ def destroy old_user = session[:user] session[:user] = session[:admin_user] session.delete(:admin_user) - flash[:success] = "Logged out #{old_user.username}, returned to #{session[:user].username}".html_safe + flash[:success] = t('login.admin_logged_out', old_user: old_user.username, user: session[:user].username).html_safe else session[:user] = nil - flash[:success] = "You have successfully logged out" + flash[:success] = t('login.user_logged_out') end redirect_to request.referer || "/" end @@ -114,7 +114,7 @@ def send_pass if resp.nil? redirect_to "/lost_pass_success" else - flash[:notice] = resp.errors.first + ". Please try again." + flash[:notice] = resp.errors.first + t('login.try_again_notice') redirect_to "/lost_pass" end end @@ -129,7 +129,7 @@ def reset_password login(@user) render "users/edit" else - flash[:notice] = @user.errors.first + ". Please reset your password again." + flash[:notice] = @user.errors.first + t('login.reset_password_again') redirect_to "/lost_pass" end end @@ -139,8 +139,8 @@ def reset_password def login(user) return unless user session[:user] = user - custom_ontologies_text = session[:user].customOntology && !session[:user].customOntology.empty? ? "The display is now based on your Custom Ontology Set." : "" - notice = "Welcome " + user.username.to_s + "! " + custom_ontologies_text + custom_ontologies_text = session[:user].customOntology && !session[:user].customOntology.empty? ? t('login.custom_ontology_set') : "" + notice = t('login.welcome') + user.username.to_s + "! " + custom_ontologies_text flash[:success] = notice.html_safe end @@ -148,10 +148,10 @@ def validate(params) errors=[] if params[:username].nil? || params[:username].length <1 - errors << "Please enter an account name" + errors << t('login.error_account_name') end if params[:password].nil? || params[:password].length <1 - errors << "Please enter a password" + errors << t('login.error_password') end return errors diff --git a/app/controllers/mappings_controller.rb b/app/controllers/mappings_controller.rb index 269fafebe..89fc84212 100644 --- a/app/controllers/mappings_controller.rb +++ b/app/controllers/mappings_controller.rb @@ -32,11 +32,11 @@ def index # Adding external and interportal mappings to the dropdown list if ontology_acronym.to_s == EXTERNAL_MAPPINGS_GRAPH mapping_count = ontologies_mapping_count[ontology_acronym.to_s] || 0 - select_text = "External Mappings (#{number_with_delimiter(mapping_count, delimiter: ',')})" if mapping_count >= 0 + select_text = t('mappings.external_mappings', number_with_delimiter: number_with_delimiter(mapping_count, delimiter: ',')) if mapping_count >= 0 ontology_acronym = EXTERNAL_URL_PARAM_STR elsif ontology_acronym.to_s.start_with?(INTERPORTAL_MAPPINGS_GRAPH) mapping_count = ontologies_mapping_count[ontology_acronym.to_s] || 0 - select_text = "Interportal Mappings - #{ontology_acronym.to_s.split("/")[-1].upcase} (#{number_with_delimiter(mapping_count, delimiter: ',')})" if mapping_count >= 0 + select_text = t('mappings.interportal_mappings', acronym: ontology_acronym.to_s.split("/")[-1].upcase, number_with_delimiter: number_with_delimiter(mapping_count, delimiter: ',')) if mapping_count >= 0 ontology_acronym = INTERPORTAL_URL_PARAM_STR + ontology_acronym.to_s.split("/")[-1] else ontology = ontologies_hash[ontology_acronym.to_s] @@ -62,7 +62,7 @@ def loader "classes": ["http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Image_Algorithm", "http://purl.org/incf/ontology/Computational_Neurosciences/cno_alpha.owl#cno_0000202"], - "name": 'This is the mappings produced to test the bulk load', + "name": t('mappings.test_bulk_load'), "source": 'https://w3id.org/semapv/LexicalMatching', "comment": 'mock data', "relation": [ @@ -111,7 +111,7 @@ def show_mappings if @ontology.nil? ontology_acronym = params[:id] if params[:id] == EXTERNAL_URL_PARAM_STR - @ontology_name = "External Mappings" + @ontology_name = t('mappings.external_mappings') elsif params[:id].start_with?(INTERPORTAL_URL_PARAM_STR) @ontology_name = params[:id].sub(":", " - ") end @@ -122,10 +122,10 @@ def show_mappings if @target_ontology.nil? if params[:target] == EXTERNAL_MAPPINGS_GRAPH target_acronym = EXTERNAL_URL_PARAM_STR - @target_ontology_name = "External Mappings" + @target_ontology_name = t('mappings.external_mappings') elsif params[:target].start_with?(INTERPORTAL_MAPPINGS_GRAPH) target_acronym = "#{INTERPORTAL_URL_PARAM_STR}:#{params[:target].split("/")[-1]}" - @target_ontology_name = "Interportal - #{params[:target].split("/")[-1].upcase}" + @target_ontology_name = t('mappings.interportal_mappings', params: params[:target].split("/")[-1].upcase) end else target_acronym = @target_ontology.acronym @@ -196,7 +196,7 @@ def create @delete_mapping_permission = check_delete_mapping_permission(@mapping_saved) mapping = LinkedData::Client::Models::Mapping.find(@mapping_saved.id) render turbo_stream: [ - alert(type: 'success') { 'Mapping created' }, + alert(type: 'success') {t('mappings.mapping_created')}, prepend('concept_mappings_table_content', partial: 'show_line', locals: { map: mapping, concept: @concept }) ] end @@ -220,7 +220,7 @@ def update render_turbo_stream(alert_error { JSON.pretty_generate errors }) else render_turbo_stream( - alert_success { 'Mapping updated' }, + alert_success { t('mappings.mapping_updated') }, replace(@mapping.id.split('/').last, partial: 'show_line', locals: { map: request_mapping, concept: @concept }) ) end @@ -236,7 +236,7 @@ def destroy map_uri = "#{MAPPINGS_URL}/#{CGI.escape(map_id)}" result = LinkedData::Client::HTTP.delete(map_uri) if result.status == 204 - success_text = "#{map_id} deleted successfully" + success_text = t('mappings.mapping_deleted', map_id: map_id) else error = result.body end @@ -336,14 +336,14 @@ def mapping_form_values def request_mapping mapping = LinkedData::Client::Models::Mapping.find(params[:id]) - not_found("Mapping #{params[:id]} not found") if mapping.nil? || mapping.errors + not_found( t('mappings.mapping_not_found', id: params[:id]) ) if mapping.nil? || mapping.errors mapping end def valid_values?(values) errors = [] if values[:classes].reject(&:blank?).size != 2 - errors << 'Source and target concepts need to be specified' + errors << t('mappings.error_of_source_and_target') end errors end diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index b47208ac2..08b24d53d 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -1,10 +1,11 @@ class NotesController < ApplicationController include TurboHelper layout 'ontology' + NOTES_PROPOSAL_TYPES = { - ProposalNewClass: "New Class Proposal", - ProposalChangeHierarchy: "New Relationship Proposal", - ProposalChangeProperty: "Change Property Value Proposal" + ProposalNewClass: t('notes.new_class_proposal'), + ProposalChangeHierarchy: t('notes.new_relationship_proposal'), + ProposalChangeProperty: t('notes.change_property_value_proposal') } def show @@ -100,7 +101,7 @@ def create new_note = note.save parent_type = params[:type].eql?("ontology") ? 'ontology' : 'class' ontology_acronym = new_note.relatedOntology.first.split('/').last - success_message = 'New comment added successfully' + success_message = t('notes.new_comment_added') locals = { note: new_note, ontology_acronym: ontology_acronym, parent_type: parent_type } partial = 'notes/note_line' container_id = "#{parent_type}_notes_table_body" @@ -128,10 +129,10 @@ def destroy if note.errors response[:errors] = note.errors else - response[:success] = "Note #{note_id} was deleted successfully" + response[:success] = t('notes.note_deleted_successfully', note_id: note_id) end else - response[:errors] = "Note #{note_id} was not found in the system" + response[:errors] = t('notes.note_not_found', note_id: note_id) end parent_type = params[:parent_type] alerts_container_id = "notes_#{parent_type}_list_table_alerts" diff --git a/app/helpers/multi_languages_helper.rb b/app/helpers/multi_languages_helper.rb index 81d605818..304f6190d 100644 --- a/app/helpers/multi_languages_helper.rb +++ b/app/helpers/multi_languages_helper.rb @@ -9,7 +9,7 @@ def request_lang end def portal_language_help_text - "Indicate the language in which the interfaces should appear" + t('language.portal_language_help_text') end def portal_languages { @@ -49,7 +49,7 @@ def portal_language_selector def search_language_help_text content_tag(:div, style: 'width: 300px; text-align: center') do - "Indicate the language on which to perform the search, restricting text matching exclusively to terms with that language" + t('language.search_language_help_text') end end def search_languages @@ -80,9 +80,9 @@ def content_languages(submission = @submission || @submission_latest) end def content_language_help_text content_tag(:div, style: 'width: 350px;') do - concat content_tag(:div, "Indicate the language on which the content of this resource will be displayed.") + concat content_tag(:div, t('language.content_language_help_text_1')) concat(content_tag(:div, class: "mt-1" ) do - content_tag(:span, "The available languages are specified by the resource admin.") + edit_sub_languages_button + content_tag(:span, t('language.content_language_help_text_2')) + edit_sub_languages_button end) end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 03dd8324d..a978861f4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -25,6 +25,12 @@ en: acceptance: Acceptance additional_parameters: 'Additional parameters explained at ' + language: + translation_not_available: "%{language} translation not available" + portal_language_help_text: Indicate the language in which the interfaces should appear + search_language_help_text: Indicate the language on which to perform the search, restricting text matching exclusively to terms with that language + content_language_help_text_1: Indicate the language on which the content of this resource will be displayed. + content_language_help_text_2: The available languages are specified by the resource admin. collections: error_valid_collection: "Error: You must provide a valid collection id" concepts: @@ -493,6 +499,16 @@ en: visit_the_site: visit the full site login: + invalid_account_combination: "Invalid account name/password combination" + authentication_failed: "%{provider} authentication failed" + admin_logged_out: Logged out %{old_user}, returned to %{user} + user_logged_out: You have successfully logged out + try_again_notice: ". Please try again." + reset_password_again: ". Please reset your password again." + custom_ontology_set: "The display is now based on your Custom Ontology Set." + welcome: "Welcome " + error_account_name: Please enter an account name + error_password: Please enter a password enter_email: Enter your username enter_password: Enter your password forgot_password: Forgot password? @@ -522,6 +538,16 @@ en: ontology_visits: Ontology visits mappings: + external_mappings: "External Mappings (%{number_with_delimiter})" + interportal_mappings: "Interportal Mappings - %{acronym} (%{number_with_delimiter})" + test_bulk_load: This is the mappings produced to test the bulk load + external_mappings: External Mappings + interportal_mappings: Interportal - %{acronym} (%{number_with_delimiter}) + mapping_created: Mapping created + mapping_updated: Mapping updated + mapping_deleted: "%{map_id} deleted successfully" + mapping_not_found: "Mapping %{id} not found" + error_of_source_and_target: Source and target concepts need to be specified mapping_issue: "Mapping issue with '%{mapping}' : %{message}" find_mappings: Find mappings of a class/concept intro: Find all the mappings of an ontology @@ -967,10 +993,13 @@ en: hide_advanced_options: Hide advanced options no_result_was_found: No result was found notes: - comment: Comment new_class_proposal: New Class Proposal new_relationship_proposal: New Relationship Proposal change_property_value_proposal: Change Property Value Proposal + new_comment_added: New comment added successfully + note_deleted_successfully: Note %{note_id} was deleted successfully + note_not_found: Note %{note_id} was not found in the system + comment: Comment new_comment: subject: Subject comment: Comment @@ -1065,6 +1094,11 @@ en: bioportal_user: BioPortal User ID annotator_plus: + query: "Query: %{query}" + retrieved_annotations: "Retrieved %{annotations} annotations: %{time}s" + completed_massage_for_annotated: "Completed massage for annotated classes: %{time}s" + failed_get_class_details: "Failed to get class details for: %{details}" + not_found_message: Not Found title: Annotator Plus annotator: Annotator + intro: Get annotations for text with ontology classes