Skip to content

Commit

Permalink
Fixed plural issue in VPN server selection panel
Browse files Browse the repository at this point in the history
fix brave/brave-browser#40987

"city" should be used for single city otherwise "cities" is used.
"server" should be used for single server otherwise "servers" is used.
  • Loading branch information
simonhong committed Sep 12, 2024
1 parent b5e1306 commit d4e095a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ void AddLocalizedStrings(content::WebUIDataSource* html_source) {
{"braveVpnLoading", IDS_BRAVE_VPN_LOADING},
{"braveVpnPurchaseFailed", IDS_BRAVE_VPN_PURCHASE_FAILED},
{"braveVpnSelectYourServer", IDS_BRAVE_VPN_SELECT_YOUR_SERVER},
{"braveVpnServerSelectionCountryInfo",
IDS_BRAVE_VPN_SERVER_SELECTION_COUNTRY_INFO},
{"braveVpnServerSelectionCityInfo",
IDS_BRAVE_VPN_SERVER_SELECTION_CITY_INFO},
{"braveVpnServerSelectionSingleCity",
IDS_BRAVE_VPN_SERVER_SELECTION_SINGLE_CITY},
{"braveVpnServerSelectionMultipleCities",
IDS_BRAVE_VPN_SERVER_SELECTION_MULTIPLE_CITIES},
{"braveVpnServerSelectionSingleServer",
IDS_BRAVE_VPN_SERVER_SELECTION_SINGLE_SERVER},
{"braveVpnServerSelectionMultipleServers",
IDS_BRAVE_VPN_SERVER_SELECTION_MULTIPLE_SERVERS},
{"braveVpnServerSelectionAutomaticLabel",
IDS_BRAVE_VPN_SERVER_SELECTION_AUTOMATIC_LABEL},
{"braveVpnServerSelectionOptimalLabel",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,31 @@ import Flag from '../flag'
import { Region } from '../../api/panel_browser_api'
import { useSelector, useDispatch } from '../../state/hooks'
import * as Actions from '../../state/actions'
import { getLocale, getLocaleWithReplacements } from '$web-common/locale'
import { getLocale } from '$web-common/locale'

import 'emptykit.css'

function getCountryInfo(numCity: number, numServer: number) {
const city =
numCity === 1
? getLocale('braveVpnServerSelectionSingleCity')
: getLocale('braveVpnServerSelectionMultipleCities').replace(
'$1',
`${numCity}`
)

return `${city} - ${getCityInfo(numServer)}`
}

function getCityInfo(numServer: number) {
return numServer === 1
? getLocale('braveVpnServerSelectionSingleServer')
: getLocale('braveVpnServerSelectionMultipleServers').replace(
'$1',
`${numServer}`
)
}

interface ConnectButtonProps {
right: string
connect: () => void
Expand Down Expand Up @@ -82,11 +103,6 @@ function RegionContent(props: RegionContentProps) {
if (props.selected) ref.current?.scrollIntoView()
}, [])

const countryInfo = {
$1: props.region.cities.length,
$2: props.region.serverCount
}

return (
<S.RegionContainer
selected={props.selected}
Expand All @@ -105,9 +121,9 @@ function RegionContent(props: RegionContentProps) {
{props.region.namePretty}
</S.RegionCountryLabel>
<S.CountryServerInfo selected={!props.open && props.selected}>
{getLocaleWithReplacements(
'braveVpnServerSelectionCountryInfo',
countryInfo
{getCountryInfo(
props.region.cities.length,
props.region.serverCount
)}
</S.CountryServerInfo>
</S.CountryInfo>
Expand Down Expand Up @@ -143,10 +159,7 @@ function RegionContent(props: RegionContentProps) {
<RegionCity
key={city.name}
cityLabel={city.namePretty}
serverInfo={getLocale('braveVpnServerSelectionCityInfo').replace(
'$1',
`${city.serverCount}`
)}
serverInfo={getCityInfo(city.serverCount)}
selected={props.selected && currentRegion.name === city.name}
connectionButton={
<ConnectButton
Expand Down
6 changes: 4 additions & 2 deletions components/brave_vpn/resources/panel/stories/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ provideStrings({
'Unable to check the status of your purchase. This is probably a network problem. Try again or contact support.',
braveVpnSelectPanelBackButtonAriaLabel: 'Go to main',
braveVpnSelectYourServer: 'Select your server',
braveVpnServerSelectionCountryInfo: '$1 cities - $2 servers',
braveVpnServerSelectionCityInfo: '$1 servers',
braveVpnServerSelectionSingleCity: '1 city',
braveVpnServerSelectionMultipleCities: '$1 cities',
braveVpnServerSelectionSingleServer: '1 server',
braveVpnServerSelectionMultipleServers: '$1 servers',
braveVpnServerSelectionAutomaticLabel: 'Automatic',
braveVpnServerSelectionOptimalLabel: 'Optimal',
braveVpnServerSelectionOptimalDesc: 'Use the best server available',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const mockRegionList: Region[] = [
'regionPrecision': 'city',
'isAutomatic': false,
'cities': [],
'serverCount': 8
'serverCount': 1
}
],
'continent': 'Oceania',
Expand All @@ -29,7 +29,7 @@ export const mockRegionList: Region[] = [
'namePretty': 'Australia',
'regionPrecision': 'country',
'isAutomatic': false,
'serverCount': 8
'serverCount': 1
},
{
'cities': [
Expand Down
14 changes: 13 additions & 1 deletion components/resources/brave_vpn_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,19 @@
<ph name="CITY_COUNT">$1<ex>5</ex></ph> cities - <ph name="SERVER_COUNT">$2<ex>5</ex></ph> servers
</message>

<message name="IDS_BRAVE_VPN_SERVER_SELECTION_CITY_INFO" desc="Text for the server count for the city">
<message name="IDS_BRAVE_VPN_SERVER_SELECTION_SINGLE_CITY" desc="Text for the single city in selection panel">
1 city
</message>

<message name="IDS_BRAVE_VPN_SERVER_SELECTION_MULTIPLE_CITIES" desc="Text for the multiple cities in selection panel">
<ph name="CITY_COUNT">$1<ex>5</ex></ph> cities
</message>

<message name="IDS_BRAVE_VPN_SERVER_SELECTION_SINGLE_SERVER" desc="Text for the single server in selection panel">
1 server
</message>

<message name="IDS_BRAVE_VPN_SERVER_SELECTION_MULTIPLE_SERVERS" desc="Text for the multiple servers in selection panel">
<ph name="SERVER_COUNT">$1<ex>5</ex></ph> servers
</message>

Expand Down

0 comments on commit d4e095a

Please sign in to comment.