Skip to content

Commit 32d76ff

Browse files
committed
Merge remote-tracking branch 'upstream/dev' into chore-replace-i18n-calls
2 parents 699b568 + 84695ca commit 32d76ff

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

ts/components/conversation/composition/CharacterCount.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import styled from 'styled-components';
22
import { Constants } from '../../../session';
3-
import { Localizer } from '../../basic/Localizer';
43
import { useFeatureFlag } from '../../../state/ducks/types/releasedFeaturesReduxTypes';
54
import { SessionTooltip } from '../../SessionTooltip';
65
import { SessionIcon } from '../../icon';
@@ -12,6 +11,7 @@ import {
1211
import { formatNumber } from '../../../util/i18n/formatting/generics';
1312
import { useHasPro } from '../../../hooks/useHasPro';
1413
import { useIsProAvailable } from '../../../hooks/useIsProAvailable';
14+
import { localize } from '../../../localization/localeTools';
1515

1616
export type CharacterCountProps = {
1717
count: number;
@@ -68,13 +68,9 @@ export function CharacterCount({ count }: CharacterCountProps) {
6868
<SessionTooltip
6969
horizontalPosition="center"
7070
verticalPosition="bottom"
71-
content={
72-
pastLimit ? (
73-
<Localizer token="remainingCharactersOverTooltip" args={{ count: remaining * -1 }} />
74-
) : (
75-
<Localizer token="remainingCharactersTooltip" args={{ count: remaining }} />
76-
)
77-
}
71+
content={localize(
72+
pastLimit ? 'remainingCharactersOverTooltip' : 'remainingCharactersTooltip'
73+
).withArgs({ count: pastLimit ? remaining * -1 : remaining })}
7874
dataTestId="tooltip-character-count"
7975
>
8076
<StyledRemainingNumber pastLimit={pastLimit}>

ts/hooks/useDebouncedSelectAllOnTripleClickHandler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ export const useDebouncedSelectAllOnTripleClickHandler = ({
4040
const resetClickCount = useCallback(
4141
debounce(() => {
4242
clickCount.current = 0;
43-
}, 300),
43+
// NOTE: This value needs to be >= the browser's default triple click interval
44+
}, 500),
4445
[]
4546
);
4647

ts/localization/localeTools.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ function deSanitizeHtmlTags(str: string, identifier: string): string {
276276
.replace(new RegExp(`${identifier}&gt;${identifier}`, 'g'), '>');
277277
}
278278

279+
const pluralKey = 'count' as const;
280+
279281
class LocalizedStringBuilder<T extends MergedLocalizerTokens> extends String {
280282
private readonly token: T;
281283
private args?: ArgsFromToken<T>;
@@ -363,8 +365,6 @@ class LocalizedStringBuilder<T extends MergedLocalizerTokens> extends String {
363365
}
364366

365367
private resolvePluralString(): string {
366-
const pluralKey = 'count' as const;
367-
368368
let num: number | string | undefined = this.args?.[pluralKey as keyof ArgsFromToken<T>];
369369

370370
if (num === undefined) {
@@ -420,17 +420,19 @@ class LocalizedStringBuilder<T extends MergedLocalizerTokens> extends String {
420420
}
421421
}
422422

423-
return pluralString.replaceAll('#', `${num}`);
423+
return pluralString;
424424
}
425425

426426
private formatStringWithArgs(str: string): string {
427427
/** Find and replace the dynamic variables in a localized string and substitute the variables with the provided values */
428428
return str.replace(/\{(\w+)\}/g, (match, arg: string) => {
429-
const matchedArg = this.args
430-
? this.args[arg as keyof ArgsFromToken<T>]?.toString()
431-
: undefined;
429+
const matchedArg = this.args ? this.args[arg as keyof ArgsFromToken<T>] : undefined;
430+
431+
if (arg === pluralKey && typeof matchedArg === 'number' && Number.isFinite(matchedArg)) {
432+
return new Intl.NumberFormat(this.crowdinLocale).format(matchedArg);
433+
}
432434

433-
return matchedArg ?? match;
435+
return matchedArg?.toString() ?? match;
434436
});
435437
}
436438
}

0 commit comments

Comments
 (0)