Skip to content

Commit

Permalink
Feature/728 language clean up (#743)
Browse files Browse the repository at this point in the history
* create language selector dropdown

* translate languages

* change position of selector

* add translations check

* add attr translation for object

* update translations for people profile and add cancel form button

* add translations for people_skills and language select

* fix human_attribute_name method

* use instance for translations

* add translation for sv_export

* Update translate and action_link helper

* update translations

* add more action_link helper

* update translations till _cv.html

* Fix translations for people

* update translations for people_skills

* translate all person_relations

* update translations for admin panel

* update skills translations

* add custom rubocop

* finish translations

* update translations

* add missing translations for everything

* start adding custom scanner

* update i18n-tasks config

* normalize translation files

* add missing tranlatins

* Fix failing tests

* fix complex tests

* try to fix people skills

* add translations and fix tests

* add french tranlatiions

* fix search

* fix tests

* make rubocop happy

* fix language selector and belive

* language gets persistend after changing person

* fix i18n tests

* fix all failing tests

* improve person routing behavior

* improve translations

* fix i18n-tasks

* fix topbar

* add translations via url path

* Fix bug related to the new way to set locale

* update locale files

* fix rspec locale bug

* fix failing tests

* normalize locale files

* clean up

* normalize locale files

* Make rubocop happy

* Implement feedback

* fix translation of adminpanel and fix export icon

* use tabbar partial for main navbar and improve tabbar

* works

* fix translations of cv search

* clean up language files

* update translations

* simplify routing logic

* simplify i18n helper logic

* regenerate language files

* clean up translations

* start fixing cv search

* fix translations

* translate people skills search

* fix people_skills search

* reimplement placeholder in skills_search

* fix translations

* fix all tests

* normalize files

* add routing and tabbar specs

* readd instant login for keycloak

* Fix controller specs

* use options_for_select in people_search

* clean up people search

* add tests to check lanugage selection

* fix routing and tabbar specs

* add translation for tabbar

* add more model translations

* change name of cancel.svg and use correct language to display language

* Return languages capitalized for language dropdown

---------

Co-authored-by: Robin Steiner <[email protected]>
  • Loading branch information
kcinay055679 and Robin481 authored Aug 8, 2024
1 parent c67153c commit d3a7f14
Show file tree
Hide file tree
Showing 124 changed files with 2,261 additions and 806 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require:
- rubocop-rspec
- rubocop-capybara
- rubocop-rspec_rails
- ./lib/custom_cops/translated_haml_files

AllCops:
NewCops: enable
Expand Down Expand Up @@ -177,3 +178,6 @@ Style/FrozenStringLiteralComment:

Style/Attr:
Enabled: false

CustomCops/TranslatedHamlFiles:
Enabled: true
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ group :development, :test do
# Call 'byebug' anywhere in the code
# to stop execution and get a debugger console
gem 'byebug', platform: :mri
gem 'i18n-tasks', '~> 1.0.14'
gem 'pry'
gem 'pry-byebug'
gem 'rspec-rails'
Expand Down
14 changes: 14 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,22 @@ GEM
rubocop (>= 1.0)
sysexits (~> 1.1)
hashie (5.0.0)
highline (3.0.1)
http-accept (1.7.0)
http-cookie (1.0.5)
domain_name (~> 0.5)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
i18n-tasks (1.0.14)
activesupport (>= 4.0.2)
ast (>= 2.1.0)
erubi
highline (>= 2.0.0)
i18n
parser (>= 3.2.2.1)
rails-i18n
rainbow (>= 2.2.2, < 4.0)
terminal-table (>= 1.5.1)
i18n_data (0.17.1)
simple_po_parser (~> 1.1)
image_processing (1.12.2)
Expand Down Expand Up @@ -428,6 +439,8 @@ GEM
strscan (3.1.0)
sysexits (1.2.0)
temple (0.10.3)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
thor (1.3.1)
tilt (2.3.0)
timeout (0.4.1)
Expand Down Expand Up @@ -475,6 +488,7 @@ DEPENDENCIES
faker
haml-rails
haml_lint
i18n-tasks (~> 1.0.14)
i18n_data
jsbundling-rails
language_list
Expand Down
File renamed without changes
3 changes: 3 additions & 0 deletions app/assets/stylesheets/crud.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ footer {
height: 16px;
display: inline-block;
background: no-repeat;
background-position: center;
vertical-align: top;
}

Expand All @@ -56,3 +57,5 @@ footer {
.icon-pencil { background-image: url('assets/pencil-square.svg'); }
.icon-list { background-image: url('assets/list.png'); }
.icon-zoom-in { background-image: url('assets/search.svg'); }
.icon-export { background-image: url('assets/export.svg'); }
.icon-close { background-image: url('assets/cancel.svg'); }
10 changes: 10 additions & 0 deletions app/assets/stylesheets/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ $skills-dark-blue: #1e5a96;
cursor: pointer;
}

.skills-navbar{
.nav-link {
color: white;
@extend .px-2;
&.active {
background-color: $skills-dark-blue;
}
}
}

.navbar {
flex-direction: row;
list-style-type: none;
Expand Down
16 changes: 11 additions & 5 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

class ApplicationController < ActionController::Base
before_action :authenticate_auth_user!
before_action :set_first_path!
around_action :switch_locale

default_form_builder SkillsFormBuilder

def switch_locale(&)
locale = params[:locale] || I18n.default_locale
I18n.with_locale(locale, &)
end

def authenticate_auth_user!
return super if helpers.devise?
Expand All @@ -14,10 +20,6 @@ def authenticate_auth_user!
request.env['warden'].set_user(admin, :scope => :auth_user)
end

def set_first_path!
@first_path = Pathname(request.path).each_filename.to_a.map { |e| "/#{e}" }.first
end

def render_unauthorized_not_admin
render_unauthorized(helpers.admin?)
end
Expand All @@ -39,4 +41,8 @@ def render_error(title_key, body_key, status = :bad_request)
body: translate("devise.failure.#{body_key}") },
:status => status
end

def default_url_options
{ locale: I18n.locale }
end
end
5 changes: 2 additions & 3 deletions app/controllers/people_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ class PeopleController < CrudController
self.permitted_attrs = [:birthdate, :location, :marital_status, :updated_by, :name, :nationality,
:nationality2, :title, :competence_notes, :company_id, :email,
:department_id, :shortname, :picture, :picture_cache,
{ person_roles_attributes: [:role_id, :person_role_level_id,
:percent, :id, :_destroy] },
{ person_roles_attributes:
[:role_id, :person_role_level_id, :percent, :id, :_destroy] },
{ language_skills_attributes:
[:language, :level, :certificate, :id, :_destroy] }]
layout 'person', only: [:show]

def index
return flash[:alert] = I18n.t('errors.profile-not-found') if params[:alert].present?
return flash[:alert] = I18n.t('errors.messages.profile-not-found') if params[:alert].present?

super
end
Expand Down Expand Up @@ -60,6 +58,7 @@ def export
disposition: content_disposition('attachment', filename)
end


private

def fetch_entries
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/people_skills/filter_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def interest_of_row(row_id)
end

def skill_of_row(row_id)
skill_ids.nil? ? nil : skill_ids[row_id].to_i
skill_ids[row_id]&.to_i
end

def query_params
Expand Down
3 changes: 2 additions & 1 deletion app/domain/people_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def search_result

people.map do |p|
found_in(p).each do |result|
results.push({ person: { id: p.id, name: p.name }, found_in: result })
translated_attr = Person.human_attribute_name(result, count: 2)
results.push({ person: { id: p.id, name: p.name }, found_in: translated_attr })
end
end
results
Expand Down
2 changes: 1 addition & 1 deletion app/exporters/odt/cv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def insert_core_competences(report)
# rubocop:enable Metrics/MethodLength

def skills_by_level(level_value)
person.people_skills.where('level >= ?', level_value)
person.people_skills.where(level: level_value..)
end

def competence_notes_list
Expand Down
22 changes: 20 additions & 2 deletions app/helpers/actions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,28 @@ def index_action_link(path = nil, url_options = { returning: true })

# Standard add action to given path.
# Uses the current +model_class+ if no path is given.
def add_action_link(path = nil, url_options = {})
def add_action_link(path = nil, url_options = {}, html_options = {})
path ||= path_args(model_class)
path = new_polymorphic_path(path, url_options) unless path.is_a?(String)
action_link(ti('link.add'), 'plus', path)
action_link(ti('link.add'), 'plus', path, html_options)
end

def add_action_link_modal(path = nil, url_options = {})
path ||= path_args(model_class)
path = new_polymorphic_path(path, url_options) unless path.is_a?(String)
options = { data: { turbo_frame: 'remote_modal' } }
action_link(ti('link.add'), 'plus', path, options)
end

def export_action_link(path, options = {})
action_link(ti('link.export'), 'export', path, options)
end

def close_action_link(path, options = {})
action_link('', 'close', path, options)
end

def cancel_action_link(path, options = {})
action_link(ti('link.cancel'), '', path, options)
end
end
9 changes: 9 additions & 0 deletions app/helpers/auth_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

module AuthHelper

def session_path(_scope)
new_auth_user_session_path
end
Expand All @@ -21,4 +22,12 @@ def find_person_by_auth_user
def devise?
AuthConfig.keycloak? || Rails.env.test?
end

def language_selector
languages = I18n.available_locales.map { |e| e.to_s }.map do |lang_code|
language = I18nData.languages(lang_code)[lang_code.upcase]
[language.capitalize, url_for(locale: lang_code)]
end
options_for_select(languages, url_for(locale: I18n.locale))
end
end
5 changes: 1 addition & 4 deletions app/helpers/cv_search_helper.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# frozen_string_literal: true

module CvSearchHelper
def translate_found_in(result)
I18n.t("cv_search.#{result[:found_in].underscore}")
end

def found_in_skills?(result)
result[:found_in].include?('skills')
result[:found_in].include?('Skills')
end
end
2 changes: 1 addition & 1 deletion app/helpers/date_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def months

def date_range_end_label(model_with_dates)
if model_with_dates&.till_today?
return "- #{t('date_range_picker.today')}"
return "- #{ti('date.today')}"
elsif !(model_with_dates.same_year? && model_with_dates.same_month?)
return "- #{months[model_with_dates&.month_to || 0]} #{model_with_dates&.year_to}"
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/dry_crud/form/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def has_many_field(attr, html_options = {})

# Render the error messages for the current form.
def error_messages
@template.render('shared/error_messages',
@template.render('application/error_banners',
errors: @object.errors,
object: @object)
end
Expand Down
5 changes: 3 additions & 2 deletions app/helpers/i18n_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ module I18nHelper
# - {parent_controller}.global.{key}
# - ...
# - global.{key}
def translate_inheritable(key, variables = {})
def translate_inheritable(key, variables = {}) # rubocop:disable Metrics/CyclomaticComplexity
partial = defined?(@virtual_path) ? @virtual_path.gsub(/.*\/_?/, '') : nil
defaults = inheritable_translation_defaults(key, partial)
variables[:default] ||= defaults
t(defaults.shift, **variables)
variables[:model] ||= model_class&.model_name&.human if respond_to?(:model_class)
t(defaults.shift, **variables).upcase_first
end

alias ti translate_inheritable
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/person_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,12 @@ def not_rated_default_skills(person)
certificate: false, core_competence: false })
end
end

