@react-form-builder/core
Version:
React JSON Schema Form Builder to create complex, validated, reusable forms with no deep React knowledge required
45 lines (44 loc) • 1.68 kB
JavaScript
import { FluentResource as f } from "@fluent/bundle";
import { createFluentBundle as c } from "./createFluentBundle.js";
import { logFluentErrors as p, convertFluentError as I } from "./fluentErrors.js";
import { objectToFluentResource as h } from "./fluentResource.js";
const d = (n, t, e) => {
const o = h(t), s = new f(o);
return n.addResource(s, e).map(I);
}, a = (n, t, e) => {
const o = d(e, n);
return t.length = 0, t.push(...o), p(t), e;
};
class R {
#t = /* @__PURE__ */ new Map();
/**
* Returns an existing bundle for the locale or creates and caches a new one.
* @param languageFullCode the full language code.
* @returns the fluent bundle for the locale.
*/
getOrCreate(t) {
const e = this.#t.get(t) ?? c(t);
return this.#t.set(t, e), e;
}
/**
* Adds messages to the cached bundle for the locale.
* @param locale the locale for the messages.
* @param messages the messages to add.
* @param options add-resource options.
* @param options.allowOverrides when true, allows overriding existing message ids in the bundle.
* @returns localization errors from fluent.
*/
addMessages(t, e, o) {
return d(this.getOrCreate(t), e, o);
}
}
const w = (n, t, e) => {
const o = n.defaultLanguage.fullCode, s = o !== t ? n.localization.getItems(o) : void 0, l = n.localization.getItems(t), r = s ?? void 0, u = l ?? void 0, i = r ? a(r, e, c(o)) : void 0, m = u ? a(u, e, c(t)) : void 0;
return { defaultBundle: i, defaultItems: r, formBundle: m, formItems: u };
};
export {
R as FluentBundleCache,
a as populateFluentBundle,
w as setupLocalizationBundles
};
//# sourceMappingURL=fluentBundleSetup.js.map