diff --git a/WordPress/Classes/ViewRelated/Stats/Insights/ViewsVisitors/ViewsVisitorsLineChartCell.swift b/WordPress/Classes/ViewRelated/Stats/Insights/ViewsVisitors/ViewsVisitorsLineChartCell.swift index 77222c7662e4..78c50d7d535d 100644 --- a/WordPress/Classes/ViewRelated/Stats/Insights/ViewsVisitors/ViewsVisitorsLineChartCell.swift +++ b/WordPress/Classes/ViewRelated/Stats/Insights/ViewsVisitors/ViewsVisitorsLineChartCell.swift @@ -57,30 +57,45 @@ struct StatsSegmentedControlData { // We want to show something like "+1.2K (5%)" if we have a percentage difference and "1.2K" if we don't. // Because localized strings need to be strings literal, we cannot embed any conditional logic in the `localizedString...` call. // We therefore need to generate different string literals based on the state. - let differenceSign = difference < 0 ? "" : "+" - if differencePercent != 0 { - let stringFormat = NSLocalizedString( - "insights.visitorsLineChartCell.differenceLabelWithPercentage", - value: "%@%@ (%@%%)", + switch (difference > 0, differencePercent != 0) { + case (true, true): // E.g.: +1.2k (5%) + stringFormat = NSLocalizedString( + "insights.visitorsLineChartCell.differenceLabelPosiviteWithPercentage", + value: "+%@ (%@%%)", comment: "Difference label for Insights Overview stat, indicating change from previous period, including percentage value. Example: +99.9K (5%)" ) return String.localizedStringWithFormat( stringFormat, - differenceSign, difference.abbreviatedString(), differencePercent.abbreviatedString() ) - } else { - let stringFormat = NSLocalizedString( - "insights.visitorsLineChartCell.differenceLabelWithoutPercentage", - value: "%@%@", + case (true, false): // E.g.: +1.2k + // We cannot assume every locale would translate an English string like "+1.2k" in the same way. + // So, even though we have only a "+" prefix, we ought to make this string localized. + stringFormat = NSLocalizedString( + "insights.visitorsLineChartCell.differenceLabelPosiviteWithoutPercentage", + value: "+%@", comment: "Difference label for Insights Overview stat, indicating change from previous period. Example: +99.9K" ) return String.localizedStringWithFormat( stringFormat, - differenceSign, difference.abbreviatedString() ) + case (false, true): // E.g. 1.2k (5%) + stringFormat = NSLocalizedString( + "insights.visitorsLineChartCell.differenceLabelNotPosiviteWithPercentage", + value: "%@ (%@%%)", + comment: "Difference label for Insights Overview stat, indicating change from previous period, including percentage value, when the change is 0 or less. Example: 99.9K (5%)" + ) + return String.localizedStringWithFormat( + stringFormat, + difference.abbreviatedString(), + differencePercent.abbreviatedString() + ) + break + case (false, false): // E.g.: 1.2k + // There's no + sign nor percentage value here, we don't need to add any localization treatment. + return difference.abbreviatedString() } }