From a1d56abb97c26edf60b1b7115abec6e720ee005d Mon Sep 17 00:00:00 2001 From: situchan Date: Thu, 12 Feb 2026 21:51:01 +0600 Subject: [PATCH 1/3] refactor policy rules modified system message --- src/languages/de.ts | 34 ++++++----------------- src/languages/en.ts | 41 ++++++---------------------- src/languages/es.ts | 41 ++++++---------------------- src/languages/fr.ts | 34 ++++++----------------- src/languages/it.ts | 34 ++++++----------------- src/languages/ja.ts | 34 ++++++----------------- src/languages/nl.ts | 34 ++++++----------------- src/languages/pl.ts | 34 ++++++----------------- src/languages/pt-BR.ts | 34 ++++++----------------- src/languages/zh-hans.ts | 34 ++++++----------------- src/libs/ModifiedExpenseMessage.ts | 44 ++++++++++++++++++++++++++---- 11 files changed, 129 insertions(+), 269 deletions(-) diff --git a/src/languages/de.ts b/src/languages/de.ts index 35a758b8b897..e8758ecb0516 100644 --- a/src/languages/de.ts +++ b/src/languages/de.ts @@ -1545,31 +1545,15 @@ const translations: TranslationDeepObject = { }, correctDistanceRateError: 'Behebe den Fehler beim Entfernungssatz und versuche es erneut.', AskToExplain: `. Erklären ✨`, - policyRulesModifiedFields: (policyRulesModifiedFields: PolicyRulesModifiedFields, policyRulesRoute: string, formatList: (list: string[]) => string) => { - const entries = ObjectUtils.typedEntries(policyRulesModifiedFields); - const fragments = entries.map(([key, value], i) => { - const isFirst = i === 0; - if (key === 'reimbursable') { - return value ? 'hat die Ausgabe als „erstattungsfähig“ markiert' : 'hat die Ausgabe als „nicht erstattungsfähig“ markiert'; - } - if (key === 'billable') { - return value ? 'hat die Ausgabe als „verrechenbar“ markiert' : 'hat die Ausgabe als „nicht abrechenbar“ markiert'; - } - if (key === 'tax') { - const taxEntry = value as PolicyRulesModifiedFields['tax']; - const taxRateName = taxEntry?.field_id_TAX.name ?? ''; - if (isFirst) { - return `Steuersatz auf „${taxRateName}“ festlegen`; - } - return `Steuersatz auf „${taxRateName}“`; - } - const updatedValue = value as string | boolean; - if (isFirst) { - return `setze ${translations.common[key].toLowerCase()} auf „${updatedValue}“`; - } - return `${translations.common[key].toLowerCase()} zu „${updatedValue}“`; - }); - return `${formatList(fragments)} über Workspace-Regeln`; + policyRulesModifiedFields: { + reimbursable: (value: boolean) => (value ? 'hat die Ausgabe als „erstattungsfähig“ markiert' : 'hat die Ausgabe als „nicht erstattungsfähig“ markiert'), + billable: (value: boolean) => (value ? 'hat die Ausgabe als „verrechenbar“ markiert' : 'hat die Ausgabe als „nicht abrechenbar“ markiert'), + tax: (value: string, isFirst: boolean) => (isFirst ? `Steuersatz auf „${value}“ festlegen` : `Steuersatz auf „${value}“`), + common: (key: keyof PolicyRulesModifiedFields, value: string, isFirst: boolean) => { + const field = translations.common[key].toLowerCase(); + return isFirst ? `setze ${field} auf „${value}“` : `${field} zu „${value}“`; + }, + format: (fragments: string, route: string) => `${fragments} über Workspace-Regeln`, }, duplicateNonDefaultWorkspacePerDiemError: 'Sie können Per-Diem-Ausgaben nicht über mehrere Workspaces hinweg duplizieren, da sich die Sätze zwischen den Workspaces unterscheiden können.', diff --git a/src/languages/en.ts b/src/languages/en.ts index 86de05f1f00a..603b2d07a4c4 100644 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -1549,38 +1549,15 @@ const translations = { }, correctDistanceRateError: 'Fix the distance rate error and try again.', AskToExplain: `. Explain ✨`, - policyRulesModifiedFields: (policyRulesModifiedFields: PolicyRulesModifiedFields, policyRulesRoute: string, formatList: (list: string[]) => string) => { - const entries = ObjectUtils.typedEntries(policyRulesModifiedFields); - - const fragments = entries.map(([key, value], i) => { - const isFirst = i === 0; - - if (key === 'reimbursable') { - return value ? 'marked the expense as "reimbursable"' : 'marked the expense as "non-reimbursable"'; - } - - if (key === 'billable') { - return value ? 'marked the expense as "billable"' : 'marked the expense as "non-billable"'; - } - - if (key === 'tax') { - const taxEntry = value as PolicyRulesModifiedFields['tax']; - const taxRateName = taxEntry?.field_id_TAX.name ?? ''; - if (isFirst) { - return `set the tax rate to "${taxRateName}"`; - } - return `tax rate to "${taxRateName}"`; - } - - const updatedValue = value as string | boolean; - if (isFirst) { - return `set the ${translations.common[key].toLowerCase()} to "${updatedValue}"`; - } - - return `${translations.common[key].toLowerCase()} to "${updatedValue}"`; - }); - - return `${formatList(fragments)} via workspace rules`; + policyRulesModifiedFields: { + reimbursable: (value: boolean) => (value ? 'marked the expense as "reimbursable"' : 'marked the expense as "non-reimbursable"'), + billable: (value: boolean) => (value ? 'marked the expense as "billable"' : 'marked the expense as "non-billable"'), + tax: (value: string, isFirst: boolean) => (isFirst ? `set the tax rate to "${value}"` : `tax rate to "${value}"`), + common: (key: keyof PolicyRulesModifiedFields, value: string, isFirst: boolean) => { + const field = translations.common[key].toLowerCase(); + return isFirst ? `set the ${field} to "${value}"` : `${field} to "${value}"`; + }, + format: (fragments: string, route: string) => `${fragments} via workspace rules`, }, duplicateNonDefaultWorkspacePerDiemError: "You can't duplicate per diem expenses across workspaces because the rates may differ between workspaces.", }, diff --git a/src/languages/es.ts b/src/languages/es.ts index cfbd934aa1dd..034bda8a884a 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -1320,38 +1320,15 @@ const translations: TranslationDeepObject = { }, correctDistanceRateError: 'Corrige el error de la tasa de distancia y vuelve a intentarlo.', AskToExplain: `. Explicar ✨`, - policyRulesModifiedFields: (policyRulesModifiedFields: PolicyRulesModifiedFields, policyRulesRoute: string, formatList: (list: string[]) => string) => { - const entries = ObjectUtils.typedEntries(policyRulesModifiedFields); - - const fragments = entries.map(([key, value], i) => { - const isFirst = i === 0; - - if (key === 'reimbursable') { - return value ? 'marcó el gasto como "reembolsable"' : 'marcó el gasto como "no reembolsable"'; - } - - if (key === 'billable') { - return value ? 'marcó el gasto como "facturable"' : 'marcó el gasto como "no facturable"'; - } - - if (key === 'tax') { - const taxEntry = value as PolicyRulesModifiedFields['tax']; - const taxRateName = taxEntry?.field_id_TAX.name ?? ''; - if (isFirst) { - return `estableció la tasa de impuesto a "${taxRateName}"`; - } - return `tasa de impuesto a "${taxRateName}"`; - } - - const updatedValue = value as string | boolean; - if (isFirst) { - return `estableció el ${translations.common[key].toLowerCase()} a "${updatedValue}"`; - } - - return `${translations.common[key].toLowerCase()} a "${updatedValue}"`; - }); - - return `${formatList(fragments)} a través de reglas del espacio de trabajo`; + policyRulesModifiedFields: { + reimbursable: (value: boolean) => (value ? 'marcó el gasto como "reembolsable"' : 'marcó el gasto como "no reembolsable"'), + billable: (value: boolean) => (value ? 'marcó el gasto como "facturable"' : 'marcó el gasto como "no facturable"'), + tax: (value: string, isFirst: boolean) => (isFirst ? `estableció la tasa de impuesto a "${value}"` : `tasa de impuesto a "${value}"`), + common: (key: keyof PolicyRulesModifiedFields, value: string, isFirst: boolean) => { + const field = translations.common[key].toLowerCase(); + return isFirst ? `estableció el ${field} a "${value}"` : `${field} a "${value}"`; + }, + format: (fragments: string, route: string) => `${fragments} a través de reglas del espacio de trabajo`, }, duplicateNonDefaultWorkspacePerDiemError: 'No puedes duplicar gastos de viáticos entre espacios de trabajo porque las tarifas pueden variar entre ellos.', }, diff --git a/src/languages/fr.ts b/src/languages/fr.ts index fa05ed6c5fb8..bca028502e67 100644 --- a/src/languages/fr.ts +++ b/src/languages/fr.ts @@ -1552,31 +1552,15 @@ const translations: TranslationDeepObject = { }, correctDistanceRateError: 'Corrigez l’erreur de taux de distance, puis réessayez.', AskToExplain: `. Expliquer ✨`, - policyRulesModifiedFields: (policyRulesModifiedFields: PolicyRulesModifiedFields, policyRulesRoute: string, formatList: (list: string[]) => string) => { - const entries = ObjectUtils.typedEntries(policyRulesModifiedFields); - const fragments = entries.map(([key, value], i) => { - const isFirst = i === 0; - if (key === 'reimbursable') { - return value ? 'a marqué la dépense comme « remboursable »' : 'a marqué la dépense comme « non remboursable »'; - } - if (key === 'billable') { - return value ? 'a marqué la dépense comme « facturable »' : 'a marqué la dépense comme « non refacturable »'; - } - if (key === 'tax') { - const taxEntry = value as PolicyRulesModifiedFields['tax']; - const taxRateName = taxEntry?.field_id_TAX.name ?? ''; - if (isFirst) { - return `définir le taux de taxe sur « ${taxRateName} »`; - } - return `taux de taxe à « ${taxRateName} »`; - } - const updatedValue = value as string | boolean; - if (isFirst) { - return `définir ${translations.common[key].toLowerCase()} sur « ${updatedValue} »`; - } - return `${translations.common[key].toLowerCase()} à « ${updatedValue} »`; - }); - return `${formatList(fragments)} via les règles de l’espace de travail`; + policyRulesModifiedFields: { + reimbursable: (value: boolean) => (value ? 'a marqué la dépense comme « remboursable »' : 'a marqué la dépense comme « non remboursable »'), + billable: (value: boolean) => (value ? 'a marqué la dépense comme « facturable »' : 'a marqué la dépense comme « non refacturable »'), + tax: (value: string, isFirst: boolean) => (isFirst ? `définir le taux de taxe sur « ${value} »` : `taux de taxe à « ${value} »`), + common: (key: keyof PolicyRulesModifiedFields, value: string, isFirst: boolean) => { + const field = translations.common[key].toLowerCase(); + return isFirst ? `définir ${field} sur « ${value} »` : `${field} à « ${value} »`; + }, + format: (fragments: string, route: string) => `${fragments} via les règles de l’espace de travail`, }, duplicateNonDefaultWorkspacePerDiemError: 'Vous ne pouvez pas dupliquer les indemnités journalières entre plusieurs espaces de travail, car les taux peuvent différer d’un espace de travail à l’autre.', diff --git a/src/languages/it.ts b/src/languages/it.ts index 62414a798278..604df9ba2276 100644 --- a/src/languages/it.ts +++ b/src/languages/it.ts @@ -1542,31 +1542,15 @@ const translations: TranslationDeepObject = { }, correctDistanceRateError: 'Correggi l’errore nella tariffa distanza e riprova.', AskToExplain: `. Spiega ✨`, - policyRulesModifiedFields: (policyRulesModifiedFields: PolicyRulesModifiedFields, policyRulesRoute: string, formatList: (list: string[]) => string) => { - const entries = ObjectUtils.typedEntries(policyRulesModifiedFields); - const fragments = entries.map(([key, value], i) => { - const isFirst = i === 0; - if (key === 'reimbursable') { - return value ? 'ha contrassegnato la spesa come "rimborsabile"' : 'ha contrassegnato la spesa come "non rimborsabile"'; - } - if (key === 'billable') { - return value ? 'ha contrassegnato la spesa come "fatturabile"' : 'ha contrassegnato la spesa come "non fatturabile"'; - } - if (key === 'tax') { - const taxEntry = value as PolicyRulesModifiedFields['tax']; - const taxRateName = taxEntry?.field_id_TAX.name ?? ''; - if (isFirst) { - return `imposta l’aliquota fiscale su "${taxRateName}"`; - } - return `aliquota fiscale a "${taxRateName}"`; - } - const updatedValue = value as string | boolean; - if (isFirst) { - return `imposta ${translations.common[key].toLowerCase()} su "${updatedValue}"`; - } - return `${translations.common[key].toLowerCase()} a "${updatedValue}"`; - }); - return `${formatList(fragments)} tramite le regole dello spazio di lavoro`; + policyRulesModifiedFields: { + reimbursable: (value: boolean) => (value ? 'ha contrassegnato la spesa come "rimborsabile"' : 'ha contrassegnato la spesa come "non rimborsabile"'), + billable: (value: boolean) => (value ? 'ha contrassegnato la spesa come "fatturabile"' : 'ha contrassegnato la spesa come "non fatturabile"'), + tax: (value: string, isFirst: boolean) => (isFirst ? `imposta l’aliquota fiscale su "${value}"` : `aliquota fiscale a "${value}"`), + common: (key: keyof PolicyRulesModifiedFields, value: string, isFirst: boolean) => { + const field = translations.common[key].toLowerCase(); + return isFirst ? `imposta ${field} su "${value}"` : `${field} a "${value}"`; + }, + format: (fragments: string, route: string) => `${fragments} tramite le regole dello spazio di lavoro`, }, duplicateNonDefaultWorkspacePerDiemError: 'Non puoi duplicare le spese di diaria tra diversi spazi di lavoro perché le tariffe potrebbero essere diverse tra gli spazi di lavoro.', }, diff --git a/src/languages/ja.ts b/src/languages/ja.ts index 5b6847321fab..f6c34581f7fe 100644 --- a/src/languages/ja.ts +++ b/src/languages/ja.ts @@ -1537,31 +1537,15 @@ const translations: TranslationDeepObject = { }, correctDistanceRateError: '距離レートのエラーを修正して、もう一度お試しください。', AskToExplain: `. 説明 ✨`, - policyRulesModifiedFields: (policyRulesModifiedFields: PolicyRulesModifiedFields, policyRulesRoute: string, formatList: (list: string[]) => string) => { - const entries = ObjectUtils.typedEntries(policyRulesModifiedFields); - const fragments = entries.map(([key, value], i) => { - const isFirst = i === 0; - if (key === 'reimbursable') { - return value ? '経費を「精算対象」としてマークしました' : '経費を「非精算」としてマークしました'; - } - if (key === 'billable') { - return value ? '経費を「請求可能」に設定しました' : '経費を「請求不可」としてマークしました'; - } - if (key === 'tax') { - const taxEntry = value as PolicyRulesModifiedFields['tax']; - const taxRateName = taxEntry?.field_id_TAX.name ?? ''; - if (isFirst) { - return `税率を「${taxRateName}」に設定する`; - } - return `税率を「${taxRateName}」に`; - } - const updatedValue = value as string | boolean; - if (isFirst) { - return `${translations.common[key].toLowerCase()} を「${updatedValue}」に設定する`; - } - return `${translations.common[key].toLowerCase()} から「${updatedValue}」へ`; - }); - return `${formatList(fragments)}(ワークスペースルール経由)`; + policyRulesModifiedFields: { + reimbursable: (value: boolean) => (value ? '経費を「精算対象」としてマークしました' : '経費を「非精算」としてマークしました'), + billable: (value: boolean) => (value ? '経費を「請求可能」に設定しました' : '経費を「請求不可」としてマークしました'), + tax: (value: string, isFirst: boolean) => (isFirst ? `税率を「${value}」に設定する` : `税率を「${value}」に`), + common: (key: keyof PolicyRulesModifiedFields, value: string, isFirst: boolean) => { + const field = translations.common[key].toLowerCase(); + return isFirst ? `${field} を「${value}」に設定する` : `${field} から「${value}」へ`; + }, + format: (fragments: string, route: string) => `${fragments}(ワークスペースルール経由)`, }, duplicateNonDefaultWorkspacePerDiemError: 'ワークスペースごとに日当レートが異なる場合があるため、日当経費をワークスペース間で複製することはできません。', }, diff --git a/src/languages/nl.ts b/src/languages/nl.ts index a6d424ad4d07..48152948b568 100644 --- a/src/languages/nl.ts +++ b/src/languages/nl.ts @@ -1542,31 +1542,15 @@ const translations: TranslationDeepObject = { }, correctDistanceRateError: 'Los het foutieve afstandstarief op en probeer het opnieuw.', AskToExplain: `. Uitleggen ✨`, - policyRulesModifiedFields: (policyRulesModifiedFields: PolicyRulesModifiedFields, policyRulesRoute: string, formatList: (list: string[]) => string) => { - const entries = ObjectUtils.typedEntries(policyRulesModifiedFields); - const fragments = entries.map(([key, value], i) => { - const isFirst = i === 0; - if (key === 'reimbursable') { - return value ? 'heeft de uitgave gemarkeerd als „vergoedbaar”' : 'markeerde de uitgave als ‘niet-terugbetaalbaar’'; - } - if (key === 'billable') { - return value ? 'heeft de uitgave gemarkeerd als ‘door te belasten’' : 'heeft de uitgave gemarkeerd als ‘niet factureerbaar’'; - } - if (key === 'tax') { - const taxEntry = value as PolicyRulesModifiedFields['tax']; - const taxRateName = taxEntry?.field_id_TAX.name ?? ''; - if (isFirst) { - return `stel het belastingtarief in op „${taxRateName}”`; - } - return `belastingtarief naar „${taxRateName}”`; - } - const updatedValue = value as string | boolean; - if (isFirst) { - return `stel de ${translations.common[key].toLowerCase()} in op "${updatedValue}"`; - } - return `${translations.common[key].toLowerCase()} naar "${updatedValue}"`; - }); - return `${formatList(fragments)} via werkruimte­regels`; + policyRulesModifiedFields: { + reimbursable: (value: boolean) => (value ? 'heeft de uitgave gemarkeerd als „vergoedbaar”' : 'markeerde de uitgave als ‘niet-terugbetaalbaar’'), + billable: (value: boolean) => (value ? 'heeft de uitgave gemarkeerd als ‘door te belasten’' : 'heeft de uitgave gemarkeerd als ‘niet factureerbaar’'), + tax: (value: string, isFirst: boolean) => (isFirst ? `stel het belastingtarief in op „${value}”` : `belastingtarief naar „${value}”`), + common: (key: keyof PolicyRulesModifiedFields, value: string, isFirst: boolean) => { + const field = translations.common[key].toLowerCase(); + return isFirst ? `stel de ${field} in op "${value}"` : `${field} naar "${value}"`; + }, + format: (fragments: string, route: string) => `${fragments} via werkruimte­regels`, }, duplicateNonDefaultWorkspacePerDiemError: 'Je kunt dagvergoedingen niet dupliceren tussen werkruimtes, omdat de tarieven per werkruimte kunnen verschillen.', }, diff --git a/src/languages/pl.ts b/src/languages/pl.ts index c89befddfd28..430ddae5603e 100644 --- a/src/languages/pl.ts +++ b/src/languages/pl.ts @@ -1541,31 +1541,15 @@ const translations: TranslationDeepObject = { }, correctDistanceRateError: 'Napraw błąd stawki za dystans i spróbuj ponownie.', AskToExplain: `. Wyjaśnij ✨`, - policyRulesModifiedFields: (policyRulesModifiedFields: PolicyRulesModifiedFields, policyRulesRoute: string, formatList: (list: string[]) => string) => { - const entries = ObjectUtils.typedEntries(policyRulesModifiedFields); - const fragments = entries.map(([key, value], i) => { - const isFirst = i === 0; - if (key === 'reimbursable') { - return value ? 'oznaczył(a) wydatek jako „podlegający zwrotowi”' : 'oznaczył(a) wydatek jako „niepodlegający zwrotowi”'; - } - if (key === 'billable') { - return value ? 'oznaczył(-a) wydatek jako „fakturowany”' : 'oznaczono wydatek jako „niefakturowalny”'; - } - if (key === 'tax') { - const taxEntry = value as PolicyRulesModifiedFields['tax']; - const taxRateName = taxEntry?.field_id_TAX.name ?? ''; - if (isFirst) { - return `ustaw stawkę podatku na „${taxRateName}”`; - } - return `stawka podatku na „${taxRateName}”`; - } - const updatedValue = value as string | boolean; - if (isFirst) { - return `ustaw ${translations.common[key].toLowerCase()} na „${updatedValue}”`; - } - return `${translations.common[key].toLowerCase()} na „${updatedValue}”`; - }); - return `${formatList(fragments)} przez zasady przestrzeni roboczej`; + policyRulesModifiedFields: { + reimbursable: (value: boolean) => (value ? 'oznaczył(a) wydatek jako „podlegający zwrotowi”' : 'oznaczył(a) wydatek jako „niepodlegający zwrotowi”'), + billable: (value: boolean) => (value ? 'oznaczył(-a) wydatek jako „fakturowany”' : 'oznaczono wydatek jako „niefakturowalny”'), + tax: (value: string, isFirst: boolean) => (isFirst ? `ustaw stawkę podatku na „${value}”` : `stawka podatku na „${value}”`), + common: (key: keyof PolicyRulesModifiedFields, value: string, isFirst: boolean) => { + const field = translations.common[key].toLowerCase(); + return isFirst ? `ustaw ${field} na „${value}”` : `${field} na „${value}”`; + }, + format: (fragments: string, route: string) => `${fragments} przez zasady przestrzeni roboczej`, }, duplicateNonDefaultWorkspacePerDiemError: 'Nie możesz duplikować wydatków z tytułu diet między przestrzeniami roboczymi, ponieważ stawki mogą się różnić między poszczególnymi przestrzeniami.', diff --git a/src/languages/pt-BR.ts b/src/languages/pt-BR.ts index bc9eb8065018..c7f6dca06fe8 100644 --- a/src/languages/pt-BR.ts +++ b/src/languages/pt-BR.ts @@ -1539,31 +1539,15 @@ const translations: TranslationDeepObject = { }, correctDistanceRateError: 'Corrija o erro na taxa de distância e tente novamente.', AskToExplain: `. Explicar ✨`, - policyRulesModifiedFields: (policyRulesModifiedFields: PolicyRulesModifiedFields, policyRulesRoute: string, formatList: (list: string[]) => string) => { - const entries = ObjectUtils.typedEntries(policyRulesModifiedFields); - const fragments = entries.map(([key, value], i) => { - const isFirst = i === 0; - if (key === 'reimbursable') { - return value ? 'marcou a despesa como "reembolsável"' : 'marcou a despesa como “não reembolsável”'; - } - if (key === 'billable') { - return value ? 'marcou a despesa como "faturável"' : 'marcou a despesa como “não faturável”'; - } - if (key === 'tax') { - const taxEntry = value as PolicyRulesModifiedFields['tax']; - const taxRateName = taxEntry?.field_id_TAX.name ?? ''; - if (isFirst) { - return `definir a alíquota de imposto como "${taxRateName}"`; - } - return `alíquota de imposto para “${taxRateName}”`; - } - const updatedValue = value as string | boolean; - if (isFirst) { - return `defina ${translations.common[key].toLowerCase()} como "${updatedValue}"`; - } - return `${translations.common[key].toLowerCase()} para "${updatedValue}"`; - }); - return `${formatList(fragments)} via regras do espaço de trabalho`; + policyRulesModifiedFields: { + reimbursable: (value: boolean) => (value ? 'marcou a despesa como "reembolsável"' : 'marcou a despesa como “não reembolsável”'), + billable: (value: boolean) => (value ? 'marcou a despesa como "faturável"' : 'marcou a despesa como “não faturável”'), + tax: (value: string, isFirst: boolean) => (isFirst ? `definir a alíquota de imposto como "${value}"` : `alíquota de imposto para “${value}”`), + common: (key: keyof PolicyRulesModifiedFields, value: string, isFirst: boolean) => { + const field = translations.common[key].toLowerCase(); + return isFirst ? `defina ${field} como "${value}"` : `${field} para "${value}"`; + }, + format: (fragments: string, route: string) => `${fragments} via regras do espaço de trabalho`, }, duplicateNonDefaultWorkspacePerDiemError: 'Você não pode duplicar despesas de diárias entre espaços de trabalho porque as tarifas podem variar entre eles.', }, diff --git a/src/languages/zh-hans.ts b/src/languages/zh-hans.ts index 94d1d9cccc25..24609de422a9 100644 --- a/src/languages/zh-hans.ts +++ b/src/languages/zh-hans.ts @@ -1516,31 +1516,15 @@ const translations: TranslationDeepObject = { }, correctDistanceRateError: '修复距离费率错误后请重试。', AskToExplain: `。说明 ✨`, - policyRulesModifiedFields: (policyRulesModifiedFields: PolicyRulesModifiedFields, policyRulesRoute: string, formatList: (list: string[]) => string) => { - const entries = ObjectUtils.typedEntries(policyRulesModifiedFields); - const fragments = entries.map(([key, value], i) => { - const isFirst = i === 0; - if (key === 'reimbursable') { - return value ? '已将该报销单标记为“可报销”' : '将该报销单标记为“不可报销”'; - } - if (key === 'billable') { - return value ? '将该报销标记为“可计费”' : '将该报销标记为“不可计费”'; - } - if (key === 'tax') { - const taxEntry = value as PolicyRulesModifiedFields['tax']; - const taxRateName = taxEntry?.field_id_TAX.name ?? ''; - if (isFirst) { - return `将税率设置为“${taxRateName}”`; - } - return `税率为“${taxRateName}”`; - } - const updatedValue = value as string | boolean; - if (isFirst) { - return `将 ${translations.common[key].toLowerCase()} 设置为“${updatedValue}”`; - } - return `${translations.common[key].toLowerCase()} 至 “${updatedValue}”`; - }); - return `${formatList(fragments)} 通过 工作区规则`; + policyRulesModifiedFields: { + reimbursable: (value: boolean) => (value ? '已将该报销单标记为“可报销”' : '将该报销单标记为“不可报销”'), + billable: (value: boolean) => (value ? '将该报销标记为“可计费”' : '将该报销标记为“不可计费”'), + tax: (value: string, isFirst: boolean) => (isFirst ? `将税率设置为“${value}”` : `税率为“${value}”`), + common: (key: keyof PolicyRulesModifiedFields, value: string, isFirst: boolean) => { + const field = translations.common[key].toLowerCase(); + return isFirst ? `将 ${field} 设置为“${value}”` : `${field} 至 “${value}”`; + }, + format: (fragments: string, route: string) => `${fragments} 通过 工作区规则`, }, duplicateNonDefaultWorkspacePerDiemError: '您无法在不同工作区之间复制每日津贴报销,因为各工作区的补贴标准可能不同。', }, diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 25c3a2c0b3e3..8b601c816aca 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -7,6 +7,8 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {Policy, PolicyTagLists, Report, ReportAction} from '@src/types/onyx'; +import {PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage'; +import ObjectUtils from '@src/types/utils/ObjectUtils'; import {getDecodedCategoryName, isCategoryMissing} from './CategoryUtils'; import {convertToDisplayString} from './CurrencyUtils'; import DateUtils from './DateUtils'; @@ -16,7 +18,7 @@ import {formatList, translateLocal} from './Localize'; import Log from './Log'; import Parser from './Parser'; import {getPersonalDetailByEmail} from './PersonalDetailsUtils'; -import {getCleanedTagName, getPolicy, getSortedTagKeys, isPolicyAdmin} from './PolicyUtils'; +import {getCleanedTagName, getCommaSeparatedTagNameWithSanitizedColons, getPolicy, getSortedTagKeys, isPolicyAdmin} from './PolicyUtils'; import {getOriginalMessage, isModifiedExpenseAction} from './ReportActionsUtils'; // This cycle import is safe because ReportNameUtils was extracted from ReportUtils to separate report name computation logic. // The functions imported here are pure utility functions that don't create initialization-time dependencies. @@ -199,6 +201,40 @@ function getMovedFromOrToReportMessage(translate: LocalizedTranslate, movedFromR } } +function getPolicyRulesModifiedMessage(translate: LocalizedTranslate, fields: PolicyRulesModifiedFields, policyID: string) { + const route = `${environmentURL}/${ROUTES.WORKSPACE_RULES.getRoute(policyID)}`; + const entries = ObjectUtils.typedEntries(fields); + + const fragments = entries.map(([key, value], i) => { + const isFirst = i === 0; + + if (key === 'reimbursable') { + return translate('iou.policyRulesModifiedFields.reimbursable', value as boolean); + } + + if (key === 'billable') { + return translate('iou.policyRulesModifiedFields.billable', value as boolean); + } + + if (key === 'tax') { + const taxEntry = value as PolicyRulesModifiedFields['tax']; + const taxRateName = taxEntry?.field_id_TAX.name ?? ''; + return translate('iou.policyRulesModifiedFields.tax', taxRateName, isFirst); + } + + let updatedValue = value as string; + if (key === 'category') { + updatedValue = getDecodedCategoryName(updatedValue); + } else if (key === 'tag') { + updatedValue = getCommaSeparatedTagNameWithSanitizedColons(updatedValue); + } + + return translate('iou.policyRulesModifiedFields.common', key, updatedValue, isFirst); + }); + + return translate('iou.policyRulesModifiedFields.format', formatList(fragments), route); +} + /** * Get the report action message when expense has been modified. * @@ -474,9 +510,8 @@ function getForReportAction({ const policyRulesModifiedFields = reportActionOriginalMessage.policyRulesModifiedFields; if (policyRulesModifiedFields && rulePolicyID) { - const policyRulesRoute = `${environmentURL}/${ROUTES.WORKSPACE_RULES.getRoute(rulePolicyID)}`; // eslint-disable-next-line @typescript-eslint/no-deprecated - return translateLocal('iou.policyRulesModifiedFields', policyRulesModifiedFields, policyRulesRoute, formatList); + return getPolicyRulesModifiedMessage(translateLocal, policyRulesModifiedFields, rulePolicyID); } } @@ -718,8 +753,7 @@ function getForReportActionTemp({ const {policyRulesModifiedFields, policyID} = reportActionOriginalMessage; if (policyRulesModifiedFields && policyID) { - const policyRulesRoute = `${environmentURL}/${ROUTES.WORKSPACE_RULES.getRoute(policyID)}`; - return translate('iou.policyRulesModifiedFields', policyRulesModifiedFields, policyRulesRoute, formatList); + return getPolicyRulesModifiedMessage(translate, policyRulesModifiedFields, policyID); } } From 8fed2ce93984df6430047ec93f2bc52d8015f27e Mon Sep 17 00:00:00 2001 From: situchan Date: Thu, 12 Feb 2026 21:57:02 +0600 Subject: [PATCH 2/3] fix lint --- src/languages/de.ts | 1 - src/languages/en.ts | 1 - src/languages/es.ts | 1 - src/languages/fr.ts | 1 - src/languages/it.ts | 1 - src/languages/ja.ts | 1 - src/languages/nl.ts | 1 - src/languages/pl.ts | 1 - src/languages/pt-BR.ts | 1 - src/languages/zh-hans.ts | 1 - src/libs/ModifiedExpenseMessage.ts | 2 +- 11 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/languages/de.ts b/src/languages/de.ts index e8758ecb0516..82d2837812c0 100644 --- a/src/languages/de.ts +++ b/src/languages/de.ts @@ -18,7 +18,6 @@ import CONST from '@src/CONST'; import type {Country} from '@src/CONST'; import type OriginalMessage from '@src/types/onyx/OriginalMessage'; import type {OriginalMessageSettlementAccountLocked, PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage'; -import ObjectUtils from '@src/types/utils/ObjectUtils'; import type en from './en'; import type { AddBudgetParams, diff --git a/src/languages/en.ts b/src/languages/en.ts index 603b2d07a4c4..5165e9165d79 100644 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -7,7 +7,6 @@ import CONST from '@src/CONST'; import type {Country} from '@src/CONST'; import type OriginalMessage from '@src/types/onyx/OriginalMessage'; import type {OriginalMessageSettlementAccountLocked, PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage'; -import ObjectUtils from '@src/types/utils/ObjectUtils'; import type { AddBudgetParams, AddedOrDeletedPolicyReportFieldParams, diff --git a/src/languages/es.ts b/src/languages/es.ts index 034bda8a884a..485ad7d5a7bf 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -2,7 +2,6 @@ import {CONST as COMMON_CONST} from 'expensify-common'; import dedent from '@libs/StringUtils/dedent'; import CONST from '@src/CONST'; import type {OriginalMessageSettlementAccountLocked, PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage'; -import ObjectUtils from '@src/types/utils/ObjectUtils'; import type en from './en'; import type {CreatedReportForUnapprovedTransactionsParams, PaidElsewhereParams, RoutedDueToDEWParams, SplitDateRangeParams, UpdatedPolicyTagParams, ViolationsRterParams} from './params'; import type {TranslationDeepObject} from './types'; diff --git a/src/languages/fr.ts b/src/languages/fr.ts index bca028502e67..54b94444d266 100644 --- a/src/languages/fr.ts +++ b/src/languages/fr.ts @@ -18,7 +18,6 @@ import CONST from '@src/CONST'; import type {Country} from '@src/CONST'; import type OriginalMessage from '@src/types/onyx/OriginalMessage'; import type {OriginalMessageSettlementAccountLocked, PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage'; -import ObjectUtils from '@src/types/utils/ObjectUtils'; import type en from './en'; import type { AddBudgetParams, diff --git a/src/languages/it.ts b/src/languages/it.ts index 604df9ba2276..7a7a84a0e930 100644 --- a/src/languages/it.ts +++ b/src/languages/it.ts @@ -18,7 +18,6 @@ import CONST from '@src/CONST'; import type {Country} from '@src/CONST'; import type OriginalMessage from '@src/types/onyx/OriginalMessage'; import type {OriginalMessageSettlementAccountLocked, PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage'; -import ObjectUtils from '@src/types/utils/ObjectUtils'; import type en from './en'; import type { AddBudgetParams, diff --git a/src/languages/ja.ts b/src/languages/ja.ts index f6c34581f7fe..2d6aa8e63714 100644 --- a/src/languages/ja.ts +++ b/src/languages/ja.ts @@ -18,7 +18,6 @@ import CONST from '@src/CONST'; import type {Country} from '@src/CONST'; import type OriginalMessage from '@src/types/onyx/OriginalMessage'; import type {OriginalMessageSettlementAccountLocked, PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage'; -import ObjectUtils from '@src/types/utils/ObjectUtils'; import type en from './en'; import type { AddBudgetParams, diff --git a/src/languages/nl.ts b/src/languages/nl.ts index 48152948b568..faf521941339 100644 --- a/src/languages/nl.ts +++ b/src/languages/nl.ts @@ -18,7 +18,6 @@ import CONST from '@src/CONST'; import type {Country} from '@src/CONST'; import type OriginalMessage from '@src/types/onyx/OriginalMessage'; import type {OriginalMessageSettlementAccountLocked, PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage'; -import ObjectUtils from '@src/types/utils/ObjectUtils'; import type en from './en'; import type { AddBudgetParams, diff --git a/src/languages/pl.ts b/src/languages/pl.ts index 430ddae5603e..96fc6d24ce7e 100644 --- a/src/languages/pl.ts +++ b/src/languages/pl.ts @@ -18,7 +18,6 @@ import CONST from '@src/CONST'; import type {Country} from '@src/CONST'; import type OriginalMessage from '@src/types/onyx/OriginalMessage'; import type {OriginalMessageSettlementAccountLocked, PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage'; -import ObjectUtils from '@src/types/utils/ObjectUtils'; import type en from './en'; import type { AddBudgetParams, diff --git a/src/languages/pt-BR.ts b/src/languages/pt-BR.ts index c7f6dca06fe8..59ea453ea98d 100644 --- a/src/languages/pt-BR.ts +++ b/src/languages/pt-BR.ts @@ -18,7 +18,6 @@ import CONST from '@src/CONST'; import type {Country} from '@src/CONST'; import type OriginalMessage from '@src/types/onyx/OriginalMessage'; import type {OriginalMessageSettlementAccountLocked, PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage'; -import ObjectUtils from '@src/types/utils/ObjectUtils'; import type en from './en'; import type { AddBudgetParams, diff --git a/src/languages/zh-hans.ts b/src/languages/zh-hans.ts index 24609de422a9..b1cc67b337e1 100644 --- a/src/languages/zh-hans.ts +++ b/src/languages/zh-hans.ts @@ -18,7 +18,6 @@ import CONST from '@src/CONST'; import type {Country} from '@src/CONST'; import type OriginalMessage from '@src/types/onyx/OriginalMessage'; import type {OriginalMessageSettlementAccountLocked, PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage'; -import ObjectUtils from '@src/types/utils/ObjectUtils'; import type en from './en'; import type { AddBudgetParams, diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 8b601c816aca..76bc9048640d 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -7,7 +7,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type {Policy, PolicyTagLists, Report, ReportAction} from '@src/types/onyx'; -import {PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage'; +import type {PolicyRulesModifiedFields} from '@src/types/onyx/OriginalMessage'; import ObjectUtils from '@src/types/utils/ObjectUtils'; import {getDecodedCategoryName, isCategoryMissing} from './CategoryUtils'; import {convertToDisplayString} from './CurrencyUtils'; From cf2b6e8156adbe8bd560daa1c6140566a52f6b12 Mon Sep 17 00:00:00 2001 From: situchan Date: Thu, 12 Feb 2026 22:05:42 +0600 Subject: [PATCH 3/3] address feedback --- src/libs/ModifiedExpenseMessage.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 76bc9048640d..954b5abd1982 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -222,11 +222,12 @@ function getPolicyRulesModifiedMessage(translate: LocalizedTranslate, fields: Po return translate('iou.policyRulesModifiedFields.tax', taxRateName, isFirst); } - let updatedValue = value as string; + const updatedValue = value as string; if (key === 'category') { - updatedValue = getDecodedCategoryName(updatedValue); - } else if (key === 'tag') { - updatedValue = getCommaSeparatedTagNameWithSanitizedColons(updatedValue); + return translate('iou.policyRulesModifiedFields.common', key, getDecodedCategoryName(updatedValue), isFirst); + } + if (key === 'tag') { + return translate('iou.policyRulesModifiedFields.common', key, getCommaSeparatedTagNameWithSanitizedColons(updatedValue), isFirst); } return translate('iou.policyRulesModifiedFields.common', key, updatedValue, isFirst);