Skip to content

Commit 1ee9083

Browse files
committed
Unalias FluentMessage, FluentAttribute, FluentAttributes
1 parent 3a370af commit 1ee9083

File tree

11 files changed

+35
-48
lines changed

11 files changed

+35
-48
lines changed

frontend/src/core/editor/actions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import * as unsavedchanges from 'modules/unsavedchanges';
1313

1414
import type { Entity, SourceType } from 'core/api';
1515
import type { Locale } from 'core/locale';
16-
import type { FluentMessage } from 'core/utils/fluent/types';
16+
import type { Entry } from '@fluent/syntax';
1717

1818
export const END_UPDATE_TRANSLATION: 'editor/END_UPDATE_TRANSLATION' =
1919
'editor/END_UPDATE_TRANSLATION';
@@ -40,7 +40,7 @@ export const UPDATE_SELECTION: 'editor/UPDATE_SELECTION' =
4040
export const UPDATE_MACHINERY_SOURCES: 'editor/UPDATE_MACHINERY_SOURCES' =
4141
'editor/UPDATE_MACHINERY_SOURCES';
4242

43-
export type Translation = string | FluentMessage;
43+
export type Translation = string | Entry;
4444

4545
/**
4646
* Update the current translation of the selected entity.

frontend/src/core/utils/fluent/convertSyntax.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import getSimplePreview from './getSimplePreview';
77
import parser from './parser';
88
import serializer from './serializer';
99

10-
import type { FluentMessage } from './types';
10+
import type { Entry } from '@fluent/syntax';
1111
import type { Locale } from 'core/locale';
1212

1313
type SyntaxType = 'simple' | 'rich' | 'complex' | '';
@@ -60,7 +60,7 @@ export function getRichFromComplex(
6060
original: string,
6161
initial: string,
6262
locale: Locale,
63-
): [FluentMessage, FluentMessage] {
63+
): [Entry, Entry] {
6464
let translationContent = parser.parseEntry(current);
6565

6666
// If the parsed content is invalid, create an empty message instead.
@@ -87,7 +87,7 @@ export function getRichFromComplex(
8787
}
8888

8989
export function getComplexFromRich(
90-
current: FluentMessage,
90+
current: Entry,
9191
original: string,
9292
initial: string,
9393
locale: Locale,
@@ -114,21 +114,21 @@ export function getComplexFromRich(
114114
*
115115
* @param {string} fromSyntax Syntax of the current translation.
116116
* @param {string} toSyntax Expected syntax of the output.
117-
* @param {string | FluentMessage} current Current content of the translation, as entered by the user.
117+
* @param {string | Entry} current Current content of the translation, as entered by the user.
118118
* @param {string} original Original string of the entity.
119119
* @param {string} initial Currently active translation, if any.
120120
* @param {Locale} locale Current locale.
121121
*
122-
* @returns {[ string | FluentMessage, string ]} The converted current translation and initial translation.
122+
* @returns {[ string | Entry, string ]} The converted current translation and initial translation.
123123
*/
124124
export default function convertSyntax(
125125
fromSyntax: SyntaxType,
126126
toSyntax: SyntaxType,
127-
current: string | FluentMessage,
127+
current: string | Entry,
128128
original: string,
129129
initial: string,
130130
locale: Locale,
131-
): [FluentMessage, FluentMessage] | [string, string] {
131+
): [Entry, Entry] | [string, string] {
132132
if (
133133
fromSyntax === 'complex' &&
134134
toSyntax === 'simple' &&

frontend/src/core/utils/fluent/flattenMessage.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
import flattenPatternElements from './flattenPatternElements';
44

5-
import type { FluentMessage } from './types';
5+
import type { Entry } from '@fluent/syntax';
66

77
/**
88
* Return a flattened Fluent message.
99
*
1010
* Takes a Fluent message and returns a copy with flattened value and
1111
* attributes elements.
1212
*
13-
* @param {FluentMessage} message A Fluent message to flatten.
13+
* @param {Entry} message A Fluent message to flatten.
1414
*
15-
* @returns {FluentMessage} A copy of the given Fluent message with flattened
15+
* @returns {Entry} A copy of the given Fluent message with flattened
1616
* value and attributes elements.
1717
*/
18-
export default function flattenMessage(message: FluentMessage): FluentMessage {
18+
export default function flattenMessage(message: Entry): Entry {
1919
const flatMessage = message.clone();
2020
if (flatMessage.type !== 'Message' && flatMessage.type !== 'Term') {
2121
return flatMessage;

frontend/src/core/utils/fluent/getEmptyMessage.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import isPluralExpression from './isPluralExpression';
1313

1414
import { CLDR_PLURALS } from 'core/plural';
1515

16-
import type { FluentMessage } from './types';
16+
import type { Entry } from '@fluent/syntax';
1717
import type { Locale } from 'core/locale';
1818

1919
/**
@@ -78,13 +78,10 @@ function withDefaultVariant(variants: Array<Variant>): Array<Variant> {
7878
* Note that this produces "junk" Fluent messages. Serializing the AST works,
7979
* but parsing it afterwards will result in a Junk message.
8080
*
81-
* @param {FluentMessage} source A Fluent AST to empty.
82-
* @returns {FluentMessage} An emptied copy of the source.
81+
* @param {Entry} source A Fluent AST to empty.
82+
* @returns {Entry} An emptied copy of the source.
8383
*/
84-
export default function getEmptyMessage(
85-
source: FluentMessage,
86-
locale: Locale,
87-
): FluentMessage {
84+
export default function getEmptyMessage(source: Entry, locale: Locale): Entry {
8885
class EmptyTransformer extends Transformer {
8986
// Empty Text Elements
9087
visitTextElement(node: TextElement): TextElement {
@@ -119,5 +116,5 @@ export default function getEmptyMessage(
119116

120117
// Empty TextElements
121118
const transformer = new EmptyTransformer();
122-
return ((transformer.visit(flatMessage): any): FluentMessage);
119+
return ((transformer.visit(flatMessage): any): Entry);
123120
}

frontend/src/core/utils/fluent/getReconstructedMessage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import parser from './parser';
44

5-
import type { FluentMessage } from './types';
5+
import type { Entry } from '@fluent/syntax';
66

77
/**
88
* Return a reconstructed Fluent message from the original message and some
@@ -11,7 +11,7 @@ import type { FluentMessage } from './types';
1111
export default function getReconstructedMessage(
1212
original: string,
1313
translation: string,
14-
): FluentMessage {
14+
): Entry {
1515
const message = parser.parseEntry(original);
1616
if (message.type !== 'Message' && message.type !== 'Term') {
1717
throw new Error(

frontend/src/core/utils/fluent/getSyntaxType.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@ import isSimpleMessage from './isSimpleMessage';
44
import isSimpleSingleAttributeMessage from './isSimpleSingleAttributeMessage';
55
import isSupportedMessage from './isSupportedMessage';
66

7-
import type { FluentMessage, SyntaxType } from './types';
7+
import type { SyntaxType } from './types';
8+
import type { Entry } from '@fluent/syntax';
89

910
/**
1011
* Return the syntax type of a given Fluent message.
1112
*
12-
* @param {FluentMessage} message A Fluent message (AST) to analyze.
13+
* @param {Entry} message A Fluent message (AST) to analyze.
1314
*
1415
* @returns {string} The syntax type of the Fluent message. Can be one of:
1516
* - "simple": can be shown as a simple string in generic editor;
1617
* - "rich": can be shown in a rich editor;
1718
* - "complex": can only be shown in a source editor.
1819
*/
19-
export default function getSyntaxType(message: FluentMessage): SyntaxType {
20+
export default function getSyntaxType(message: Entry): SyntaxType {
2021
if (!isSupportedMessage(message)) {
2122
return 'complex';
2223
}

frontend/src/core/utils/fluent/isSimpleSingleAttributeMessage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/* @flow */
22

33
import isSimpleElement from './isSimpleElement';
4-
import type { FluentMessage } from './types';
4+
import type { Entry } from '@fluent/syntax';
55

66
/**
77
* Return true when message has no value and a single attribute with only simple
88
* elements.
99
*/
1010
export default function isSimpleSingleAttributeMessage(
11-
message: FluentMessage,
11+
message: Entry,
1212
): boolean {
1313
if (
1414
message.type === 'Message' &&

frontend/src/core/utils/fluent/types.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
/* @flow */
22

3-
import type { Attribute, Entry } from '@fluent/syntax';
4-
5-
export type FluentAttribute = Attribute;
6-
7-
export type FluentAttributes = Array<FluentAttribute>;
8-
9-
export type FluentMessage = Entry;
10-
113
// Type of syntax of the translation to show in the editor.
124
// `simple` => SimpleEditor (the message can be simplified to a single text element)
135
// `rich` => RichEditor (the message can be displayed in our rich interface)

frontend/src/modules/fluenteditor/components/FluentEditor.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import * as entities from 'core/entities';
1010
import * as notification from 'core/notification';
1111
import * as plural from 'core/plural';
1212
import { fluent } from 'core/utils';
13-
import type { FluentMessage, SyntaxType } from 'core/utils/fluent/types';
13+
import type { SyntaxType } from 'core/utils/fluent/types';
14+
import type { Entry } from '@fluent/syntax';
1415

1516
import SourceEditor from './source/SourceEditor';
1617
import SimpleEditor from './simple/SimpleEditor';
@@ -81,7 +82,7 @@ function useLoadTranslation(forceSource) {
8182
activeTranslationString || entity.original,
8283
);
8384

84-
let translationContent: string | FluentMessage = '';
85+
let translationContent: string | Entry = '';
8586
if (syntax === 'complex') {
8687
// Use the actual content that we get from the server: a Fluent message as a string.
8788
translationContent = activeTranslationString;

frontend/src/modules/fluenteditor/components/rich/RichTranslationForm.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { CLDR_PLURALS } from 'core/plural';
1414
import { fluent } from 'core/utils';
1515

1616
import type { Translation } from 'core/editor';
17-
import type { FluentAttributes, FluentMessage } from 'core/utils/fluent/types';
17+
import type { Attribute, Entry } from '@fluent/syntax';
1818
import type {
1919
Pattern,
2020
PatternElement,
@@ -30,7 +30,7 @@ type Child = SyntaxNode | Array<SyntaxNode>;
3030
* value.
3131
*/
3232
function getUpdatedTranslation(
33-
translation: FluentMessage,
33+
translation: Entry,
3434
value: string,
3535
path: MessagePath,
3636
) {
@@ -483,7 +483,7 @@ export default function RichTranslationForm(
483483
}
484484

485485
function renderAttributes(
486-
attributes: ?FluentAttributes,
486+
attributes: ?Array<Attribute>,
487487
path: MessagePath,
488488
) {
489489
if (!attributes) {

0 commit comments

Comments
 (0)