def sorted_people
people_for_select.sort_by { |e| e.first.downcase }
end

def people_for_select
Person.all.map { |p| [p.name, person_path(p)] }
end
end
10 changes: 7 additions & 3 deletions app/helpers/select_helper.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

module SelectHelper
def select_when_availabale(obj)
selected = obj ? obj.id : ''
prompt = obj ? false : true
def select_when_available(obj)
selected = obj || ''
prompt = selected.blank?
{ selected: selected, prompt: prompt, disabled: '' }
end

Expand All @@ -15,4 +15,8 @@ def skills_dropdown_options
skills = Skill.list.map { |s| [s.title, s.id, { 'data-category-id': s.category.id }] }
add_default_option(skills, { 'data-placeholder': true })
end

def model_path_or_nil(model)
polymorphic_path(model) if model
end
end
29 changes: 27 additions & 2 deletions app/helpers/tab_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
# frozen_string_literal: true

module TabHelper
LOCALE_REGEX = /(\/(?:#{I18n.available_locales.join('|')}))/
GLOBAL_NAVBAR_REGEX = /^#{LOCALE_REGEX}?(\/[^\/]+)(?:\/|$)/
PERSON_NAVBAR_REGEX = /^(.*)/

def person_tabs(person)
[
{ title: 'CV', path: person_path(person) },
{ title: 'Skills', path: person_people_skills_path(person) }
{ title: ti('tabbar.cv'), path: person_path(person) },
{ title: ti('tabbar.skills'), path: person_people_skills_path(person) }
]
end

def global_tabs
[
{ title: ti('navbar.profile'), path: people_path },
{ title: ti('navbar.skill_search'), path: people_skills_path },
{ title: ti('navbar.cv_search'), path: cv_search_index_path },
{ title: ti('navbar.skillset'), path: skills_path }
]
end

def extract_path(regex)
request.path.match(regex)&.captures&.join
end

def global_navbar_path
extract_path(GLOBAL_NAVBAR_REGEX)
end

def person_navbar_path
extract_path(PERSON_NAVBAR_REGEX)
end
end
5 changes: 4 additions & 1 deletion app/javascript/controllers/dropdown_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import SlimSelect from 'slim-select';
export default class extends Controller {
static targets = [ "dropdown" ]
connect() {
if (!this.hasDropdownTarget)
return;

new SlimSelect({
select: this.dropdownTarget
});
}

handleChange(event) {
window.location.href = event.target.dataset.value + event.target.value;
window.location.href = event.target.value;
}
}
3 changes: 0 additions & 3 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ application.register("people-skills", PeopleSkillsController)
import PeopleSkillsFilterController from "./people_skills_filter_controller"
application.register("people-skills-filter", PeopleSkillsFilterController)

import ProfileTabController from "./profile_tab_controller"
application.register("profile-tab", ProfileTabController)

import RemoteModalController from "./remote_modal_controller"
application.register("remote-modal", RemoteModalController)

Expand Down
Loading

0 comments on commit d3a7f14

Please sign in to comment.