From b76c53a78ef6d867a22aeb0f4c1970acd092e38b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matja=C5=BE=20Horvat?= Date: Tue, 13 Feb 2018 17:38:43 +0100 Subject: [PATCH] Update to fluent libraries to 0.6.2 (#840) Includes: * Switch to PyPI install * Support for Terms (treated same as Messages) * Support for GroupComments as a replacement for Section comments * Remove reference to Tags * Reflect the introduction of type Placeable * Replace serializeExpression() with fluentSerializer.serializeExpression() * Use `isinstance` instead of `type` * Factor out isSelectExpressionElement() * In unsaved changes check, if translation cannot be parsed, return source editor value * If no textarea has focus, select first * Add check for matching Message keys * runChecks() as a standalone function * Run checks when switching from source view to rich mode * Properly render multiple selectors --- pontoon/base/static/js/fluent_interface.js | 258 ++-- pontoon/base/static/js/lib/fluent-syntax.js | 1237 +++++++++++-------- pontoon/base/static/js/translate.js | 2 +- pontoon/base/templatetags/helpers.py | 12 +- pontoon/sync/formats/ftl.py | 17 +- requirements.txt | 4 +- 6 files changed, 912 insertions(+), 618 deletions(-) diff --git a/pontoon/base/static/js/fluent_interface.js b/pontoon/base/static/js/fluent_interface.js index a90ea6b97..6ae402035 100644 --- a/pontoon/base/static/js/fluent_interface.js +++ b/pontoon/base/static/js/fluent_interface.js @@ -1,30 +1,9 @@ /* global FluentSyntax */ +var fluentParser = new FluentSyntax.FluentParser({ withSpans: false }); +var fluentSerializer = new FluentSyntax.FluentSerializer(); /* Public functions used across different files */ var Pontoon = (function (my) { - var fluentParser = new FluentSyntax.FluentParser({ withSpans: false }); - var fluentSerializer = new FluentSyntax.FluentSerializer(); - - // TODO: Replace with fluentSerializer.serializeExpression() on fluent.js 0.6 update - function serializeExpression(expression) { - switch (expression.type) { - case 'MessageReference': - return expression.id.name; - case 'ExternalArgument': - return '$' + expression.id.name; - case 'NumberExpression': - return expression.value || expression.val.value; - case 'StringExpression': - return '"' + (expression.value || expression.val.value) + '"'; - case 'NamedArgument': - return expression.name.name + ': ' + serializeExpression(expression.val); - case 'CallExpression': - var args = expression.args.map(function (arg) { - return serializeExpression(arg); - }); - return expression.callee.name + '(' + args.join(', ') + ')'; - } - } /* * Render original string element: simple string value or a variant. @@ -103,8 +82,8 @@ var Pontoon = (function (my) { } // Render SelectExpression - if (element.type === 'SelectExpression') { - element.variants.forEach(function (item) { + if (Pontoon.fluent.isSelectExpressionElement(element)) { + element.expression.variants.forEach(function (item) { content += renderOriginalElement(item.key.value || item.key.name, item.value.elements); }); } @@ -139,9 +118,9 @@ var Pontoon = (function (my) { } // Render SelectExpression - if (element.type === 'SelectExpression') { - var expression = serializeExpression(element.expression); - content = '