Resolve [LOC] account names to human-readable display names
CI / docker (push) Has been cancelled
CI / build-and-test (push) Has started running

AccountNameResolver strips [LOC] prefix and looks up English display
names from a static dictionary matching the v5 .resx resource file.
Applied to all API endpoints that return account names:
- Inspect ledger (account ledger + general journal)
- Accounts tree dropdown
- Tree report endpoints (balance sheet + P&L)
- Account list endpoint

Examples: [LOC]Asset_BitcoinHot → "Bitcoin Hot Wallet",
[LOC]Cost_ForexLosses → "Forex Capital Losses",
[LOC]Debt_Equity → "Equity"

Non-[LOC] names (user-created accounts) pass through unchanged.
Future: load per-language from database for i18n support.

Made-with: Cursor
This commit is contained in:
2026-04-09 12:51:59 +02:00
parent 635a1911ad
commit da4a2b5cbc
4 changed files with 110 additions and 8 deletions
@@ -1,4 +1,5 @@
using UsingCash.Api.Configuration;
using UsingCash.Api.Support;
using UsingCash.Common.Enums;
using UsingCash.Database.Repositories;
@@ -15,7 +16,7 @@ public static class AccountEndpoints
var accounts = await repo.GetAccountsForOrganization(orgId);
return Results.Ok(accounts.Select(a => new
{
a.FinancialAccountId, a.Name, accountType = a.AccountType.ToString(),
a.FinancialAccountId, name = AccountNameResolver.Resolve(a.Name), accountType = a.AccountType.ToString(),
a.ParentFinancialAccountId, a.OwnerUserId, a.Open, a.OpenedYear, a.ClosedYear,
a.Expensable, a.EnabledForExpensing, a.EnabledForInvoicing
}));
@@ -1,3 +1,4 @@
using UsingCash.Api.Support;
using UsingCash.Database.Repositories;
namespace UsingCash.Api.Endpoints;
@@ -46,7 +47,7 @@ public static class InspectLedgerEndpoints
}
bool isGroup = accountIds.Count > 1;
var accountNameMap = allAccounts.ToDictionary(a => a.FinancialAccountId, a => a.Name);
var accountNameMap = allAccounts.ToDictionary(a => a.FinancialAccountId, a => AccountNameResolver.Resolve(a.Name));
var allRows = new List<(UsingCash.Basic.Types.BasicFinancialTransactionRow Row, int AccountId)>();
long priorBalance = 0;
@@ -96,7 +97,7 @@ public static class InspectLedgerEndpoints
return Results.Ok(new
{
accountId,
accountName = selectedAccount.Name,
accountName = AccountNameResolver.Resolve(selectedAccount.Name),
isGroup,
groupAccountCount = accountIds.Count,
year = yr,
@@ -115,7 +116,7 @@ public static class InspectLedgerEndpoints
return Results.Ok(accounts.Select(a => new
{
id = a.FinancialAccountId,
name = a.Name,
name = AccountNameResolver.Resolve(a.Name),
parentId = a.ParentFinancialAccountId,
accountType = a.AccountType.ToString(),
open = a.Open,
@@ -147,8 +148,8 @@ public static class InspectLedgerEndpoints
{
if (!accountMap.TryGetValue(acctId, out var acct)) return $"#{acctId}";
if (acct.ParentFinancialAccountId != 0 && accountMap.TryGetValue(acct.ParentFinancialAccountId, out var parent))
return $"{parent.Name} » {acct.Name}";
return acct.Name;
return $"{AccountNameResolver.Resolve(parent.Name)} » {AccountNameResolver.Resolve(acct.Name)}";
return AccountNameResolver.Resolve(acct.Name);
}
// Get ALL rows for ALL accounts in this org for the period, sorted by transaction
@@ -1,3 +1,4 @@
using UsingCash.Api.Support;
using UsingCash.Common.Enums;
using UsingCash.Database.Repositories;
@@ -49,7 +50,7 @@ public static class TreeReportEndpoints
nodes.Add(new
{
id = acct.Identity,
name = acct.Name,
name = AccountNameResolver.Resolve(acct.Name),
parentId = acct.ParentFinancialAccountId,
accountType = acct.AccountType.ToString(),
ownValues = values,
@@ -102,7 +103,7 @@ public static class TreeReportEndpoints
nodes.Add(new
{
id = acct.Identity,
name = acct.Name,
name = AccountNameResolver.Resolve(acct.Name),
parentId = acct.ParentFinancialAccountId,
accountType = acct.AccountType.ToString(),
ownValues = values,
@@ -0,0 +1,99 @@
namespace UsingCash.Api.Support;
/// <summary>
/// Resolves [LOC] prefixed account names to human-readable display names.
/// In v5, these were looked up from .resx resource files. In v6, we use a
/// static dictionary for the English defaults. Future: load per-language
/// from resource files or database.
/// </summary>
public static class AccountNameResolver
{
private static readonly Dictionary<string, string> EnglishNames = new(StringComparer.OrdinalIgnoreCase)
{
["Asset_BankAccount"] = "Bank Account",
["Asset_BankAccounts"] = "Bank Accounts",
["Asset_BitcoinCold"] = "Bitcoin Cold Storage",
["Asset_BitcoinHot"] = "Bitcoin Hot Wallet",
["Asset_CashAdvances"] = "Cash Advances",
["Asset_Hardware"] = "Hardware, Machinery, etc.",
["Asset_InboundVat"] = "Inbound VAT",
["Asset_InboundVatReported"] = "Surplus inbound VAT in report",
["Asset_InboundVatUnreported"] = "Inbound VAT to report",
["Asset_OutboundInvoices"] = "Outbound Invoices",
["Asset_Paypal"] = "PayPal Account",
["Asset_PrivateWithdrawals"] = "Private Withdrawals",
["Asset_PrivateWithdrawals_HealthInsurance"] = "Health Insurance",
["Asset_ShortTerm"] = "Short Term Assets",
["Asset_TaxAdvances"] = "Taxes Prepayment",
["Asset_TransfersInProgress"] = "Internal Transfers in Progress",
["Cost_AccountingErrors"] = "Accounting Errors",
["Cost_AllocatedFunds"] = "Allocated Funds",
["Cost_AnnualResult"] = "Annual Profit/Loss",
["Cost_AssetDepreciation"] = "Asset Depreciation",
["Cost_BankFees"] = "Bank Fees",
["Cost_BitcoinFees"] = "Bitcoin Miner Fees",
["Cost_BusinessServices"] = "Business Services",
["Cost_CentRounding"] = "Cent Rounding",
["Cost_Conferences"] = "Conferences",
["Cost_EventTickets"] = "Event Tickets",
["Cost_FinancialFees"] = "Financial Fees",
["Cost_ForexLosses"] = "Forex Capital Losses",
["Cost_Hospitality"] = "Hospitality",
["Cost_IctInfrastructure"] = "ICT and Infrastructure",
["Cost_InterestLosses"] = "Interest Losses",
["Cost_LegalFees"] = "Legal Fees",
["Cost_LodgingFiveStar"] = "5 Star",
["Cost_LodgingFourStar"] = "4 Star",
["Cost_LodgingHostel"] = "Hostel or budget equivalent",
["Cost_LodgingShared"] = "Shared lodging (AirBnB etc)",
["Cost_LodgingThreeStar"] = "3 Star",
["Cost_MaintenanceDonations"] = "Maintenance Donations",
["Cost_MarketingCampaigns"] = "Marketing and Campaigns",
["Cost_OfficeEquipment"] = "Office Equipment",
["Cost_Offices"] = "Offices",
["Cost_OfficeSpace"] = "Office Space",
["Cost_OfficeSupplies"] = "Office Supplies",
["Cost_PublicTransit"] = "Public Transit",
["Cost_ResearchDevelopment"] = "Research and Development",
["Cost_Staff"] = "Staff",
["Cost_StaffBenefits"] = "Staff Benefits",
["Cost_StaffExpenses"] = "Staff Expenses",
["Cost_StaffPerDiem"] = "Staff Per-Diem",
["Cost_StaffSalaries"] = "Staff Salaries",
["Cost_Taxes"] = "Taxes",
["Cost_TaxiTransport"] = "Taxi, Limo, etc.",
["Cost_TrainsFerries"] = "Trains and Ferries",
["Cost_Transportation"] = "Transportation",
["Cost_Travel"] = "Travel",
["Cost_TravelLodging"] = "Lodging",
["Cost_TravelPerDiem"] = "Per Diems",
["Cost_Unforeseen"] = "Unforeseen",
["Debt_Equity"] = "Equity",
["Debt_EquityRestricted"] = "Restricted Equity",
["Debt_EquityUnrestricted"] = "Unrestricted Equity",
["Debt_ExpenseClaims"] = "Expense Claims",
["Debt_General"] = "General Debt",
["Debt_InboundInvoices"] = "Inbound Invoices",
["Debt_OutboundVat"] = "Outbound VAT",
["Debt_OutboundVatReported"] = "Reported VAT to pay",
["Debt_OutboundVatUnreported"] = "Outbound VAT to report",
["Debt_PrivateDeposits"] = "Private Deposits",
["Debt_Salaries"] = "Salaries Due",
["Debt_Taxes"] = "Taxes Due",
["Income_Donations"] = "Donations",
["Income_ForexGains"] = "Forex Capital Gains",
["Income_InterestGains"] = "Interest Gains",
["Income_MembershipDues"] = "Membership Dues",
["Income_Sales"] = "Sales",
["Income_SubsidiesGrants"] = "Subsidies and Grants",
};
public static string Resolve(string name)
{
if (!name.StartsWith("[LOC]"))
return name;
var key = name[5..];
return EnglishNames.TryGetValue(key, out var localized) ? localized : name;
}
}