Hi
Great to see the error handling documented in https://github.com/projectfluent/fluent/wiki/Error-Handling#error-reporting that will provide errors such as Use * in front of at least one variant to mark it as primary
.
Which tools are available for this?
The following example from https://github.com/projectfluent/fluent.js/tree/master/fluent-bundle#how-to-use hints that it will provide syntax errors.
import {FluentBundle, FluentResource} from "@fluent/bundle";
let resource = new FluentResource(`
-brand-name = Foo 3000
welcome = Welcome, {$name}, to {-brand-name}!
`);
let bundle = new FluentBundle("en-US");
let errors = bundle.addResource(resource);
if (errors.length) {
// Syntax errors are per-message and don't break the whole resource
}
let welcome = bundle.getMessage("welcome");
if (welcome.value) {
bundle.formatPattern(welcome.value, {name: "Anna"});
// → "Welcome, Anna, to Foo 3000!"
}
However if I remove an ending curly-brace in the welcome message the errors is still empty. Same also if I refer to -brandname instead of -brand-name.
As for the example from the error handling documentation, running
import { FluentBundle, FluentResource } from "@fluent/bundle";
let resource = new FluentResource(`
liked-photo = { PLURAL($people) ->
[1] { $people } lubi
[2] { $people } lubią
[3] { TAKE(2, $people), "jedna inna osoba" } lubią
*[other] { TAKE(2, $people),
"{ PLURAL(DROP(2, $people)) ->
[1] jedna inna osoba lubią
[few] { LEN(DROP(2, $people)) } inne osoby lubią
[many] { LEN(DROP(2, $people)) } innych osób lubi
}"
}
} Twoje zdjęcie.`);
console.log(resource)
let bundle = new FluentBundle("en-US");
let errors = bundle.addResource(resource);
if (errors.length) {
// Syntax errors are per-message and don't break the whole resource
console.log("Errors ", errors)
} else {
console.log("No errors when adding resource")
}
prints
FluentResource { body: [] }
No errors when adding resource