Bug 1347801 - Land Fluent MessageContext (Parser, Resolver, Context). r=mossop

This patch lands the core of the new localization API:
 * Parser for the Fluent syntax called "FTL"
 * Resolver for the Fluent logic
 * MessageContext class which is a central class for storing and operating
   on Fluent messages.

MozReview-Commit-ID: E7nKGsLOCJe

--HG--
extra : rebase_source : 893178263744ef6cf6e64c135d28e10a53b61a19
This commit is contained in:
Zibi Braniecki 2017-06-02 10:35:15 +02:00
parent 25d89ec12e
commit 489d8a2762
6 changed files with 1924 additions and 0 deletions

View File

@ -121,6 +121,9 @@ var whitelist = [
// Needed by Normandy
{file: "resource://gre/modules/IndexedDB.jsm"},
// New L10n API that is not yet used in production
{file: "resource://gre/modules/MessageContext.jsm"},
// Starting from here, files in the whitelist are bugs that need fixing.
// Bug 1339420
{file: "chrome://branding/content/icon128.png"},

1864
intl/l10n/MessageContext.jsm Normal file

File diff suppressed because it is too large Load Diff

13
intl/l10n/moz.build Normal file
View File

@ -0,0 +1,13 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
EXTRA_JS_MODULES += [
'MessageContext.jsm',
]
XPCSHELL_TESTS_MANIFESTS += ['test/xpcshell.ini']
FINAL_LIBRARY = 'xul'

View File

@ -0,0 +1,39 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
function run_test() {
const { MessageContext } = Components.utils.import("resource://gre/modules/MessageContext.jsm", {});
test_methods_presence(MessageContext);
test_methods_calling(MessageContext);
ok(true);
}
function test_methods_presence(MessageContext) {
const ctx = new MessageContext(["en-US", "pl"]);
equal(typeof ctx.addMessages, "function");
equal(typeof ctx.format, "function");
equal(typeof ctx.formatToParts, "function");
}
function test_methods_calling(MessageContext) {
const ctx = new MessageContext(["en-US", "pl"], {
useIsolating: false
});
ctx.addMessages("key = Value");
const msg = ctx.getMessage("key");
equal(ctx.format(msg), "Value");
deepEqual(ctx.formatToParts(msg), ["Value"]);
ctx.addMessages("key2 = Hello { $name }");
const msg2 = ctx.getMessage("key2");
equal(ctx.format(msg2, { name: "Amy" }), "Hello Amy");
deepEqual(ctx.formatToParts(msg2), ["Hello ", {
value: "name",
opts: undefined
}]);
ok(true);
}

View File

@ -0,0 +1,4 @@
[DEFAULT]
head =
[test_messagecontext.js]

View File

@ -16,6 +16,7 @@ DIRS += [
'lwbrk',
'strres',
'unicharutil',
'l10n',
]
DIRS += [