Skip to content

Commit b2240fd

Browse files
authored
Move the 100% match indicator into the editor menu (#4413)
The indicator pushed the menu down by its own height on every string that had a perfect match, and let it back up on every string that didn't. Moving between such strings made the menu jump, which #4410 made worse by removing the confirmation dialog that used to slow that movement down. Show it next to the translation length instead.
1 parent 7cc05fe commit b2240fd

6 files changed

Lines changed: 78 additions & 23 deletions

File tree

translate/public/locale/en-US/translate.ftl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ editor-KeyboardShortcuts--copy-from-next-helper-shortcut = <mod1>Ctrl</mod1> + <
236236
## Editor machinery source indicator
237237
## Shown when a perfect match is provided automatically from translation memory
238238

239-
editor-MachinerySourceIndicator--text = <stress>100%</stress> MATCH FROM TRANSLATION MEMORY
239+
editor-MachinerySourceIndicator--match = <stress>100%</stress> MATCH
240+
.title = 100% Translation Memory match
240241
241242
242243
## Editor New Contributor Tooltip

translate/src/modules/editor/components/Editor.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ import { TranslationForm } from '~/modules/translationform';
55
import './Editor.css';
66
import { EditorMenu } from './EditorMenu';
77
import { NewContributorTooltip } from './NewContributorTooltip';
8-
import { MachinerySourceIndicator } from './MachinerySourceIndicator';
98

109
export const Editor = () => (
1110
<div className='editor'>
1211
<NewContributorTooltip />
1312
<TranslationForm />
14-
<MachinerySourceIndicator />
1513
<EditorMenu />
1614
</div>
1715
);

translate/src/modules/editor/components/EditorMenu.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { EditorSettings } from './EditorSettings';
1616
import { FailedChecks } from './FailedChecks';
1717
import { FtlSwitch } from './FtlSwitch';
1818
import { KeyboardShortcuts } from './KeyboardShortcuts';
19+
import { MachinerySourceIndicator } from './MachinerySourceIndicator';
1920
import { TranslationLength } from './TranslationLength';
2021

2122
/**
@@ -79,6 +80,7 @@ function MenuContent() {
7980
<EditorSettings settings={settings} updateSetting={updateSetting} />
8081
<KeyboardShortcuts />
8182
<TranslationLength />
83+
<MachinerySourceIndicator />
8284
<div className='actions'>
8385
<Localized id='editor-EditorMenu--button-copy' attrs={{ title: true }}>
8486
<button

translate/src/modules/editor/components/MachinerySourceIndicator.css

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
.tm-source {
2+
background-color: var(--background-1);
3+
border: 1px solid var(--main-border-1);
4+
border-radius: 3px;
5+
color: var(--editor-menu-color);
6+
float: left;
27
font-size: 11px;
3-
padding: 10px 0;
4-
border-bottom: 1px solid var(--main-border-1);
5-
border-top: 1px solid var(--main-border-1);
6-
width: 100%;
7-
text-align: center;
8-
background: var(--editor-menu-background);
9-
color: var(--light-grey-6);
10-
}
11-
12-
.translationform + .tm-source {
13-
background: var(--editor-form-background);
14-
}
15-
16-
.dark-theme[data-editor-theme='dark'] .singlefield ~ .tm-source,
17-
.light-theme[data-editor-theme='light'] .singlefield ~ .tm-source,
18-
[data-editor-theme='match'] .singlefield ~ .tm-source {
19-
background: var(--editor-background);
8+
line-height: 20px;
9+
margin-left: 5px;
10+
padding: 9px;
2011
}
2112

2213
.tm-source .stress {
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import React from 'react';
2+
import { render } from '@testing-library/react';
3+
import { describe, expect, it } from 'vitest';
4+
5+
import { EditorData } from '~/context/Editor';
6+
import { MockLocalizationProvider } from '~/test/utils';
7+
8+
import { MachinerySourceIndicator } from './MachinerySourceIndicator';
9+
10+
const field = (value) => ({
11+
id: '',
12+
name: '',
13+
keys: [],
14+
labels: [],
15+
handle: { current: { value } },
16+
});
17+
18+
const mount = (editor) =>
19+
render(
20+
<MockLocalizationProvider
21+
resources={[
22+
`editor-MachinerySourceIndicator--match = <stress>100%</stress> MATCH
23+
.title = 100% Translation Memory match`,
24+
]}
25+
>
26+
<EditorData.Provider
27+
value={{
28+
fields: [field('Bonjour')],
29+
machinery: { manual: false, sources: [], translation: 'Bonjour' },
30+
sourceView: false,
31+
...editor,
32+
}}
33+
>
34+
<MachinerySourceIndicator />
35+
</EditorData.Provider>
36+
</MockLocalizationProvider>,
37+
);
38+
39+
describe('<MachinerySourceIndicator>', () => {
40+
it('shows for content that was filled in automatically', () => {
41+
const { container } = mount();
42+
43+
const indicator = container.querySelector('.tm-source');
44+
expect(indicator).not.toBeNull();
45+
expect(indicator.textContent).toContain('100%');
46+
expect(indicator.getAttribute('title')).toBeTruthy();
47+
});
48+
49+
it('shows nothing for a manual copy', () => {
50+
const { container } = mount({
51+
machinery: { manual: true, sources: [], translation: 'Bonjour' },
52+
});
53+
54+
expect(container.querySelector('.tm-source')).toBeNull();
55+
});
56+
57+
it('shows nothing once the filled-in content has been edited', () => {
58+
const { container } = mount({ fields: [field('Bonjour !')] });
59+
60+
expect(container.querySelector('.tm-source')).toBeNull();
61+
});
62+
});

translate/src/modules/editor/components/MachinerySourceIndicator.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ export function MachinerySourceIndicator() {
2222

2323
return (
2424
<Localized
25-
id='editor-MachinerySourceIndicator--text'
25+
id='editor-MachinerySourceIndicator--match'
26+
attrs={{ title: true }}
2627
elems={{ stress: <span className='stress' /> }}
2728
>
28-
<div className='tm-source'>
29-
{'<stress>100%</stress> MATCH FROM TRANSLATION MEMORY'}
29+
<div className='tm-source' title='100% Translation Memory match'>
30+
{'<stress>100%</stress> MATCH'}
3031
</div>
3132
</Localized>
3233
);

0 commit comments

Comments
 (0)