From ecabf71149a8157e0525bad9eac55924895d502b Mon Sep 17 00:00:00 2001 From: Christoph Eicke Date: Sun, 9 Jun 2024 21:48:07 +0200 Subject: [PATCH] Localize the models Start with localizing the messages from the models. --- app/models/conversation.rb | 9 +- app/models/document.rb | 2 +- app/models/message.rb | 4 +- app/models/person.rb | 4 +- config/environments/development.rb | 3 + config/environments/test.rb | 3 + config/locales/de.yml | 236 ++++++++++++++++++++++++++ config/locales/en.yml | 257 +++++++++++++++++++++++++---- 8 files changed, 482 insertions(+), 36 deletions(-) create mode 100644 config/locales/de.yml diff --git a/app/models/conversation.rb b/app/models/conversation.rb index 33849c2c7..81d80a105 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -30,7 +30,14 @@ class Conversation < ApplicationRecord def self.grouped_by_increasing_time_interval_for_user(user) nav_conversations = user.conversations.ordered - keys = ["Today", "Yesterday", "This Week", "This Month", "Last Month", "Older"] + keys = [ + I18n.t('models.conversation.groupings.today'), + I18n.t('models.conversation.groupings.yesterday'), + I18n.t('models.conversation.groupings.this_week'), + I18n.t('models.conversation.groupings.this_month'), + I18n.t('models.conversation.groupings.last_month'), + I18n.t('models.conversation.groupings.older'), + ] values = [ nil, Date.today.beginning_of_day, diff --git a/app/models/document.rb b/app/models/document.rb index e8181ab86..d70e7c16c 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -70,7 +70,7 @@ def set_default_bytes end def file_present - errors.add(:file, "must be attached") unless file.attached? + errors.add(:file, I18n.t('activerecord.errors.messages.must_be_attached')) unless file.attached? end def wait_for_file_variant_to_process!(variant) diff --git a/app/models/message.rb b/app/models/message.rb index d13293b86..538c0b08a 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -58,11 +58,11 @@ def create_conversation end def validate_conversation - errors.add(:conversation, 'is invalid') unless conversation.user == Current.user + errors.add(:conversation, I18n.t('errors.messages.invalid')) unless conversation.user == Current.user end def validate_assistant - errors.add(:assistant, 'is invalid') unless assistant.user == Current.user + errors.add(:assistant, I18n.t('errors.messages.invalid')) unless assistant.user == Current.user end def start_assistant_reply diff --git a/app/models/person.rb b/app/models/person.rb index 3845640d6..36461455b 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -17,13 +17,13 @@ class Person < ApplicationRecord def personable_id_unchanged if personable_id_changed? && persisted? - errors.add(:personable_id, "cannot be changed after creation") + errors.add(:personable_id, I18n.t('errors.messages.cannot_be_changed_after_creation')) end end def proper_personable_id if personable_id.present? && personable.id.blank? - errors.add(:personable_id, 'must be provided on update') + errors.add(:personable_id, I18n.t('errors.messages.must_be_provided_on_update')) end end end diff --git a/config/environments/development.rb b/config/environments/development.rb index 0744cf6ad..96d037695 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -79,4 +79,7 @@ config.web_console.permissions = ["192.168.0.0/16", "172.17.0.0/16"] config.hosts << ENV['DEV_HOST'] if ENV['DEV_HOST'].present? + + # Uncomment if you want to force a different locale during development + # config.i18n.default_locale = :de end diff --git a/config/environments/test.rb b/config/environments/test.rb index 667e26d6c..cf9bd6b06 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -64,4 +64,7 @@ # Raise error when a before_action's only/except options reference missing actions config.action_controller.raise_on_missing_callback_actions = true + + # Set the default locale to 'en' when running tests + config.i18n.default_locale = :en end diff --git a/config/locales/de.yml b/config/locales/de.yml new file mode 100644 index 000000000..63f0a7429 --- /dev/null +++ b/config/locales/de.yml @@ -0,0 +1,236 @@ +de: + activerecord: + errors: + messages: + record_invalid: 'Gültigkeitsprüfung ist fehlgeschlagen: %{errors}' + restrict_dependent_destroy: + has_one: Datensatz kann nicht gelöscht werden, da ein abhängiger %{record}-Datensatz + existiert. + has_many: Datensatz kann nicht gelöscht werden, da abhängige %{record} existieren. + must_be_attached: muss angehängt sein + date: + abbr_day_names: + - So + - Mo + - Di + - Mi + - Do + - Fr + - Sa + abbr_month_names: + - + - Jan + - Feb + - Mär + - Apr + - Mai + - Jun + - Jul + - Aug + - Sep + - Okt + - Nov + - Dez + day_names: + - Sonntag + - Montag + - Dienstag + - Mittwoch + - Donnerstag + - Freitag + - Samstag + formats: + default: "%d.%m.%Y" + long: "%e. %B %Y" + short: "%e. %b" + month_names: + - + - Januar + - Februar + - März + - April + - Mai + - Juni + - Juli + - August + - September + - Oktober + - November + - Dezember + order: + - :day + - :month + - :year + datetime: + distance_in_words: + about_x_hours: + one: etwa eine Stunde + other: etwa %{count} Stunden + about_x_months: + one: etwa ein Monat + other: etwa %{count} Monate + about_x_years: + one: etwa ein Jahr + other: etwa %{count} Jahre + almost_x_years: + one: fast ein Jahr + other: fast %{count} Jahre + half_a_minute: eine halbe Minute + less_than_x_seconds: + one: weniger als eine Sekunde + other: weniger als %{count} Sekunden + less_than_x_minutes: + one: weniger als eine Minute + other: weniger als %{count} Minuten + over_x_years: + one: mehr als ein Jahr + other: mehr als %{count} Jahre + x_seconds: + one: eine Sekunde + other: "%{count} Sekunden" + x_minutes: + one: eine Minute + other: "%{count} Minuten" + x_days: + one: ein Tag + other: "%{count} Tage" + x_months: + one: ein Monat + other: "%{count} Monate" + x_years: + one: ein Jahr + other: "%{count} Jahre" + prompts: + second: Sekunde + minute: Minute + hour: Stunde + day: Tag + month: Monat + year: Jahr + errors: + format: "%{attribute} %{message}" + messages: + accepted: muss akzeptiert werden + blank: muss ausgefüllt werden + cannot_be_changed_after_creation: kann nach der Erstellung nicht geändert werden + confirmation: stimmt nicht mit %{attribute} überein + empty: muss ausgefüllt werden + equal_to: muss genau %{count} sein + even: muss gerade sein + exclusion: ist nicht verfügbar + greater_than: muss größer als %{count} sein + greater_than_or_equal_to: muss größer oder gleich %{count} sein + inclusion: ist kein gültiger Wert + invalid: ist nicht gültig + less_than: muss kleiner als %{count} sein + less_than_or_equal_to: muss kleiner oder gleich %{count} sein + model_invalid: 'Gültigkeitsprüfung ist fehlgeschlagen: %{errors}' + must_be_provided_on_update: muss beim Update bereitgestellt werden + not_a_number: ist keine Zahl + not_an_integer: muss ganzzahlig sein + odd: muss ungerade sein + other_than: darf nicht gleich %{count} sein + present: darf nicht ausgefüllt werden + required: muss ausgefüllt werden + taken: ist bereits vergeben + too_long: + one: ist zu lang (mehr als %{count} Zeichen) + other: ist zu lang (mehr als %{count} Zeichen) + too_short: + one: ist zu kurz (weniger als %{count} Zeichen) + other: ist zu kurz (weniger als %{count} Zeichen) + wrong_length: + one: hat die falsche Länge (muss genau %{count} Zeichen haben) + other: hat die falsche Länge (muss genau %{count} Zeichen haben) + template: + body: 'Bitte überprüfen Sie die folgenden Felder:' + header: + one: 'Konnte %{model} nicht speichern: ein Fehler.' + other: 'Konnte %{model} nicht speichern: %{count} Fehler.' + helpers: + select: + prompt: Bitte wählen + submit: + create: "%{model} erstellen" + submit: "%{model} speichern" + update: "%{model} aktualisieren" + number: + currency: + format: + delimiter: "." + format: "%n %u" + precision: 2 + separator: "," + significant: false + strip_insignificant_zeros: false + unit: "€" + format: + delimiter: "." + precision: 2 + round_mode: default + separator: "," + significant: false + strip_insignificant_zeros: false + human: + decimal_units: + format: "%n %u" + units: + billion: + one: Milliarde + other: Milliarden + million: + one: Million + other: Millionen + quadrillion: + one: Billiarde + other: Billiarden + thousand: Tausend + trillion: + one: Billion + other: Billionen + unit: '' + format: + delimiter: '' + precision: 3 + significant: true + strip_insignificant_zeros: true + storage_units: + format: "%n %u" + units: + byte: + one: Byte + other: Bytes + eb: EB + gb: GB + kb: KB + mb: MB + pb: PB + tb: TB + percentage: + format: + delimiter: '' + format: "%n %" + precision: + format: + delimiter: '' + support: + array: + last_word_connector: " und " + two_words_connector: " und " + words_connector: ", " + time: + am: vormittags + formats: + default: "%A, %d. %B %Y, %H:%M Uhr" + long: "%A, %d. %B %Y, %H:%M Uhr" + short: "%d. %b, %H:%M Uhr" + pm: nachmittags + models: + conversation: + groupings: + today: Heute + yesterday: Gestern + this_week: Diese Woche + this_month: Dieser Monat + last_month: Letzter Monat + older: Älter diff --git a/config/locales/en.yml b/config/locales/en.yml index 6c349ae5e..adbcb5706 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,31 +1,228 @@ -# Files in the config/locales directory are used for internationalization and -# are automatically loaded by Rails. If you want to use locales other than -# English, add the necessary files in this directory. -# -# To use the locales, use `I18n.t`: -# -# I18n.t "hello" -# -# In views, this is aliased to just `t`: -# -# <%= t("hello") %> -# -# To use a different locale, set it with `I18n.locale`: -# -# I18n.locale = :es -# -# This would use the information in config/locales/es.yml. -# -# To learn more about the API, please read the Rails Internationalization guide -# at https://guides.rubyonrails.org/i18n.html. -# -# Be aware that YAML interprets the following case-insensitive strings as -# booleans: `true`, `false`, `on`, `off`, `yes`, `no`. Therefore, these strings -# must be quoted to be interpreted as strings. For example: -# -# en: -# "yes": yup -# enabled: "ON" - en: - hello: "Hello world" + activerecord: + errors: + messages: + record_invalid: 'Validation failed: %{errors}' + restrict_dependent_destroy: + has_one: Cannot delete record because a dependent %{record} exists + has_many: Cannot delete record because dependent %{record} exist + must_be_attached: must be attached + date: + abbr_day_names: + - Sun + - Mon + - Tue + - Wed + - Thu + - Fri + - Sat + abbr_month_names: + - + - Jan + - Feb + - Mar + - Apr + - May + - Jun + - Jul + - Aug + - Sep + - Oct + - Nov + - Dec + day_names: + - Sunday + - Monday + - Tuesday + - Wednesday + - Thursday + - Friday + - Saturday + formats: + default: "%Y-%m-%d" + long: "%B %d, %Y" + short: "%b %d" + month_names: + - + - January + - February + - March + - April + - May + - June + - July + - August + - September + - October + - November + - December + order: + - :year + - :month + - :day + datetime: + distance_in_words: + about_x_hours: + one: about %{count} hour + other: about %{count} hours + about_x_months: + one: about %{count} month + other: about %{count} months + about_x_years: + one: about %{count} year + other: about %{count} years + almost_x_years: + one: almost %{count} year + other: almost %{count} years + half_a_minute: half a minute + less_than_x_seconds: + one: less than %{count} second + other: less than %{count} seconds + less_than_x_minutes: + one: less than a minute + other: less than %{count} minutes + over_x_years: + one: over %{count} year + other: over %{count} years + x_seconds: + one: "%{count} second" + other: "%{count} seconds" + x_minutes: + one: "%{count} minute" + other: "%{count} minutes" + x_days: + one: "%{count} day" + other: "%{count} days" + x_months: + one: "%{count} month" + other: "%{count} months" + x_years: + one: "%{count} year" + other: "%{count} years" + prompts: + second: Second + minute: Minute + hour: Hour + day: Day + month: Month + year: Year + errors: + format: "%{attribute} %{message}" + messages: + accepted: must be accepted + blank: can't be blank + cannot_be_changed_after_creation: cannot be changed after creation + confirmation: doesn't match %{attribute} + empty: can't be empty + equal_to: must be equal to %{count} + even: must be even + exclusion: is reserved + greater_than: must be greater than %{count} + greater_than_or_equal_to: must be greater than or equal to %{count} + in: must be in %{count} + inclusion: is not included in the list + invalid: is invalid + less_than: must be less than %{count} + less_than_or_equal_to: must be less than or equal to %{count} + model_invalid: 'Validation failed: %{errors}' + must_be_provided_on_update: must be provided on update + not_a_number: is not a number + not_an_integer: must be an integer + odd: must be odd + other_than: must be other than %{count} + present: must be blank + required: must exist + taken: has already been taken + too_long: + one: is too long (maximum is %{count} character) + other: is too long (maximum is %{count} characters) + too_short: + one: is too short (minimum is %{count} character) + other: is too short (minimum is %{count} characters) + wrong_length: + one: is the wrong length (should be %{count} character) + other: is the wrong length (should be %{count} characters) + template: + body: 'There were problems with the following fields:' + header: + one: "%{count} error prohibited this %{model} from being saved" + other: "%{count} errors prohibited this %{model} from being saved" + helpers: + select: + prompt: Please select + submit: + create: Create %{model} + submit: Save %{model} + update: Update %{model} + number: + currency: + format: + delimiter: "," + format: "%u%n" + precision: 2 + separator: "." + significant: false + strip_insignificant_zeros: false + unit: "$" + format: + delimiter: "," + precision: 3 + round_mode: default + separator: "." + significant: false + strip_insignificant_zeros: false + human: + decimal_units: + format: "%n %u" + units: + billion: Billion + million: Million + quadrillion: Quadrillion + thousand: Thousand + trillion: Trillion + unit: '' + format: + delimiter: '' + precision: 3 + significant: true + strip_insignificant_zeros: true + storage_units: + format: "%n %u" + units: + byte: + one: Byte + other: Bytes + eb: EB + gb: GB + kb: KB + mb: MB + pb: PB + tb: TB + percentage: + format: + delimiter: '' + format: "%n%" + precision: + format: + delimiter: '' + support: + array: + last_word_connector: ", and " + two_words_connector: " and " + words_connector: ", " + time: + am: am + formats: + default: "%a, %d %b %Y %H:%M:%S %z" + long: "%B %d, %Y %H:%M" + short: "%d %b %H:%M" + pm: pm + models: + conversation: + groupings: + today: Today + yesterday: Yesterday + this_week: This Week + this_month: This Month + last_month: Last Month + older: Older