Skip to content

Commit

Permalink
updated fluent to 0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
dannycoates committed Sep 4, 2018
1 parent 5922451 commit 7c6aabc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions build/fluent_loader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { MessageContext } = require('fluent');
const { FluentBundle } = require('fluent');
const fs = require('fs');

function toJSON(map) {
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion docs/localization.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 7c6aabc

Please sign in to comment.