updated fluent to 0.8

This commit is contained in:
Danny Coates 2018-09-04 13:30:11 -07:00
parent 59224516b7
commit 7c6aabc388
No known key found for this signature in database
GPG key ID: 4C442633C62E00CB
4 changed files with 15 additions and 15 deletions

View file

@ -1,4 +1,4 @@
const { MessageContext } = require('fluent');
const { FluentBundle } = require('fluent');
const fs = require('fs');
function toJSON(map) {
@ -26,10 +26,10 @@ module.exports = function(source) {
require.resolve('../public/locales/en-US/send.ftl'),
'utf8'
);
const en = new MessageContext('en-US');
const en = new FluentBundle('en-US');
en.addMessages(en_ftl);
// pre-parse the ftl
const context = new MessageContext(locale);
const context = new FluentBundle(locale);
context.addMessages(source);
const merged = merge(en._messages, context._messages);
@ -39,14 +39,14 @@ if (typeof window === 'undefined') {
var fluent = require('fluent');
}
(function () {
var ctx = new fluent.MessageContext('${locale}', {useIsolating: false});
ctx._messages = new Map(${toJSON(merged)});
var bundle = new fluent.FluentBundle('${locale}', {useIsolating: false});
bundle._messages = new Map(${toJSON(merged)});
function translate(id, data) {
var msg = ctx.getMessage(id);
var msg = bundle.getMessage(id);
if (typeof(msg) !== 'string' && !msg.val && msg.attrs) {
msg = msg.attrs.title || msg.attrs.alt
}
return ctx.format(msg, data);
return bundle.format(msg, data);
}
if (typeof window === 'undefined') {
module.exports = translate;