diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f79f7ea..2199c95 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,6 +1,18 @@ class ApplicationController < ActionController::Base + before_action :set_locale + private + def set_locale + I18n.locale = params[:locale] || session[:locale] || I18n.default_locale + session[:locale] = I18n.locale + end + + # Optional: Make locale persist across requests via URL helpers + def default_url_options + { locale: I18n.locale } + end + def set_company company_id = session.fetch(:company_id, Company.first&.id) session[:company_id] = company_id diff --git a/app/javascript/controllers/main_calendar_controller.js b/app/javascript/controllers/main_calendar_controller.js index 142cf64..475db88 100644 --- a/app/javascript/controllers/main_calendar_controller.js +++ b/app/javascript/controllers/main_calendar_controller.js @@ -9,6 +9,15 @@ export default class extends Controller { document.getElementById('main-calendar').style.height = '100vh'; document.getElementById('main-calendar').style.width = '100vw'; + // Get current locale from html lang attribute + const currentLocale = document.documentElement.lang || 'bs'; + + // Get translations from data attribute + const translations = JSON.parse(document.getElementById('main-calendar').dataset.translations || '{}'); + + // Translation helper + const t = (key) => translations[key] || key; + const calendar = new tui.Calendar(document.getElementById('main-calendar'), { defaultView: 'week', usageStatistics: false, @@ -27,9 +36,6 @@ export default class extends Controller { displayLabel: 'UTC' // Optional: Label for the timezone } ] - // You might need `primaryTimezone: 'UTC'` here as well, - // depending on the exact library version and desired behavior. - // Let's start with just zones. }, // This is important - set the height to 100% height: '100%', @@ -37,7 +43,7 @@ export default class extends Controller { width: '100%', template: { timegridDisplayPrimaryTime({time}) { - return `${time.getHours()} sati`; + return `${time.getHours()} ${t('hours')}`; }, popupDetailLocation(eventObj) { return ''; // Empty location as requested @@ -50,6 +56,12 @@ export default class extends Controller { }, popupDetailBody(eventObj) { return ''; + }, + popupEdit() { + return t('edit'); + }, + popupDelete() { + return t('delete'); } }, calendars: [ @@ -105,7 +117,7 @@ export default class extends Controller { const csrfToken = this.getCsrfToken(); if (!csrfToken) { console.error("CSRF token not found."); - alert("Error: Could not verify request security token."); + alert(t('delete_error')); return false; } @@ -120,10 +132,10 @@ export default class extends Controller { if (response.ok) { calendar.deleteEvent(reservationId, calendarId); - alert('Reservation deleted.'); + alert(t('delete_success')); } else { console.error(`Failed to delete reservation ${reservationId}. Status: ${response.status}`); - let errorMessage = 'Error deleting reservation.'; + let errorMessage = t('delete_error'); try { const errorData = await response.json(); errorMessage += ` Server says: ${errorData.error || JSON.stringify(errorData)}`; @@ -132,7 +144,7 @@ export default class extends Controller { } } catch (error) { console.error("Network error or exception during delete:", error); - alert("Error deleting reservation due to a network or script issue."); + alert(t('network_error')); } return false; // Prevent TUI default delete handling diff --git a/app/views/companies/_company.html.erb b/app/views/companies/_company.html.erb index c1f327f..fdc81fd 100644 --- a/app/views/companies/_company.html.erb +++ b/app/views/companies/_company.html.erb @@ -1,47 +1,51 @@ -
-

- Name: - <%= company.name %> -

- -

- Id number: - <%= company.id_number %> -

- -

- Vat number: - <%= company.vat_number %> -

- -

- Address line one: - <%= company.address_line_one %> -

- -

- Address line two: - <%= company.address_line_two %> -

- -

- Postal code: - <%= company.postal_code %> -

- -

- City: - <%= company.city %> -

- -

- Entity: - <%= company.entity %> -

- -

- Country: - <%= company.country %> -

+
+
+

<%= company.name %>

+
+ + + +
+
+
+
+

+ <%= t('companies.company.id_number') %> + <%= company.id_number %> +

+

+ <%= t('companies.company.vat_number') %> + <%= company.vat_number %> +

+

+ <%= t('companies.company.entity') %> + <%= company.entity %> +

+

+ <%= t('companies.company.country') %> + <%= company.country %> +

+
+
+

+ <%= t('companies.company.address_line_one') %> + <%= company.address_line_one %> +

+ <% if company.address_line_two.present? %> +

+ <%= t('companies.company.address_line_two') %> + <%= company.address_line_two %> +

+ <% end %> +

+ <%= t('companies.company.postal_code') %> + <%= company.postal_code %> +

+

+ <%= t('companies.company.city') %> + <%= company.city %> +

+
+
diff --git a/app/views/companies/_form.html.erb b/app/views/companies/_form.html.erb index 2f0317d..4a37c07 100644 --- a/app/views/companies/_form.html.erb +++ b/app/views/companies/_form.html.erb @@ -1,7 +1,7 @@ <%= form_with(model: company, class: "contents") do |form| %> <% if company.errors.any? %>
-

<%= pluralize(company.errors.count, "error") %> prohibited this company from being saved:

+

<%= t('companies.form.errors.header', count: company.errors.count) %>