Skip to content

Commit

Permalink
Localize the models
Browse files Browse the repository at this point in the history
Start with localizing the messages from the models.
  • Loading branch information
ceicke committed Jun 9, 2024
1 parent af36793 commit ecabf71
Show file tree
Hide file tree
Showing 8 changed files with 482 additions and 36 deletions.
9 changes: 8 additions & 1 deletion app/models/conversation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions app/models/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
236 changes: 236 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit ecabf71

Please sign in to comment.