https://github.com/pirxpilot/connect-gettext
https://github.com/pirxpilot/connect-gettext
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/pirxpilot/connect-gettext
- Owner: pirxpilot
- Created: 2015-05-09T15:36:57.000Z (about 11 years ago)
- Default Branch: main
- Last Pushed: 2024-01-31T11:52:40.000Z (over 2 years ago)
- Last Synced: 2025-03-02T17:37:29.937Z (over 1 year ago)
- Language: JavaScript
- Size: 17.6 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
[![NPM version][npm-image]][npm-url]
[![Build Status][build-image]][build-url]
[![Dependency Status][deps-image]][deps-url]
# connect-gettext
Lightweight implementation of gettext as connect middleware.
## Install
```sh
$ npm install --save connect-gettext
```
## Usage
Use with any middleware that sets `req.lang` - such as [detect-language] and/or [overwrite-language].
```js
var app = require('express');
var locale = {
supportedLanguages: ['de', 'fr', 'pl', 'en-GB', 'en-US'],
defaultLanguage: 'en',
gettextAlias: '_'
};
// use any middleware that sets req.lang
// `detect-language` is just an example
app.use(require('detect-language')(locale));
app.use(require('connect-gettext')(locale));
```
Once the middleware is applied `res.locals.gettext` will have `gettext` implementation inserted
and `res.render` will be able to use it when rendering pages.
```jade
p
| #{_("This is how you can use it")}
span= _("with Jade")
```
## License
MIT © [Damian Krzeminski](https://pirxpilot.me)
[detect-language]: https://npmjs.org/package/detect-language
[overwrite-language]: https://npmjs.org/package/overwrite-language
[npm-image]: https://img.shields.io/npm/v/connect-gettext
[npm-url]: https://npmjs.org/package/connect-gettext
[build-url]: https://github.com/pirxpilot/connect-gettext/actions/workflows/check.yaml
[build-image]: https://img.shields.io/github/actions/workflow/status/pirxpilot/connect-gettext/check.yaml?branch=main
[deps-image]: https://img.shields.io/librariesio/release/npm/connect-gettext
[deps-url]: https://libraries.io/npm/connect-gettext