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 = '