1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-05 21:45:23 +02:00

Allow users to set preferred locale in settings and provide basic date and time localization support (#1226)

* Add basic date and time localization

* Normalize translations

* Localize transaction dates

* Removed unsupported Rails locales
This commit is contained in:
Zach Gollwitzer 2024-10-02 14:02:17 -04:00 committed by GitHub
parent 7fabca4679
commit ab40289eb4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
130 changed files with 25190 additions and 10 deletions

View file

@ -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.

View file

@ -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

View file

@ -21,6 +21,6 @@ class Settings::PreferencesController < SettingsController
private
def preference_params
params.require(:user).permit(family_attributes: [ :id, :currency ])
params.require(:user).permit(family_attributes: [ :id, :currency, :locale ])
end
end

View file

@ -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)

View file

@ -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) %>

View file

@ -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>

View file

@ -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>