[IMP] compiler: translatableAttributes can be added/removed

This commit is contained in:
Géry Debongnie
2022-02-03 13:31:30 +01:00
committed by Aaron Bohy
parent 140818b5f9
commit 2c1226d737
4 changed files with 32 additions and 9 deletions
+12 -2
View File
@@ -214,14 +214,24 @@ export class CodeGenerator {
templateName?: string;
dev: boolean;
translateFn: (s: string) => string;
translatableAttributes: string[];
translatableAttributes: string[] = TRANSLATABLE_ATTRS;
ast: AST;
staticCalls: { id: string; template: string }[] = [];
helpers: Set<string> = new Set();
constructor(ast: AST, options: CodeGenOptions) {
this.translateFn = options.translateFn || ((s: string) => s);
this.translatableAttributes = options.translatableAttributes || TRANSLATABLE_ATTRS;
if (options.translatableAttributes) {
const attrs = new Set(TRANSLATABLE_ATTRS);
for (let attr of options.translatableAttributes) {
if (attr.startsWith("-")) {
attrs.delete(attr.slice(1));
} else {
attrs.add(attr);
}
}
this.translatableAttributes = [...attrs];
}
this.hasSafeContext = options.hasSafeContext || false;
this.dev = options.dev || false;
this.ast = ast;