updated fluent to 0.8
This commit is contained in:
parent
59224516b7
commit
7c6aabc388
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue