mirror of
https://github.com/wassname/talk.git
synced 2026-08-11 11:27:10 +08:00
[CORL-800] Fluent Upgrade (#2739)
* feat: upgraded fluent libraries * fix: adjustments to support fluent upgrade
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { FluentBundle } from "@fluent/bundle/compat";
|
||||
import { ErrorRequestHandler } from "express";
|
||||
|
||||
import { CoralError, InternalError } from "coral-server/errors";
|
||||
import { I18n } from "coral-server/services/i18n";
|
||||
import { Request } from "coral-server/types/express";
|
||||
import { FluentBundle } from "fluent/compat";
|
||||
|
||||
/**
|
||||
* wrapError ensures that the error being propagated is a CoralError.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable max-classes-per-file */
|
||||
|
||||
import { FluentBundle } from "fluent/compat";
|
||||
import { FluentBundle } from "@fluent/bundle/compat";
|
||||
import { MongoError } from "mongodb";
|
||||
import uuid from "uuid";
|
||||
import { VError } from "verror";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { FluentBundle } from "@fluent/bundle/compat";
|
||||
import crypto from "crypto";
|
||||
import { FluentBundle } from "fluent/compat";
|
||||
|
||||
import { translate } from "coral-server/services/i18n";
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { FluentBundle } from "@fluent/bundle/compat";
|
||||
import { DOMLocalization } from "@fluent/dom/compat";
|
||||
import { Job } from "bull";
|
||||
import createDOMPurify from "dompurify";
|
||||
import { DOMLocalization } from "fluent-dom/compat";
|
||||
import { FluentBundle } from "fluent/compat";
|
||||
import { minify } from "html-minifier";
|
||||
import htmlToText from "html-to-text";
|
||||
import Joi from "joi";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { FluentBundle } from "fluent/compat";
|
||||
import { FluentBundle, FluentResource } from "@fluent/bundle/compat";
|
||||
import fs from "fs-extra";
|
||||
import path from "path";
|
||||
|
||||
@@ -64,7 +64,7 @@ export class I18n {
|
||||
|
||||
const messages = await fs.readFile(filePath, "utf8");
|
||||
|
||||
bundle.addMessages(messages);
|
||||
bundle.addResource(new FluentResource(messages));
|
||||
}
|
||||
|
||||
this.bundles[locale] = bundle;
|
||||
@@ -117,10 +117,10 @@ export function translate(
|
||||
defaultValue: string,
|
||||
id: string,
|
||||
args?: object,
|
||||
errors?: string[]
|
||||
errors?: Error[]
|
||||
): string {
|
||||
const message = bundle.getMessage(id);
|
||||
if (!message) {
|
||||
if (!message || !message.value) {
|
||||
if (config.get("env") === "test") {
|
||||
throw new Error(`the message for ${id} is missing`);
|
||||
}
|
||||
@@ -128,7 +128,7 @@ export function translate(
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
const value = bundle.format(message, args, errors);
|
||||
const value = bundle.formatPattern(message.value, args, errors);
|
||||
if (!value) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user