24
1
Fork 0

Update fluent

This commit is contained in:
AaronDewes 2022-07-26 11:03:10 +00:00
parent 000854104f
commit 44a25e4156
4 changed files with 22789 additions and 47 deletions

View File

@ -1,8 +1,8 @@
import { FluentBundle } from '@fluent/bundle';
import { FluentBundle, FluentResource } from '@fluent/bundle';
function makeBundle(locale, ftl) {
const bundle = new FluentBundle(locale, { useIsolating: false });
bundle.addMessages(ftl);
bundle.addResource(new FluentResource(ftl));
return bundle;
}
@ -19,7 +19,7 @@ export async function getTranslator(locale) {
return function(id, data) {
for (let bundle of bundles) {
if (bundle.hasMessage(id)) {
return bundle.format(bundle.getMessage(id), data);
return bundle.formatPattern(bundle.getMessage(id).value, data);
}
}
};

22811
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -131,8 +131,8 @@
},
"dependencies": {
"@dannycoates/express-ws": "^5.0.3",
"@fluent/bundle": "^0.13.0",
"@fluent/langneg": "^0.3.0",
"@fluent/bundle": "^0.17.1",
"@fluent/langneg": "^0.6.2",
"@google-cloud/storage": "^5.19.0",
"@sentry/node": "^5.30.0",
"aws-sdk": "^2.1109.0",

View File

@ -1,13 +1,15 @@
const fs = require('fs');
const path = require('path');
const { FluentBundle } = require('@fluent/bundle');
const { FluentBundle, FluentResource } = require('@fluent/bundle');
const localesPath = path.resolve(__dirname, '../public/locales');
const locales = fs.readdirSync(localesPath);
function makeBundle(locale) {
const bundle = new FluentBundle(locale, { useIsolating: false });
bundle.addMessages(
fs.readFileSync(path.resolve(localesPath, locale, 'send.ftl'), 'utf8')
bundle.addResource(
new FluentResource(
fs.readFileSync(path.resolve(localesPath, locale, 'send.ftl'), 'utf8')
)
);
return [locale, bundle];
}
@ -19,8 +21,11 @@ module.exports = function getTranslator(locale) {
const bundle = bundles.get(locale) || defaultBundle;
return function(id, data) {
if (bundle.hasMessage(id)) {
return bundle.format(bundle.getMessage(id), data);
return bundle.formatPattern(bundle.getMessage(id).value, data);
}
return defaultBundle.format(defaultBundle.getMessage(id), data);
return defaultBundle.formatPattern(
defaultBundle.getMessage(id).value,
data
);
};
};