Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zbinlin/koa-fluent
Fluent middleware for koa
https://github.com/zbinlin/koa-fluent
Last synced: 4 days ago
JSON representation
Fluent middleware for koa
- Host: GitHub
- URL: https://github.com/zbinlin/koa-fluent
- Owner: zbinlin
- License: mit
- Created: 2019-05-31T17:45:42.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T06:00:58.000Z (almost 2 years ago)
- Last Synced: 2024-09-18T06:15:44.570Z (about 2 months ago)
- Language: TypeScript
- Size: 1.03 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# koa-fluent
Fluent middleware for koa
## Install
```shell
npm install koa-fluent
```## Usage
```javascript
import * as Koa from "koa";
import fluent from "koa-fluent";const app = new Koa();
/**
*
* Adds `ftl` function to app.context
* dirs list tree
* ./locales
* ├── en-US.ftl
* ├── jp.ftl
* └── zh-CN.ftl
*/
fluent(app, {
dirs: "./locales", // locales dir
defaultLanguage: "en-US", // optional
functionName: "ftl", // optional
queryField: "ftl_locale", // optional
cookieField: "ftl_locale", // optional
});/**
* Use ctx.ftl to format message
*/
app.use(async (ctx, next) => {
ctx.body = ctx.ftl("welcome", {
name: "colin",
});
});
```