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/728 language clean up #743

Merged
merged 82 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
e6bf306
create language selector dropdown
kcinay055679 Jun 28, 2024
b056696
translate languages
kcinay055679 Jun 28, 2024
d147337
change position of selector
kcinay055679 Jul 5, 2024
2c6604f
add translations check
kcinay055679 Jun 28, 2024
60063f9
add attr translation for object
kcinay055679 Jun 28, 2024
8753378
update translations for people profile and add cancel form button
kcinay055679 Jul 1, 2024
f2a65a5
add translations for people_skills and language select
kcinay055679 Jul 1, 2024
54a6eb8
fix human_attribute_name method
kcinay055679 Jul 1, 2024
20b7bf7
use instance for translations
kcinay055679 Jul 1, 2024
a81b123
add translation for sv_export
kcinay055679 Jul 2, 2024
9ef2fc1
Update translate and action_link helper
kcinay055679 Jul 2, 2024
84f718b
update translations
kcinay055679 Jul 2, 2024
d75b7ba
add more action_link helper
kcinay055679 Jul 2, 2024
58be547
update translations till _cv.html
kcinay055679 Jul 2, 2024
23093cc
Fix translations for people
kcinay055679 Jul 3, 2024
6368754
update translations for people_skills
kcinay055679 Jul 3, 2024
4db88aa
translate all person_relations
kcinay055679 Jul 3, 2024
22cf647
update translations for admin panel
kcinay055679 Jul 3, 2024
4b59f8f
update skills translations
kcinay055679 Jul 3, 2024
6b88556
add custom rubocop
kcinay055679 Jul 3, 2024
0690be6
finish translations
kcinay055679 Jul 4, 2024
0a757ae
update translations
kcinay055679 Jul 4, 2024
a7f98d0
add missing translations for everything
kcinay055679 Jul 4, 2024
5dd9a5d
start adding custom scanner
kcinay055679 Jul 4, 2024
d2153ae
update i18n-tasks config
kcinay055679 Jul 5, 2024
2e8d948
normalize translation files
kcinay055679 Jul 5, 2024
fad7a08
add missing tranlatins
kcinay055679 Jul 5, 2024
49263af
Fix failing tests
kcinay055679 Jul 5, 2024
12cf4b9
fix complex tests
kcinay055679 Jul 5, 2024
ab0e5f0
try to fix people skills
kcinay055679 Jul 5, 2024
3b4a54f
add translations and fix tests
kcinay055679 Jul 5, 2024
6d67a6b
add french tranlatiions
kcinay055679 Jul 5, 2024
9a04246
fix search
kcinay055679 Jul 5, 2024
221fa91
fix tests
kcinay055679 Jul 5, 2024
1ce4428
make rubocop happy
kcinay055679 Jul 5, 2024
b4f28ce
fix language selector and belive
kcinay055679 Jul 22, 2024
022e603
language gets persistend after changing person
kcinay055679 Jul 22, 2024
5914c10
fix i18n tests
kcinay055679 Jul 22, 2024
da8ebaa
fix all failing tests
kcinay055679 Jul 23, 2024
88639f1
improve person routing behavior
kcinay055679 Jul 23, 2024
d0dc183
improve translations
kcinay055679 Jul 23, 2024
34f31d2
fix i18n-tasks
kcinay055679 Jul 23, 2024
a4ba89b
fix topbar
kcinay055679 Jul 23, 2024
35af3e9
add translations via url path
kcinay055679 Jul 23, 2024
09bd044
Fix bug related to the new way to set locale
kcinay055679 Jul 23, 2024
80de1dd
update locale files
kcinay055679 Jul 23, 2024
c4058d8
fix rspec locale bug
kcinay055679 Jul 24, 2024
4c7a88f
fix failing tests
kcinay055679 Jul 24, 2024
a1360b4
normalize locale files
kcinay055679 Jul 24, 2024
4a0df68
clean up
kcinay055679 Jul 24, 2024
3d5341b
normalize locale files
kcinay055679 Jul 24, 2024
87e0789
Make rubocop happy
kcinay055679 Jul 24, 2024
39ee336
Implement feedback
kcinay055679 Jul 26, 2024
9d38a60
fix translation of adminpanel and fix export icon
kcinay055679 Jul 26, 2024
6ea0c70
use tabbar partial for main navbar and improve tabbar
kcinay055679 Jul 26, 2024
a237dd2
works
kcinay055679 Jul 29, 2024
034c082
fix translations of cv search
kcinay055679 Jul 30, 2024
4fb532a
clean up language files
kcinay055679 Jul 30, 2024
dbea8e1
update translations
kcinay055679 Jul 30, 2024
9631e90
simplify routing logic
kcinay055679 Jul 30, 2024
69689bf
simplify i18n helper logic
kcinay055679 Jul 30, 2024
1e330de
regenerate language files
kcinay055679 Jul 30, 2024
e5b38fe
clean up translations
kcinay055679 Jul 30, 2024
a9ae51a
start fixing cv search
kcinay055679 Jul 30, 2024
0bd050e
fix translations
kcinay055679 Jul 31, 2024
bf98516
translate people skills search
kcinay055679 Jul 31, 2024
d966b46
fix people_skills search
kcinay055679 Jul 31, 2024
b8e9a1e
reimplement placeholder in skills_search
kcinay055679 Jul 31, 2024
5eb5571
fix translations
kcinay055679 Jul 31, 2024
66fb4c8
fix all tests
kcinay055679 Jul 31, 2024
d74b5aa
normalize files
kcinay055679 Jul 31, 2024
6bec7da
add routing and tabbar specs
kcinay055679 Jul 31, 2024
ff01a4f
readd instant login for keycloak
kcinay055679 Aug 2, 2024
cbdc90f
Fix controller specs
kcinay055679 Aug 2, 2024
e146a7f
use options_for_select in people_search
kcinay055679 Aug 2, 2024
7df7e6e
clean up people search
kcinay055679 Aug 2, 2024
b518243
add tests to check lanugage selection
kcinay055679 Aug 2, 2024
ecbd15a
fix routing and tabbar specs
kcinay055679 Aug 2, 2024
4fb83b5
add translation for tabbar
kcinay055679 Aug 2, 2024
40d0431
add more model translations
kcinay055679 Aug 2, 2024
8ac2e1e
change name of cancel.svg and use correct language to display language
kcinay055679 Aug 6, 2024
6c0d37f
Return languages capitalized for language dropdown
Robin481 Aug 8, 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
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.4)
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
Robin481 marked this conversation as resolved.
Show resolved Hide resolved
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')}"
kcinay055679 marked this conversation as resolved.
Show resolved Hide resolved
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