Closed Bug 1374246 Opened 7 years ago Closed 6 years ago

fluent.migrate: Support leading and trailing whitespace

Categories

(Localization Infrastructure and Tools :: Fluent Migration, enhancement)

enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: stas, Assigned: stas)

Details

In cases when the legacy translation has leading or trailing whitespace, the migration transforms should automatically encode it with a special placeable.

    "   Foo"

can become

    {""}   Foo

or

    {"   "}Foo
Do you have stats on how often does it happen and how often is it intentional? Maybe we shouldn't really do this if it's always unintentional. Or maybe we should reconsider FTL syntax for this feature if there are legitimate use cases...
I don't have any precise data on how often this is used. I assume this is most useful for putting text around DOM elements—something that Fluent solves in a more elegant manner with DOM overlays. For this case, the migration code and the serialization actually work well because the whitespace is only considered leading/trailing in the legacy translation; it ends up being inside of the translation in the migrated Fluent message.

To fix this, we'd need to add code to CONCAT which detects leading/trailing whitespace in the first and the last element and converts it to {""}.
> To fix this, we'd need to add code to CONCAT which detects leading/trailing whitespace in the first and the last element and converts it to {""}.

Correction: this should go into Transform.pattern_of. CONCAT should then reinsert whitespace-only StringExpressions not at the extreme positions back into the adjacent TextElements.
I ended up fixing this as part of https://github.com/projectfluent/python-fluent/commit/6e14e772c973f54a7692bcfbd2a8932107e8c8b5.
Assignee: nobody → stas
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
No longer blocks: fluent.migrate
Component: Python Library → Fluent Migration
Product: L20n → Localization Infrastructure and Tools
You need to log in before you can comment on or make changes to this bug.