-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tweak a localization to remove any assumption on "+" localization #19473
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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", | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
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%) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So yes, if we want to be explicit about the localization negative case, then we should handle cases when
|
||||||||||
stringFormat = NSLocalizedString( | ||||||||||
"insights.visitorsLineChartCell.differenceLabelNotPosiviteWithPercentage", | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Or (depending on @staskus 's reply to your answer in the PR description about why we don't use negative sign in the copy):
Suggested change
|
||||||||||
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() | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.