Skip to content

Commit

Permalink
WIP: Try to use PluralStringProxyImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhong committed Sep 12, 2024
1 parent d4e095a commit 48605ca
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ void AddLocalizedStrings(content::WebUIDataSource* html_source) {
{"braveVpnLoading", IDS_BRAVE_VPN_LOADING},
{"braveVpnPurchaseFailed", IDS_BRAVE_VPN_PURCHASE_FAILED},
{"braveVpnSelectYourServer", IDS_BRAVE_VPN_SELECT_YOUR_SERVER},
{"braveVpnServerSelectionCityInfo",
IDS_BRAVE_VPN_SERVER_SELECTION_CITY_INFO},
{"braveVpnServerSelectionSingleCity",
IDS_BRAVE_VPN_SERVER_SELECTION_SINGLE_CITY},
{"braveVpnServerSelectionMultipleCities",
Expand Down
8 changes: 8 additions & 0 deletions browser/ui/webui/brave_vpn/vpn_panel_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/webui/favicon_source.h"
#include "chrome/browser/ui/webui/plural_string_handler.h"
#include "chrome/browser/ui/webui/webui_util.h"
#include "components/favicon_base/favicon_url_parser.h"
#include "components/grit/brave_components_resources.h"
#include "components/grit/brave_components_strings.h"
#include "components/sessions/content/session_tab_helper.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
Expand All @@ -39,6 +41,12 @@ VPNPanelUI::VPNPanelUI(content::WebUI* web_ui)
content::WebUIDataSource* source = content::WebUIDataSource::CreateAndAdd(
web_ui->GetWebContents()->GetBrowserContext(), kVPNPanelURL);

auto plural_string_handler = std::make_unique<PluralStringHandler>();
plural_string_handler->AddLocalizedString(
"braveVpnServerSelectionCityInfo",
IDS_BRAVE_VPN_SERVER_SELECTION_CITY_INFO);
web_ui->AddMessageHandler(std::move(plural_string_handler));

brave_vpn::AddLocalizedStrings(source);
webui::SetupWebUIDataSource(
source,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import * as React from 'react'

import usePromise from '$web-common/usePromise'
import { PluralStringProxyImpl } from 'chrome://resources/js/plural_string_proxy.js'
import * as S from './style'
import Flag from '../flag'
import { Region } from '../../api/panel_browser_api'
Expand Down Expand Up @@ -60,19 +62,26 @@ function ConnectButton(props: ConnectButtonProps) {
interface RegionCityProps {
cityLabel: string
serverInfo: string
serverCount: number
selected: boolean
connectionButton: React.ReactElement
}

function RegionCity(props: RegionCityProps) {
const { result: serverInfo } = usePromise(
async () => PluralStringProxyImpl.getInstance().getPluralString(
'braveVpnServerSelectionCityInfo',
props.serverCount),
[props.serverCount])

return (
<S.RegionCity selected={props.selected}>
<S.RegionCityInfo>
<S.RegionCityLabel selected={props.selected}>
{props.cityLabel}
</S.RegionCityLabel>
<S.CityServerInfo selected={props.selected}>
{props.serverInfo}
{serverInfo}
</S.CityServerInfo>
</S.RegionCityInfo>
{props.selected && (
Expand Down Expand Up @@ -145,6 +154,7 @@ function RegionContent(props: RegionContentProps) {
<RegionCity
cityLabel={getLocale('braveVpnServerSelectionOptimalLabel')}
serverInfo={getLocale('braveVpnServerSelectionOptimalDesc')}
serverCount={0}
selected={
props.selected && currentRegion.name === props.region.name
}
Expand All @@ -160,6 +170,7 @@ function RegionContent(props: RegionContentProps) {
key={city.name}
cityLabel={city.namePretty}
serverInfo={getCityInfo(city.serverCount)}
serverCount={city.serverCount}
selected={props.selected && currentRegion.name === city.name}
connectionButton={
<ConnectButton
Expand Down
7 changes: 5 additions & 2 deletions components/resources/brave_vpn_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,11 @@
Select your server
</message>

<message name="IDS_BRAVE_VPN_SERVER_SELECTION_COUNTRY_INFO" desc="Text for the city and server count for the country">
<ph name="CITY_COUNT">$1<ex>5</ex></ph> cities - <ph name="SERVER_COUNT">$2<ex>5</ex></ph> servers
<message name="IDS_BRAVE_VPN_SERVER_SELECTION_CITY_INFO" desc="Text for the city info in selection panel">
{SERVER_COUNT, plural,
=1 {# server}
other {# servers}
}
</message>

<message name="IDS_BRAVE_VPN_SERVER_SELECTION_SINGLE_CITY" desc="Text for the single city in selection panel">
Expand Down

0 comments on commit 48605ca

Please sign in to comment.