From 7c6aabc388486f53abe6049ecaf53b23d4f46b8e Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Tue, 4 Sep 2018 13:30:11 -0700 Subject: [PATCH] updated fluent to 0.8 --- build/fluent_loader.js | 14 +++++++------- docs/localization.md | 2 +- package-lock.json | 12 ++++++------ package.json | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/build/fluent_loader.js b/build/fluent_loader.js index a9027d15..1630dfe6 100644 --- a/build/fluent_loader.js +++ b/build/fluent_loader.js @@ -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; diff --git a/docs/localization.md b/docs/localization.md index ad9072e1..779210ae 100644 --- a/docs/localization.md +++ b/docs/localization.md @@ -14,7 +14,7 @@ The development environment includes all locales in `public/locales` via the `L1 ## Code -In `app/` we use the `state.translate()` function to translate strings to the best matching language base on the user's `Accept-Language` header. It's a wrapper around fluent's [MessageContext.format](http://projectfluent.org/fluent.js/fluent/MessageContext.html). It works the same for both server and client side rendering. +In `app/` we use the `state.translate()` function to translate strings to the best matching language base on the user's `Accept-Language` header. It's a wrapper around fluent's [FluentBundle.format](http://projectfluent.org/fluent.js/fluent/FluentBundle.html). It works the same for both server and client side rendering. ### Examples diff --git a/package-lock.json b/package-lock.json index 6ebc3563..31b3a1f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2481,7 +2481,7 @@ }, "buffer": { "version": "4.9.1", - "resolved": "http://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.1.tgz", "integrity": "sha1-bRu2AbB6TvztlwlBMgkwJ8lbwpg=", "requires": { "base64-js": "^1.0.2", @@ -5351,9 +5351,9 @@ "dev": true }, "fluent": { - "version": "0.6.4", - "resolved": "https://registry.npmjs.org/fluent/-/fluent-0.6.4.tgz", - "integrity": "sha512-EXfMJmnGbUgaIC1myIzDk5akAF6+1JrI7KVnNCba2ou7WCKc/2CWa8QshfhImVtettOvEs0z0UVdMrS6zX7pxA==" + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/fluent/-/fluent-0.8.0.tgz", + "integrity": "sha512-bZfthhubEH1lKgGIi0fIDeNkZrfEOu3MrLbi284LdxNG+9Q5gq2KsuoocumqNPStVtWo3S3/1p8RIqd34u3Mzw==" }, "fluent-intl-polyfill": { "version": "0.1.0", @@ -6282,7 +6282,7 @@ "dependencies": { "minimist": { "version": "1.1.3", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.1.3.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.1.3.tgz", "integrity": "sha1-O+39kaktOQFvz6ocaB6Pqhoe/ag=", "dev": true } @@ -13845,7 +13845,7 @@ }, "sax": { "version": "1.2.1", - "resolved": "http://registry.npmjs.org/sax/-/sax-1.2.1.tgz", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.1.tgz", "integrity": "sha1-e45lYZCyKOgaZq6nSEgNgozS03o=" }, "schema-utils": { diff --git a/package.json b/package.json index baadd77f..aeabd7fc 100644 --- a/package.json +++ b/package.json @@ -126,7 +126,7 @@ "convict": "^4.3.2", "express": "^4.16.3", "express-ws": "^4.0.0", - "fluent": "^0.6.4", + "fluent": "^0.8.0", "fluent-langneg": "^0.1.0", "helmet": "^3.13.0", "mkdirp": "^0.5.1",