DefinitelyTyped/types/fluent/fluent-tests.ts
James Nimlos d9437c4fd6 Update fluent definitions for v0.11 (#33859)
* update fluent definitions for v0.11

* remove circular reference

* add typescript version requiring fix

* downgrade ts version

definitelytyped-header-parser errors on prereleases versions but
TS v3.4 is not actually released so it also errors
2019-03-25 09:38:31 -07:00

51 lines
1.3 KiB
TypeScript

import { FluentBundle, ftl, FluentResource } from 'fluent';
const bundle1 = new FluentBundle('en-US');
const errors1 = bundle1.addMessages(ftl`
-brand-name = Foo 3000
welcome = Welcome, { $name }, to { -brand-name }!
`);
if (errors1.length) {
// syntax errors are per-message and don't break the whole resource
}
const welcome = bundle1.getMessage('welcome');
bundle1.format(welcome, { name: 'Anna' });
// FluentBundle constructor examples:
const bundle2 = new FluentBundle(['en-US']);
const bundle3 = new FluentBundle(['en-US'], { useIsolating: false });
const bundle4 = new FluentBundle(['en-US'], {
useIsolating: true,
functions: {
NODE_ENV: () => 'production'
}
});
// FluentBundle addMessages examples:
bundle1.addMessages('foo = Foo');
bundle2.hasMessage('foo');
bundle2.getMessage('foo');
// FluentBundle addResource examples:
const a = FluentResource.fromString('foo');
bundle1.addResource(a);
bundle2.getMessage('foo');
// FluentBundle format examples:
const errors2: any[] = [];
bundle1.addMessages('hello = Hello, { $name }!');
const hello = bundle2.getMessage('hello');
bundle3.format(hello, { name: 'Jane' }, errors2);
bundle3.format(hello, undefined, errors2);
for (const [id, message] of bundle1.messages) {
bundle1.getMessage(id);
bundle1.format(message);
}