mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-27 04:38:02 +00:00
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:
parent
25d89ec12e
commit
489d8a2762
@ -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
1864
intl/l10n/MessageContext.jsm
Normal file
File diff suppressed because it is too large
Load Diff
13
intl/l10n/moz.build
Normal file
13
intl/l10n/moz.build
Normal 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'
|
39
intl/l10n/test/test_messagecontext.js
Normal file
39
intl/l10n/test/test_messagecontext.js
Normal 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);
|
||||
}
|
4
intl/l10n/test/xpcshell.ini
Normal file
4
intl/l10n/test/xpcshell.ini
Normal file
@ -0,0 +1,4 @@
|
||||
[DEFAULT]
|
||||
head =
|
||||
|
||||
[test_messagecontext.js]
|
@ -16,6 +16,7 @@ DIRS += [
|
||||
'lwbrk',
|
||||
'strres',
|
||||
'unicharutil',
|
||||
'l10n',
|
||||
]
|
||||
|
||||
DIRS += [
|
||||
|
Loading…
x
Reference in New Issue
Block a user