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:
committed by
Oluwaseun Olorunsola
parent
6a8a209d11
commit
2bc29c8b0a
@ -10,6 +10,40 @@ type StatsBadgeProps = {
|
|||||||
isInverted?: boolean;
|
isInverted?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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 = {
|
const stats = {
|
||||||
opened: {
|
opened: {
|
||||||
badgeRanges: [30, 10, 0],
|
badgeRanges: [30, 10, 0],
|
||||||
@ -61,43 +95,7 @@ const stats = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getBadgeType = (statName, rate) => {
|
const badgeType = getBadgeType(stats[props.stat], props.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 badge = badges[badgeType] || null;
|
const badge = badges[badgeType] || null;
|
||||||
if (!badge) {
|
if (!badge) {
|
||||||
return null;
|
return null;
|
||||||
|
Reference in New Issue
Block a user