From 2559d1c0e869e3af8d9dec790c5694fbcf68a061 Mon Sep 17 00:00:00 2001 From: Vinh Date: Thu, 12 Sep 2019 23:10:17 +0700 Subject: [PATCH] fix: turn off bidi characters in favor of tags (#2557) --- src/core/client/framework/lib/i18n/generateBundles.ts | 5 ++++- src/core/client/framework/testHelpers/createFluentBundle.ts | 6 +++--- src/core/server/services/i18n/index.ts | 6 +++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/core/client/framework/lib/i18n/generateBundles.ts b/src/core/client/framework/lib/i18n/generateBundles.ts index ea3679e27..d5c2fe262 100644 --- a/src/core/client/framework/lib/i18n/generateBundles.ts +++ b/src/core/client/framework/lib/i18n/generateBundles.ts @@ -44,7 +44,10 @@ export default async function generateBundles( const promises = []; for (const locale of locales) { - const bundle = new FluentBundle(locale, { functions }); + // `useIsolating: false` will remove bidi characters. + // https://github.com/projectfluent/fluent.js/wiki/Unicode-Isolation + // We should be able to use `` tags instead to support rtl languages. + const bundle = new FluentBundle(locale, { functions, useIsolating: false }); if (locale in data.bundled) { bundle.addMessages(data.bundled[locale]); promises.push(decorateWarnMissing(bundle)); diff --git a/src/core/client/framework/testHelpers/createFluentBundle.ts b/src/core/client/framework/testHelpers/createFluentBundle.ts index 8dcb0eefc..0aacf6626 100644 --- a/src/core/client/framework/testHelpers/createFluentBundle.ts +++ b/src/core/client/framework/testHelpers/createFluentBundle.ts @@ -38,9 +38,9 @@ function createFluentBundle( target: string, pathToLocale: string ): FluentBundle { - // `useIsolating: false` will remove bidi characterse. - // See https://github.com/projectfluent/fluent.js/commit/41e5445d2e399f090306c5b9a084bcce5111bbd3 - // And https://www.w3.org/International/questions/qa-bidi-unicode-controls + // `useIsolating: false` will remove bidi characters. + // https://github.com/projectfluent/fluent.js/wiki/Unicode-Isolation + // We should be able to use `` tags instead to support rtl languages. const bundle = new FluentBundle("en-US", { functions, useIsolating: false }); const files = fs.readdirSync(pathToLocale); const prefixes = commonPrefixes.concat(target); diff --git a/src/core/server/services/i18n/index.ts b/src/core/server/services/i18n/index.ts index a2248f2ef..d048ccee1 100644 --- a/src/core/server/services/i18n/index.ts +++ b/src/core/server/services/i18n/index.ts @@ -49,7 +49,11 @@ export class I18n { // Now we have a language code. const bundle: FluentBundle = - this.bundles[locale] || new FluentBundle(locale); + // `useIsolating: false` will remove bidi characters. + // https://github.com/projectfluent/fluent.js/wiki/Unicode-Isolation + // We should be able to use `` tags instead to support rtl languages. + this.bundles[locale] || + new FluentBundle(locale, { useIsolating: false }); // Load all the translations in the folder. const files = await fs.readdir(path.join(localesFolder, folder));