Skip to content

Commit 4de7f43

Browse files
committed
Add docstrings
1 parent 58f00cb commit 4de7f43

File tree

1 file changed

+67
-0
lines changed
  • fluent.syntax/src/main/kotlin/org/projectfluent/syntax/processor

1 file changed

+67
-0
lines changed

fluent.syntax/src/main/kotlin/org/projectfluent/syntax/processor/Processor.kt

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,53 @@ private val special =
88

99
/**
1010
* Processor for transforming patterns.
11+
*
12+
* This class can be used to transform patterns in a way that is friendly
13+
* to localization workflows which want to allow text characters which are
14+
* special in Fluent to be written as regular text.
15+
*
16+
* According to the Fluent syntax, characters like the curly braces must be
17+
* enclosed in StringLiterals if they are supposed to be part of the
18+
* translation content. Otherwise, an open curly brace would start a Placeable
19+
* and likely lead to a syntax error.
20+
*
21+
* Workflows in which the support for Fluent placeables is limited may choose
22+
* to provide their own visual cues for them. This often comes in form of
23+
* visual placeholders which can be rearranged within a translation
24+
* segment by the translator, but whose contents cannot be modified.
25+
*
26+
* In these workflows, the special meaning of the character like the curly
27+
* braces is void; the translator is not able to insert new placeables by
28+
* opening a curly brace anyways. Thus, for translators' convenience, the
29+
* curly brace can be treated as a regular text character and part of the
30+
* translation content.
31+
*
32+
* The Processor's methods allow baking StringLiterals into TextElements, and
33+
* then "un-baking" them again if required by the Fluent syntax. Note that
34+
* all StringLiterals are baked, while only some are un-baked. The Processor
35+
* is lossy.
1136
*/
1237
class Processor {
38+
/**
39+
* "Bake" the values of StringLiterals into TextElements. This is a lossy
40+
* transformation for literals which are not special in Fluent syntax.
41+
*
42+
* Examples:
43+
*
44+
* →Hello, {"{-_-}"}.
45+
* ←Hello, {-_-}.
46+
*
47+
* →{" "}Hello, world!
48+
* ← Hello, world!
49+
*
50+
* →A multiline pattern:
51+
* {"*"} Asterisk is special
52+
* ←A multiline pattern:
53+
* * Asterisk is special
54+
*
55+
* →Copyright {"\u00A9"} 2020
56+
* ←Copyright © 2020
57+
*/
1358
fun unescapeLiteralsToText(pattern: Pattern): Pattern {
1459
val result = Pattern()
1560
for (elem in textFromLiterals(pattern)) {
@@ -18,6 +63,28 @@ class Processor {
1863
return result
1964
}
2065

66+
/**
67+
* "Un-bake" special characters into StringLiterals, which would otherwise
68+
* cause syntax errors with Fluent parsers. Character sequences which might
69+
* have been previously enclosed in StringLiterals, will not be un-baked,
70+
* provided they are valid text characters in Fluent syntax.
71+
*
72+
* Examples:
73+
*
74+
* →Hello, {-_-}.
75+
* ←Hello, {"{"}-_-{"}"}.
76+
*
77+
* → Hello, world!
78+
* ←{""} Hello, world!
79+
*
80+
* →A multiline pattern:
81+
* * Asterisk is special
82+
* ←A multiline pattern:
83+
* {"*"} Asterisk is special
84+
*
85+
* →Copyright © 2020
86+
* ←Copyright © 2020
87+
*/
2188
fun escapeTextToLiterals(pattern: Pattern): Pattern {
2289
val result = Pattern()
2390
for (elem in literalsFromText(pattern)) {

0 commit comments

Comments
 (0)