Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Translate investment activity labels in the quick-edit badge (#4167)

Andrei Shkarin9869bcbdb6fa
diff --git a/app/helpers/transactions_helper.rb b/app/helpers/transactions_helper.rb
index 9471a1212b..ca01192315 100644
--- a/app/helpers/transactions_helper.rb
+++ b/app/helpers/transactions_helper.rb
@@ -16,6 +16,13 @@ module TransactionsHelper
]
end
+ # @param label [String] a stored investment_activity_label such as "Sweep In"
+ # @return [String] its name in the current locale, or the label itself when
+ # it has no translation
+ def investment_activity_label_name(label)
+ t("transactions.activity_labels.#{label.parameterize(separator: "_")}", default: label)
+ end
+
# @param filter [Hash] one entry from transaction_search_filters
# @return [String] the partial that renders that filter's controls
def get_transaction_search_filter_partial_path(filter)
diff --git a/app/views/investment_activity/_quick_edit_badge.html.erb b/app/views/investment_activity/_quick_edit_badge.html.erb
index 16b75ff08e..c8503a163d 100644
--- a/app/views/investment_activity/_quick_edit_badge.html.erb
+++ b/app/views/investment_activity/_quick_edit_badge.html.erb
@@ -61,7 +61,7 @@
data: (income_trade ? {} : { action: "click->activity-label-quick-edit#toggle", activity_label_quick_edit_target: "badge" }),
title: (has_label ? t("transactions.transaction.activity_type_tooltip") : t("transactions.show.activity_type"))) do %>
<% if has_label %>
- <%= label %>
+ <%= investment_activity_label_name(label) %>
<% else %>
<%= icon "tag", size: "xs", color: "current" %>
<span><%= t("transactions.show.activity_type") %></span>
@@ -89,7 +89,7 @@
class="w-full text-left px-3 py-1.5 text-sm text-primary hover:bg-surface-inset transition-colors <%= activity_label == label ? "font-semibold bg-surface-inset" : "" %>"
data-action="click->activity-label-quick-edit#select"
data-label="<%= activity_label %>">
- <%= activity_label %>
+ <%= investment_activity_label_name(activity_label) %>
</button>
<% end %>
</div>
diff --git a/app/views/transactions/show.html.erb b/app/views/transactions/show.html.erb
index ec59db9b53..9238b41a58 100644
--- a/app/views/transactions/show.html.erb
+++ b/app/views/transactions/show.html.erb
@@ -317,7 +317,7 @@
</div>
<%= ef.select :investment_activity_label,
options_for_select(
- [["—", nil]] + Transaction::ACTIVITY_LABELS.map { |l| [t("transactions.activity_labels.#{l.parameterize(separator: '_')}"), l] },
+ [["—", nil]] + Transaction::ACTIVITY_LABELS.map { |l| [investment_activity_label_name(l), l] },
@entry.entryable.investment_activity_label
),
{ label: false },
diff --git a/test/controllers/transactions_controller_test.rb b/test/controllers/transactions_controller_test.rb
index d0cddc6c3b..be5fbcdbbe 100644
--- a/test/controllers/transactions_controller_test.rb
+++ b/test/controllers/transactions_controller_test.rb
@@ -72,6 +72,22 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
"the preview-gated bill link must not render for a user without the flag"
end
+ test "the investment activity badge shows translated labels" do
+ @user.update!(locale: "ru")
+ accounts(:investment).entries.create!(
+ name: "Broker cash move", date: Date.current, amount: 100, currency: "USD",
+ entryable: Transaction.new(investment_activity_label: "Transfer")
+ )
+
+ get transactions_url
+
+ assert_response :success
+ assert_select "[data-activity-label-quick-edit-target=badge]", text: /Перевод/
+ assert_select "[data-activity-label-quick-edit-target=badge]", text: /Transfer/, count: 0
+ # The picker shows translated names but still submits the stored label.
+ assert_select "button[data-label='Sweep In']", text: "Автоперевод (зачисление)"
+ end
+
test "index groups subcategories immediately after their parent in the category filter" do
get transactions_url
assert_response :success
diff --git a/test/helpers/transactions_helper_test.rb b/test/helpers/transactions_helper_test.rb
index 20ffb8c563..5391408f11 100644
--- a/test/helpers/transactions_helper_test.rb
+++ b/test/helpers/transactions_helper_test.rb
@@ -141,4 +141,16 @@ class TransactionsHelperTest < ActionView::TestCase
assert_empty details[:provider_extras]
assert_equal({ "someprovider" => { "a" => 1 } }, JSON.parse(details[:raw]))
end
+
+ test "investment_activity_label_name translates the stored label" do
+ I18n.with_locale(:ru) do
+ assert_equal "Перевод", investment_activity_label_name("Transfer")
+ assert_equal "Автоперевод (зачисление)", investment_activity_label_name("Sweep In")
+ end
+ assert_equal "Buy", investment_activity_label_name("Buy")
+ end
+
+ test "investment_activity_label_name falls back to the stored label when it has no translation" do
+ assert_equal "Legacy Label", investment_activity_label_name("Legacy Label")
+ end
end