@hydroperx/tradur
v1.0.0
Published
Work with Project Fluent translation lists.
Readme
Tradur
Rapidly support Project Fluent translation in your web application. Both client-side and server-side applications are supported.
That is an updated version of com.hydroper.ftl.
Getting Started
Install dependency:
npm install @hydroperx/tradurExample TypeScript:
import { Tradur } from "@hydroperx/tradur";
class Main {
tradur: Tradur;
constructor() {
this.tradur = new Tradur({
locales: ["en"],
fallbacks: {
// "pt-BR": ["en"],
},
defaultLocale: "en",
source: "res/lang",
files: [
"_", // res/lang/LANG/_.ftl
],
clean: true,
// specify either 'http' or 'fileSystem' as load method
method: "fileSystem",
});
this.initialize();
}
async initialize() {
if (!(await this.tradur.load())) {
// failed to load
return;
}
console.log(this.tradur.get("hello", { to: "Diantha" }));
}
}
new Main();Example FTL file at res/lang/en/_.ftl:
hello = Hello, { $to }!Server Usage
Usually, for server applications, set the clean option to false and clone the Tradur object when necessary by invoking tradur.clone(); to change the current locale.
The tradur.clone(); method clones the Tradur object, but still re-uses resources from the original object, avoiding resource duplication.
