Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Set useIsolating option for Fluent bundles. (#4863)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenba committed Oct 3, 2018
1 parent 626f1a8 commit c672f89
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
15 changes: 11 additions & 4 deletions server/src/l10n.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,19 @@ exports.init = function(localeStringMap) {
return initPromise;
};

exports.getText = function(locales) {
exports.getText = function(locales, userAgent) {
const bundles = {};
const availableLocales = exports.getUserLocales(locales);

// This is a temporary fix for https://github.com/mozilla-services/screenshots/issues/4863
// to be reverted in https://github.com/mozilla-services/screenshots/issues/4993
let useIsolating = true;
if (userAgent && userAgent.includes("Win")) {
useIsolating = false;
}

availableLocales.forEach((locale) => {
bundles[locale] = getFluentBundle(locale);
bundles[locale] = getFluentBundle(locale, useIsolating);
});

return function(l10nID, args) {
Expand Down Expand Up @@ -92,9 +99,9 @@ function useLocaleData(localeStringMap) {
return initPromise;
}

function getFluentBundle(locale) {
function getFluentBundle(locale, useIsolating) {
if (!fluentBundles[locale]) {
const bundle = new FluentBundle(locale);
const bundle = new FluentBundle(locale, {useIsolating});
bundle.addMessages(rawStrings[locale]);
fluentBundles[locale] = bundle;
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/middleware/l10n.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exports.getLanguages = function(req) {
exports.l10n = function(req, res, next) {
l10n.init().then(() => {
const languages = exports.getLanguages(req);
req.getText = l10n.getText(languages);
req.getText = l10n.getText(languages, req.headers["user-agent"]);
req.userLocales = l10n.getUserLocales(languages);
req.messages = l10n.getStrings(languages);
next();
Expand Down
10 changes: 6 additions & 4 deletions server/src/reactruntime.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ require("fluent-intl-polyfill/compat");
const { FluentBundle } = require("fluent/compat");
const { LocalizationProvider } = require("fluent-react/compat");
const { getLocaleMessages } = require("./locale-messages");
const bundles = [];

function generateBundles(messages, locales) {
const bundles = [];
for (const locale of locales) {
const bundle = new FluentBundle(locale);
bundle.addMessages(messages[locale]);
bundles.push(bundle);
if (!messages[locale]) {
const bundle = new FluentBundle(locale);
bundle.addMessages(messages[locale]);
bundles.push(bundle);
}
}
return bundles;
}
Expand Down

0 comments on commit c672f89

Please sign in to comment.