Skip to content

Commit

Permalink
[IMP] functions: translate argument description
Browse files Browse the repository at this point in the history
The main change of this revision is the way the arguments are declared,
in order to allow the translation of the argument description.

Before this revision, arguments were declared with a template string,
which is directly interpreted, before that the translation system is
initialized. This is why the description of the arguments was not
translated.

With this revision, the arguments are declared with a function and the
description is stored in a variable. This way, the description is
translated when it's needed.

Task-id 2827455

closes #2060

Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
  • Loading branch information
pro-odoo committed Feb 27, 2023
1 parent c215783 commit a815a16
Show file tree
Hide file tree
Showing 25 changed files with 1,964 additions and 1,647 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
<span
t-if="arg.optional || arg.repeating || arg.default ">&#xA0;- [optional]&#xA0;</span>
<span t-if="arg.default">
<span>default:&#xA0;</span>
<t t-esc="arg.defaultValue"/>
<span>&#xA0;by default</span>
</span>
<span t-if="arg.repeating">repeatable</span>
</div>
Expand Down
18 changes: 2 additions & 16 deletions src/functions/arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,8 @@ const ARG_TYPES: ArgType[] = [
"META",
];

/**
* This function is meant to be used as a tag for a template strings.
*
* Its job is to convert a textual description of the list of arguments into an
* actual array of Arg, suitable for consumption.
*/
export function args(strings: string): ArgDefinition[] {
let lines = strings.split("\n");
const result: ArgDefinition[] = [];
for (let l of lines) {
l = l.trim();
if (l) {
result.push(makeArg(l));
}
}
return result;
export function arg(definition: string, description: string = ""): ArgDefinition {
return makeArg(`${definition} ${description}`);
}

function makeArg(str: string): ArgDefinition {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import * as statistical from "./module_statistical";
import * as text from "./module_text";
import * as web from "./module_web";

export { args } from "./arguments";
export { arg } from "./arguments";

type Functions = { [functionName: string]: AddFunctionDescription };
type Category = { name: string; functions: Functions };
Expand Down
13 changes: 8 additions & 5 deletions src/functions/module_custom.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { createLargeNumberFormat } from "../helpers";
import { _lt } from "../translation";
import { AddFunctionDescription, PrimitiveArg, PrimitiveArgValue } from "../types";
import { args } from "./arguments";
import { arg } from "./arguments";
import { toNumber } from "./helpers";

// -----------------------------------------------------------------------------
// FORMAT.LARGE.NUMBER
// -----------------------------------------------------------------------------
export const FORMAT_LARGE_NUMBER: AddFunctionDescription = {
description: _lt(`Apply a large number format`),
args: args(`
value (number) ${_lt("The number.")}
unit (string, optional) ${_lt("The formatting unit. Use 'k', 'm', or 'b' to force the unit")}
`),
args: [
arg("value (number)", _lt("The number.")),
arg(
"unit (string, optional)",
_lt("The formatting unit. Use 'k', 'm', or 'b' to force the unit")
),
],
returns: ["NUMBER"],
computeFormat: (arg: PrimitiveArg, unit: PrimitiveArg | undefined) => {
const value = Math.abs(toNumber(arg.value));
Expand Down
31 changes: 19 additions & 12 deletions src/functions/module_database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
MatrixArgValue,
PrimitiveArgValue,
} from "../types";
import { args } from "./arguments";
import { arg } from "./arguments";
import { assert, toString, visitMatchingRanges } from "./helpers";
import { PRODUCT, SUM } from "./module_math";
import { AVERAGE, COUNT, COUNTA, MAX, MIN, STDEV, STDEVP, VAR, VARP } from "./module_statistical";
Expand Down Expand Up @@ -139,17 +139,24 @@ function getMatchingCells(
return matchingCells;
}

const databaseArgs = args(`
database (range) ${_lt(
"The array or range containing the data to consider, structured in such a way that the first row contains the labels for each column's values."
)}
field (any) ${_lt(
"Indicates which column in database contains the values to be extracted and operated on."
)}
criteria (range) ${_lt(
"An array or range containing zero or more criteria to filter the database values by before operating."
)}
`);
const databaseArgs = [
arg(
"database (range)",
_lt(
"The array or range containing the data to consider, structured in such a way that the first row contains the labels for each column's values."
)
),
arg(
"field (any)",
_lt("Indicates which column in database contains the values to be extracted and operated on.")
),
arg(
"criteria (range)",
_lt(
"An array or range containing zero or more criteria to filter the database values by before operating."
)
),
];

// -----------------------------------------------------------------------------
// DAVERAGE
Expand Down

0 comments on commit a815a16

Please sign in to comment.