Public release from ruodoo-project: 19.0 - 2026-05-10 21:19:01 UTC

This commit is contained in:
CI Publish Bot
2026-05-10 21:19:11 +00:00
commit cbf9e6e6d6
1213 changed files with 183945 additions and 0 deletions

View File

@ -0,0 +1,57 @@
/** @odoo-module **/
import { useEffect, useEnv, useSubEnv } from "@odoo/owl";
import { registry } from "@web/core/registry";
const translateRegistry = registry.category("translate");
const translateContextSymbol = Symbol("translateContext");
class TranslateContext {
constructor(env, defaultCategories = []) {
this.env = env;
this.categories = new Map(defaultCategories.map(cat => [cat, [{}]]));
}
activateCategory(category, context) {
const contexts = this.categories.get(category) || new Set();
contexts.add(context);
this.categories.set(category, contexts);
return () => {
contexts.delete(context);
if (!contexts.size) this.categories.delete(category);
};
}
async getItems() {
return [...this.categories.entries()]
.flatMap(([category, contexts]) =>
translateRegistry
.category(category)
.getAll()
.map(factory => factory({ env: this.env, ...Object.assign({}, ...contexts) }))
)
.filter(Boolean)
.sort((a, b) => (a.sequence || 1000) - (b.sequence || 1000));
}
}
export function createTranslateContext(env, { categories = [] } = {}) {
return { [translateContextSymbol]: new TranslateContext(env, categories) };
}
export function useOwnTranslateContext({ categories = [] } = {}) {
useSubEnv(createTranslateContext(useEnv(), { categories }));
}
export function useEnvTranslateContext() {
const translateContext = useEnv()[translateContextSymbol];
if (!translateContext) throw new Error("No translate context in environment");
return translateContext;
}
export function useTranslateCategory(category, context = {}) {
const env = useEnv();
if (env.translate) {
const translateContext = useEnvTranslateContext();
useEffect(() => translateContext.activateCategory(category, context), () => []);
}
}