Move newsletter stats translaton inside component

The reason is, that translation strings outside weren't translated at all, even if they are present in .pot

[MAILPOET-6262]
This commit is contained in:
 Ján Mikláš
2024-10-03 11:09:42 +02:00
committed by Oluwaseun Olorunsola
parent 6a8a209d11
commit 2bc29c8b0a

View File

@ -10,7 +10,41 @@ type StatsBadgeProps = {
isInverted?: boolean; isInverted?: boolean;
}; };
const stats = { export const getBadgeType = (stat, rate) => {
if (!stat) {
return null;
}
if (rate < 0 || rate > 100) {
return null;
}
const len = stat.badgeRanges.length;
for (let i = 0; i < len; i += 1) {
if (rate > stat.badgeRanges[i]) {
return stat.badgeTypes[i];
}
}
// rate must be zero at this point
return stat.badgeTypes[len - 1];
};
function StatsBadge(props: StatsBadgeProps) {
const { isInverted = true } = props;
const badges = {
excellent: {
name: __('Excellent', 'mailpoet'),
tooltipTitle: __('Congrats!', 'mailpoet'),
},
good: {
name: __('Good', 'mailpoet'),
tooltipTitle: __('Good stuff.', 'mailpoet'),
},
critical: {
name: __('Critical', 'mailpoet'),
tooltipTitle: __('Something to improve.', 'mailpoet'),
},
};
const stats = {
opened: { opened: {
badgeRanges: [30, 10, 0], badgeRanges: [30, 10, 0],
badgeTypes: ['excellent', 'good', 'critical'], badgeTypes: ['excellent', 'good', 'critical'],
@ -59,45 +93,9 @@ const stats = {
critical: __('above 0.7%', 'mailpoet'), critical: __('above 0.7%', 'mailpoet'),
}, },
}, },
};
export const getBadgeType = (statName, rate) => {
const stat = stats[statName] || null;
if (!stat) {
return null;
}
if (rate < 0 || rate > 100) {
return null;
}
const len = stat.badgeRanges.length;
for (let i = 0; i < len; i += 1) {
if (rate > stat.badgeRanges[i]) {
return stat.badgeTypes[i];
}
}
// rate must be zero at this point
return stat.badgeTypes[len - 1];
};
function StatsBadge(props: StatsBadgeProps) {
const { isInverted = true } = props;
const badges = {
excellent: {
name: __('Excellent', 'mailpoet'),
tooltipTitle: __('Congrats!', 'mailpoet'),
},
good: {
name: __('Good', 'mailpoet'),
tooltipTitle: __('Good stuff.', 'mailpoet'),
},
critical: {
name: __('Critical', 'mailpoet'),
tooltipTitle: __('Something to improve.', 'mailpoet'),
},
}; };
const badgeType = getBadgeType(props.stat, props.rate); const badgeType = getBadgeType(stats[props.stat], props.rate);
const badge = badges[badgeType] || null; const badge = badges[badgeType] || null;
if (!badge) { if (!badge) {
return null; return null;