Add taxFromSaleProduct translation and enhance MoneyHistoryView for product loading
- Added new translation keys for "taxFromSaleProduct" in both German and English locales. - Updated MoneyHistoryView component to load product data asynchronously and map product IDs to their labels for improved activity translation handling. - Enhanced activity translation logic to support both legacy and new formats for tax-related activities.
This commit is contained in:
@@ -583,6 +583,7 @@
|
||||
"Production cost": "Produktionskosten",
|
||||
"Sell all products": "Alle Produkte verkauft",
|
||||
"sell products": "Produkte verkauft",
|
||||
"taxFromSaleProduct": "Steuer aus Verkauf: {product}",
|
||||
"director starts production": "Direktor beginnt Produktion",
|
||||
"director payed out": "Direktorgehalt ausgezahlt",
|
||||
"Buy storage (type: field)": "Lagerplatz gekauft (Typ: Feld)",
|
||||
|
||||
@@ -116,6 +116,7 @@
|
||||
"Production cost": "Production cost",
|
||||
"Sell all products": "Sell all products",
|
||||
"sell products": "Sell products",
|
||||
"taxFromSaleProduct": "Tax from product sale: {product}",
|
||||
"director starts production": "Director starts production",
|
||||
"director payed out": "Director salary paid out",
|
||||
"Buy storage (type: field)": "Bought storage (type: field)",
|
||||
|
||||
@@ -67,12 +67,28 @@ export default {
|
||||
currentPage: 1,
|
||||
totalPages: 1,
|
||||
},
|
||||
productsById: {},
|
||||
};
|
||||
},
|
||||
async mounted() {
|
||||
await this.fetchMoneyHistory(1);
|
||||
await Promise.all([this.loadProducts(), this.fetchMoneyHistory(1)]);
|
||||
},
|
||||
methods: {
|
||||
async loadProducts() {
|
||||
try {
|
||||
const { data } = await apiClient.get('/api/falukant/products');
|
||||
const map = {};
|
||||
for (const p of (data || [])) {
|
||||
if (p && p.id != null && p.labelTr) {
|
||||
map[String(p.id)] = p.labelTr;
|
||||
}
|
||||
}
|
||||
this.productsById = map;
|
||||
} catch (e) {
|
||||
console.error('Error loading products for money history', e);
|
||||
this.productsById = {};
|
||||
}
|
||||
},
|
||||
async fetchMoneyHistory(page) {
|
||||
try {
|
||||
const response = await apiClient.post('/api/falukant/moneyhistory', {
|
||||
@@ -85,6 +101,25 @@ export default {
|
||||
}
|
||||
},
|
||||
translateActivity(activity) {
|
||||
try {
|
||||
const raw = String(activity ?? '');
|
||||
// Handle legacy format: "tax from sale product 3"
|
||||
const m = raw.match(/^tax\s+from\s+sale\s+product\s+(\d+)$/i);
|
||||
if (m && m[1]) {
|
||||
const id = m[1];
|
||||
const labelTr = this.productsById[String(id)];
|
||||
const productName = labelTr ? this.$t(`falukant.product.${labelTr}`) : `#${id}`;
|
||||
return this.$t('falukant.moneyHistory.activities.taxFromSaleProduct', { product: productName });
|
||||
}
|
||||
// New/structured format: "taxFromSaleProduct.<labelTr>"
|
||||
if (raw.startsWith('taxFromSaleProduct.')) {
|
||||
const labelTr = raw.substring('taxFromSaleProduct.'.length);
|
||||
const productName = labelTr ? this.$t(`falukant.product.${labelTr}`) : labelTr;
|
||||
return this.$t('falukant.moneyHistory.activities.taxFromSaleProduct', { product: productName });
|
||||
}
|
||||
} catch (_) {
|
||||
// ignore and fall back
|
||||
}
|
||||
// Handle nested keys like "health.pill" -> "health.pill"
|
||||
const key = `falukant.moneyHistory.activities.${activity}`;
|
||||
const translation = this.$t(key);
|
||||
|
||||
Reference in New Issue
Block a user