Skip to content

Commit

Permalink
Allow users to set preferred locale in settings and provide basic dat…
Browse files Browse the repository at this point in the history
…e and time localization support (#1226)

* Add basic date and time localization

* Normalize translations

* Localize transaction dates

* Removed unsupported Rails locales
  • Loading branch information
zachgoll authored Oct 2, 2024
1 parent 7fabca4 commit ab40289
Show file tree
Hide file tree
Showing 130 changed files with 25,190 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ApplicationController < ActionController::Base
include AutoSync, Authentication, Invitable, SelfHostable, StoreLocation
include Localize, AutoSync, Authentication, Invitable, SelfHostable, StoreLocation
include Pagy::Backend

# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
Expand Down
13 changes: 13 additions & 0 deletions app/controllers/concerns/localize.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Localize
extend ActiveSupport::Concern

included do
around_action :switch_locale
end

private
def switch_locale(&action)
locale = Current.family.try(:locale) || I18n.default_locale
I18n.with_locale(locale, &action)
end
end
2 changes: 1 addition & 1 deletion app/controllers/settings/preferences_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ def update
private

def preference_params
params.require(:user).permit(family_attributes: [ :id, :currency ])
params.require(:user).permit(family_attributes: [ :id, :currency, :locale ])
end
end
2 changes: 2 additions & 0 deletions app/models/family.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class Family < ApplicationRecord
has_many :merchants, dependent: :destroy
has_many :issues, through: :accounts

validates :locale, inclusion: { in: I18n.available_locales.map(&:to_s) }

def snapshot(period = Period.all)
query = accounts.active.joins(:balances)
.where("account_balances.currency = ?", self.currency)
Expand Down
6 changes: 5 additions & 1 deletion app/views/account/entries/_entry_group.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
data: { action: "bulk-select#toggleGroupSelection" } %>
<% end %>

<%= tag.span "#{date.strftime('%b %d, %Y')} · #{entries.size}" %>
<p class="uppercase space-x-1.5">
<%= tag.span I18n.l(date, format: :long) %>
<span>·</span>
<%= tag.span entries.size %>
</p>
</div>

<%= totals_by_currency(collection: entries, money_method: :amount_money, negate: true) %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/account/transactions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</div>

<span class="text-sm text-gray-500">
<%= entry.date.strftime("%A %d %B") %>
<%= I18n.l(entry.date, format: :long) %>
</span>
</header>

Expand Down
7 changes: 7 additions & 0 deletions app/views/settings/preferences/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
currencies_for_select.map { |currency| [ "#{currency.name} (#{currency.iso_code})", currency.iso_code ] },
{ label: "Currency", selected: Current.family.currency },
{ data: { auto_submit_form_target: "auto" } } %>

<%= family_form.select :locale,
I18n.available_locales,
{ label: "Locale", selected: Current.family.locale },
{ data: { auto_submit_form_target: "auto" } } %>

<p class="text-xs italic pl-2 text-gray-500">Please note, we are still working on translations for various languages. Please see the <%= link_to "I18n issue", "https://github.com/maybe-finance/maybe/issues/1225", target: "_blank", class: "underline" %> for more information.</p>
<% end %>
<% end %>
</div>
Expand Down
3 changes: 3 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class Application < Rails::Application

config.active_job.queue_adapter = :good_job

# TODO: This is here for incremental adoption of localization. This can be removed when all translations are implemented.
config.i18n.fallbacks = true

config.app_mode = (ENV["SELF_HOSTING_ENABLED"] == "true" ? "self_hosted" : "managed").inquiry
end
end
11 changes: 10 additions & 1 deletion config/i18n-tasks.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
base_locale: en
fallbacks:
- default
data:
read:
- config/locales/**/*%{locale}.yml
Expand Down Expand Up @@ -26,9 +28,16 @@ search:
ignore_unused:
- 'activerecord.attributes.*' # i18n-tasks does not detect these on forms, forms validations (https://github.com/glebm/i18n-tasks/blob/0b4b483c82664f26c5696fb0f6aa1297356e4683/templates/config/i18n-tasks.yml#L146)
- 'activerecord.models.*' # i18n-tasks does not detect use in dynamic model names (e.g. object.model_name.human)
- 'activerecord.errors.models*'
- 'activerecord.errors*'
- 'activemodel.errors.models.*'
- 'helpers.submit.*' # i18n-tasks does not detect used at forms
- 'helpers.label.*' # i18n-tasks does not detect used at forms
- 'accounts.show.sync_message_*' # messages generated in the sync ActiveJob
- 'address.attributes.*'
- 'date.*'
- 'time.*'
- 'datetime.*'
- 'number.*'
- 'errors.*'
- 'helpers.*'
- 'support.*'
213 changes: 213 additions & 0 deletions config/locales/defaults/af.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
---
af:
activerecord:
errors:
messages:
record_invalid: 'Validering het misluk: %{errors}'
restrict_dependent_destroy:
has_many: Kan rekord nie skrap nie omdat afhanklike %{record} bestaan
has_one: Kan rekord nie skrap nie omdat 'n afhanklike %{record} bestaan
date:
abbr_day_names:
- Son
- Maan
- Dins
- Woe
- Don
- Vry
- Sat
abbr_month_names:
-
- Jan
- Feb
- Mar
- Apr
- Mei
- Jun
- Jul
- Aug
- Sep
- Okt
- Nov
- Des
day_names:
- Sondag
- Maandag
- Dinsdag
- Woensdag
- Donderdag
- Vrydag
- Saterdag
formats:
default: "%Y-%m-%d"
long: "%d %B %Y"
short: "%d %b"
month_names:
-
- Januarie
- Februarie
- Maart
- April
- Mei
- Junie
- Julie
- Augustus
- September
- Oktober
- November
- Desember
order:
- :year
- :month
- :day
datetime:
distance_in_words:
about_x_hours:
one: ongeveer %{count} uur
other: ongeveer %{count} ure
about_x_months:
one: ongeveer %{count} maand
other: ongeveer %{count} maande
about_x_years:
one: ongeveer %{count} jaar
other: ongeveer %{count} jaar
almost_x_years:
one: sowat %{count} jaar
other: sowat %{count} jaar
half_a_minute: halfminuut
less_than_x_minutes:
one: minder as %{count} minuut
other: minder as %{count} minute
less_than_x_seconds:
one: minder as %{count} sekonde
other: minder as %{count} sekondes
over_x_years:
one: meer as %{count} jaar
other: meer as %{count} jaar
x_days:
one: "%{count} dag"
other: "%{count} days"
x_minutes:
one: "%{count} minuut"
other: "%{count} minute"
x_months:
one: "%{count} maand"
other: "%{count} maande"
x_seconds:
one: "%{count} sekonde"
other: "%{count} sekondes"
x_years:
one: "%{count} jaar"
other: "%{count} jare"
prompts:
day: Dag
hour: Uur
minute: Minuut
month: Maand
second: Sekondes
year: Jaar
errors:
format: "%{attribute} %{message}"
messages:
accepted: moet aanvaar word
blank: mag nie leeg wees nie
confirmation: pas nie by bevestiging nie
empty: mag nie leeg wees nie
equal_to: moet gelyk wees aan %{count}
even: moet ewe wees
exclusion: is bespreek
greater_than: moet meer wees as %{count}
greater_than_or_equal_to: moet meer of gelykstaande wees aan %{count}
inclusion: is nie by die lys ingesluit nie
invalid: is ongeldig
less_than: moet minder wees as %{count}
less_than_or_equal_to: moet minder of gelykstaande wees aan %{count}
model_invalid: 'Validering het misluk: %{errors}'
not_a_number: is nie 'n getal nie
not_an_integer: moet 'n heelgetal wees
odd: moet onewe wees
other_than: moet anders wees as %{count}
present: moet leeg wees
required: moet bestaan
taken: is reeds geneem
too_long:
one: is te lank (maksimum is %{count} karakter)
other: is te lank (maksimum is %{count} karakters)
too_short:
one: is te kort (minimum is %{count} karakter)
other: is te kort (minimum is %{count} karakters)
wrong_length:
one: is die verkeerde lengte (moet %{count} karakter wees)
other: is die verkeerde lengte (moet %{count} karakters wees)
template:
body: 'There were problems with the following fields:'
header:
one: "%{count} fout het verhoed dat hierdie %{model} gestoor kon word"
other: "%{count} foute het verhoed dat hierdie %{model} gestoor kon word"
helpers:
select:
prompt: Kies asseblief
submit:
create: Skep %{model}
submit: Stoor %{model}
update: Dateer %{model} op
number:
currency:
format:
delimiter: " "
format: "%u %n"
precision: 2
separator: ","
significant: false
strip_insignificant_zeros: false
unit: R
format:
delimiter: ","
precision: 3
separator: "."
significant: false
strip_insignificant_zeros: false
human:
decimal_units:
format: "%n %u"
units:
billion: miljard
million: miljoen
quadrillion: biljard
thousand: duisend
trillion: biljoen
unit: ''
format:
delimiter: ''
precision: 3
significant: true
strip_insignificant_zeros: true
storage_units:
format: "%n %u"
units:
byte:
one: Greep
other: Grepe
gb: GG
kb: kG
mb: MG
tb: TG
percentage:
format:
delimiter: ''
format: "%n%"
precision:
format:
delimiter: ''
support:
array:
last_word_connector: ", en "
two_words_connector: " en "
words_connector: ", "
time:
am: vm
formats:
default: "%a, %d %b %Y %H:%M:%S %z"
long: "%d %B %Y %H:%M"
short: "%d %b %H:%M"
pm: nm
Loading

0 comments on commit ab40289

Please sign in to comment.