Skip to content

Commit

Permalink
Make sure screen name is internationalized
Browse files Browse the repository at this point in the history
Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
  • Loading branch information
automated-signal and indutny-signal committed Jun 3, 2021
1 parent 629790d commit 3e602c4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
12 changes: 11 additions & 1 deletion _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3384,7 +3384,17 @@
},
"calling__SelectPresentingSourcesModal--entireScreen": {
"message": "Entire screen",
"description": "Title for the select your screen sharing sources modal"
"description": "Title for the select your screen sharing sources modal and 'Entire Screen' source"
},
"calling__SelectPresentingSourcesModal--screen": {
"message": "Screen $id$",
"description": "Title for `Screen #N` source in screen sharing sources modal and overlay",
"placeholders": {
"id": {
"content": "$1",
"example": "1"
}
}
},
"calling__SelectPresentingSourcesModal--window": {
"message": "A window",
Expand Down
17 changes: 11 additions & 6 deletions ts/components/CallingSelectPresentingSourcesModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { LocalizerType } from '../types/Util';
import { Modal } from './Modal';
import { PresentedSource, PresentableSource } from '../types/Calling';
import { Theme } from '../util/theme';
import { isScreenSource, translateSourceName } from '../services/calling';

export type PropsType = {
i18n: LocalizerType;
Expand All @@ -17,14 +18,18 @@ export type PropsType = {
};

const Source = ({
i18n,
onSourceClick,
source,
sourceToPresent,
}: {
i18n: LocalizerType;
onSourceClick: (source: PresentedSource) => void;
source: PresentableSource;
sourceToPresent?: PresentedSource;
}): JSX.Element => {
const name = translateSourceName(i18n, source);

return (
<button
className={classNames({
Expand All @@ -42,22 +47,22 @@ const Source = ({
type="button"
>
<img
alt={source.name}
alt={name}
className="module-CallingSelectPresentingSourcesModal__name--screenshot"
src={source.thumbnail}
/>
<div className="module-CallingSelectPresentingSourcesModal__name--container">
{source.appIcon ? (
<img
alt={source.name}
alt={name}
className="module-CallingSelectPresentingSourcesModal__name--icon"
height={16}
src={source.appIcon}
width={16}
/>
) : null}
<span className="module-CallingSelectPresentingSourcesModal__name--text">
{source.name}
{name}
</span>
</div>
</button>
Expand All @@ -77,9 +82,7 @@ export const CallingSelectPresentingSourcesModal = ({
throw new Error('No sources available for presenting');
}

const sources = groupBy(presentingSourcesAvailable, source =>
source.id.startsWith('screen')
);
const sources = groupBy(presentingSourcesAvailable, isScreenSource);

return (
<Modal
Expand All @@ -98,6 +101,7 @@ export const CallingSelectPresentingSourcesModal = ({
<div className="module-CallingSelectPresentingSourcesModal__sources">
{sources.true.map(source => (
<Source
i18n={i18n}
key={source.id}
onSourceClick={selectedSource => setSourceToPresent(selectedSource)}
source={source}
Expand All @@ -111,6 +115,7 @@ export const CallingSelectPresentingSourcesModal = ({
<div className="module-CallingSelectPresentingSourcesModal__sources">
{sources.false.map(source => (
<Source
i18n={i18n}
key={source.id}
onSourceClick={selectedSource => setSourceToPresent(selectedSource)}
source={source}
Expand Down
33 changes: 32 additions & 1 deletion ts/services/calling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
PresentableSource,
PresentedSource,
} from '../types/Calling';
import { LocalizerType } from '../types/Util';
import { ConversationModel } from '../models/conversations';
import {
base64ToArrayBuffer,
Expand Down Expand Up @@ -89,6 +90,33 @@ enum GroupCallUpdateMessageState {
SentLeft,
}

export function isScreenSource(source: PresentedSource): boolean {
return source.id.startsWith('screen');
}

export function translateSourceName(
i18n: LocalizerType,
source: PresentedSource
): string {
const { name } = source;
if (!isScreenSource(source)) {
return name;
}

if (name === 'Entire Screen') {
return i18n('calling__SelectPresentingSourcesModal--entireScreen');
}

const match = name.match(/^Screen (\d+)$/);
if (match) {
return i18n('calling__SelectPresentingSourcesModal--screen', {
id: match[1],
});
}

return name;
}

export class CallingClass {
readonly videoCapturer: GumVideoCapturer;

Expand Down Expand Up @@ -954,7 +982,10 @@ export class CallingClass {
this.setOutgoingVideoIsScreenShare(call, isPresenting);

if (source) {
ipcRenderer.send('show-screen-share', source.name);
ipcRenderer.send(
'show-screen-share',
translateSourceName(window.i18n, source)
);
notify({
icon: 'images/icons/v2/video-solid-24.svg',
message: window.i18n('calling__presenting--notification-body'),
Expand Down

0 comments on commit 3e602c4

Please sign in to comment.