feat: i18n for token related pages

This commit is contained in:
JustSong
2025-02-01 15:11:07 +08:00
parent 93ce6c4cd7
commit 60f2776795
7 changed files with 385 additions and 185 deletions

View File

@@ -1,4 +1,5 @@
import { Label } from 'semantic-ui-react';
import { useTranslation } from 'react-i18next';
export function renderText(text, limit) {
if (text.length > limit) {
@@ -39,23 +40,27 @@ export function renderNumber(num) {
}
}
export function renderQuota(quota, digits = 2) {
let quotaPerUnit = localStorage.getItem('quota_per_unit');
let displayInCurrency = localStorage.getItem('display_in_currency');
quotaPerUnit = parseFloat(quotaPerUnit);
displayInCurrency = displayInCurrency === 'true';
export function renderQuota(quota, t, precision = 2) {
const displayInCurrency = localStorage.getItem('display_in_currency') === 'true';
const quotaPerUnit = parseFloat(localStorage.getItem('quota_per_unit') || '1');
if (displayInCurrency) {
return '$' + (quota / quotaPerUnit).toFixed(digits);
const amount = (quota / quotaPerUnit).toFixed(precision);
return t('common.quota.display_short', { amount });
}
return renderNumber(quota);
}
export function renderQuotaWithPrompt(quota, digits) {
let displayInCurrency = localStorage.getItem('display_in_currency');
displayInCurrency = displayInCurrency === 'true';
export function renderQuotaWithPrompt(quota, t) {
const displayInCurrency = localStorage.getItem('display_in_currency') === 'true';
const quotaPerUnit = parseFloat(localStorage.getItem('quota_per_unit') || '1');
if (displayInCurrency) {
return `(等价金额:${renderQuota(quota, digits)}`;
const amount = (quota / quotaPerUnit).toFixed(2);
return ` (${t('common.quota.display', { amount })})`;
}
return '';
}