|
| 1 | +import {Message} from "../impl/model.js"; |
| 2 | +import {formatMessage, NumberValue} from "../impl/runtime.js"; |
| 3 | + |
| 4 | +console.log("==== English ===="); |
| 5 | + |
| 6 | +{ |
| 7 | + // "Transferred {NUMBER $payloadSize STYLE unit UNIT megabyte}." |
| 8 | + let message: Message = { |
| 9 | + lang: "en", |
| 10 | + id: "transferred", |
| 11 | + phrases: {}, |
| 12 | + selectors: [ |
| 13 | + { |
| 14 | + expr: null, |
| 15 | + default: {type: "StringLiteral", value: "default"}, |
| 16 | + }, |
| 17 | + ], |
| 18 | + variants: [ |
| 19 | + { |
| 20 | + keys: [{type: "StringLiteral", value: "default"}], |
| 21 | + value: [ |
| 22 | + {type: "StringLiteral", value: "Transferred "}, |
| 23 | + { |
| 24 | + type: "FunctionCall", |
| 25 | + name: "NUMBER", |
| 26 | + args: [{type: "VariableReference", name: "payloadSize"}], |
| 27 | + opts: { |
| 28 | + STYLE: {type: "StringLiteral", value: "unit"}, |
| 29 | + UNIT: {type: "StringLiteral", value: "megabyte"}, |
| 30 | + }, |
| 31 | + }, |
| 32 | + {type: "StringLiteral", value: "."}, |
| 33 | + ], |
| 34 | + }, |
| 35 | + ], |
| 36 | + }; |
| 37 | + console.log( |
| 38 | + formatMessage(message, { |
| 39 | + payloadSize: new NumberValue(1.23), |
| 40 | + }) |
| 41 | + ); |
| 42 | +} |
| 43 | + |
| 44 | +console.log("==== French ===="); |
| 45 | + |
| 46 | +{ |
| 47 | + // "{NUMBER $payloadSize STYLE unit UNIT megabyte} transféré." |
| 48 | + let message: Message = { |
| 49 | + lang: "fr", |
| 50 | + id: "transferred", |
| 51 | + phrases: {}, |
| 52 | + selectors: [ |
| 53 | + { |
| 54 | + expr: null, |
| 55 | + default: {type: "StringLiteral", value: "default"}, |
| 56 | + }, |
| 57 | + ], |
| 58 | + variants: [ |
| 59 | + { |
| 60 | + keys: [{type: "StringLiteral", value: "default"}], |
| 61 | + value: [ |
| 62 | + { |
| 63 | + type: "FunctionCall", |
| 64 | + name: "NUMBER", |
| 65 | + args: [{type: "VariableReference", name: "payloadSize"}], |
| 66 | + opts: { |
| 67 | + STYLE: {type: "StringLiteral", value: "unit"}, |
| 68 | + UNIT: {type: "StringLiteral", value: "megabyte"}, |
| 69 | + }, |
| 70 | + }, |
| 71 | + {type: "StringLiteral", value: " transféré."}, |
| 72 | + ], |
| 73 | + }, |
| 74 | + ], |
| 75 | + }; |
| 76 | + console.log( |
| 77 | + formatMessage(message, { |
| 78 | + payloadSize: new NumberValue(1.23), |
| 79 | + }) |
| 80 | + ); |
| 81 | +} |
0 commit comments