update currency symbols and currency symbol supports plural symbol

This commit is contained in:
MaysWind
2024-08-03 16:06:59 +08:00
parent 10dc2d1713
commit c91a56547f
4 changed files with 506 additions and 168 deletions
+4 -1
View File
@@ -286,7 +286,10 @@ export default {
return '0';
},
getDisplayCurrencyPrependAndAppendText() {
return this.$locale.getAmountPrependAndAppendText(this.settingsStore, this.userStore, this.currency);
const numericCurrentValue = this.$locale.parseAmount(this.userStore, this.currentValue);
const isPlural = numericCurrentValue !== 100 && numericCurrentValue !== -100;
return this.$locale.getAmountPrependAndAppendText(this.settingsStore, this.userStore, this.currency, isPlural);
}
}
}
+487 -158
View File
File diff suppressed because it is too large Load Diff
+9 -5
View File
@@ -2,7 +2,7 @@ import currencyConstants from '@/consts/currency.js';
import { isString, isNumber } from './common.js';
export function appendCurrencySymbol(value, currencyDisplayType, currencyCode, currencyName) {
export function appendCurrencySymbol(value, currencyDisplayType, currencyCode, currencyName, isPlural) {
if (isNumber(value)) {
value = value.toString();
}
@@ -11,7 +11,7 @@ export function appendCurrencySymbol(value, currencyDisplayType, currencyCode, c
return value;
}
const symbol = getAmountPrependAndAppendCurrencySymbol(currencyDisplayType, currencyCode, currencyName);
const symbol = getAmountPrependAndAppendCurrencySymbol(currencyDisplayType, currencyCode, currencyName, isPlural);
if (!symbol) {
return value;
@@ -30,7 +30,7 @@ export function appendCurrencySymbol(value, currencyDisplayType, currencyCode, c
return value;
}
export function getAmountPrependAndAppendCurrencySymbol(currencyDisplayType, currencyCode, currencyName) {
export function getAmountPrependAndAppendCurrencySymbol(currencyDisplayType, currencyCode, currencyName, isPlural) {
if (!currencyDisplayType) {
return null;
}
@@ -40,8 +40,12 @@ export function getAmountPrependAndAppendCurrencySymbol(currencyDisplayType, cur
if (currencyDisplayType.symbol === currencyConstants.allCurrencyDisplaySymbol.Symbol) {
const currencyInfo = currencyConstants.all[currencyCode];
if (currencyInfo && currencyInfo.symbol) {
symbol = currencyInfo.symbol;
if (currencyInfo && currencyInfo.symbol && currencyInfo.symbol.normal) {
symbol = currencyInfo.symbol.normal;
if (isPlural && currencyInfo.symbol.plural) {
symbol = currencyInfo.symbol.plural;
}
}
if (!symbol) {
+6 -4
View File
@@ -855,6 +855,8 @@ function getFormatedAmountWithCurrency(value, currencyCode, translateFn, userSto
value = value.toString();
}
const isPlural = value !== '100' && value !== '-100';
if (!notConvertValue) {
const numberFormatOptions = getNumberFormatOptions(translateFn, userStore);
const hasIncompleteFlag = isString(value) && value.charAt(value.length - 1) === '+';
@@ -885,7 +887,7 @@ function getFormatedAmountWithCurrency(value, currencyCode, translateFn, userSto
}
const currencyName = getCurrencyName(currencyCode, translateFn);
return appendCurrencySymbol(value, currencyDisplayType, currencyCode, currencyName);
return appendCurrencySymbol(value, currencyDisplayType, currencyCode, currencyName, isPlural);
}
function getFormatedExchangeRateAmount(value, translateFn, userStore) {
@@ -898,10 +900,10 @@ function getAdaptiveAmountRate(amount1, amount2, fromExchangeRate, toExchangeRat
return getAdaptiveDisplayAmountRate(amount1, amount2, fromExchangeRate, toExchangeRate, numberFormatOptions);
}
function getAmountPrependAndAppendText(currencyCode, userStore, settingsStore, translateFn) {
function getAmountPrependAndAppendText(currencyCode, userStore, settingsStore, isPlural, translateFn) {
const currencyDisplayType = getCurrentCurrencyDisplayType(translateFn, userStore);
const currencyName = getCurrencyName(currencyCode, translateFn);
return getAmountPrependAndAppendCurrencySymbol(currencyDisplayType, currencyCode, currencyName);
return getAmountPrependAndAppendCurrencySymbol(currencyDisplayType, currencyCode, currencyName, isPlural);
}
function getAllExpenseIncomeAmountColors(translateFn, expenseOrIncome) {
@@ -1466,7 +1468,7 @@ export function i18nFunctions(i18nGlobal) {
formatAmountWithCurrency: (settingsStore, userStore, value, currencyCode) => getFormatedAmountWithCurrency(value, currencyCode, i18nGlobal.t, userStore, settingsStore),
formatExchangeRateAmount: (userStore, value) => getFormatedExchangeRateAmount(value, i18nGlobal.t, userStore),
getAdaptiveAmountRate: (userStore, amount1, amount2, fromExchangeRate, toExchangeRate) => getAdaptiveAmountRate(amount1, amount2, fromExchangeRate, toExchangeRate, i18nGlobal.t, userStore),
getAmountPrependAndAppendText: (settingsStore, userStore, currencyCode) => getAmountPrependAndAppendText(currencyCode, userStore, settingsStore, i18nGlobal.t),
getAmountPrependAndAppendText: (settingsStore, userStore, currencyCode, isPlural) => getAmountPrependAndAppendText(currencyCode, userStore, settingsStore, isPlural, i18nGlobal.t),
getAllExpenseAmountColors: () => getAllExpenseIncomeAmountColors(i18nGlobal.t, 1),
getAllIncomeAmountColors: () => getAllExpenseIncomeAmountColors(i18nGlobal.t, 2),
getAllAccountCategories: () => getAllAccountCategories(i18nGlobal.t),