# pug-i18n-postparse

> pug i18n plugin

Latest version **1.0.3** (published 2018-05-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install pug-i18n-postparse
pnpm add pug-i18n-postparse
yarn add pug-i18n-postparse
bun add pug-i18n-postparse
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2018-05-01 |
| First published | 2018-05-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 10.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | sarkiroka |
| Maintainers | sarkiroka |
| Keywords | pug, i18n, plugin, postparse, language, lang |

## Links

- npm: https://www.npmjs.com/package/pug-i18n-postparse
- Repository: https://github.com/sarkiroka/pug-i18n-postparse
- Homepage: https://github.com/sarkiroka/pug-i18n-postparse#readme
- Issues: https://github.com/sarkiroka/pug-i18n-postparse/issues
- npm.io page: https://npm.io/package/pug-i18n-postparse

## Dependencies (2)

- [debug](https://npm.io/package/debug.md) 3.1.0
- [pug-walk](https://npm.io/package/pug-walk.md) 1.1.7

## Alternatives

- [messageformat](https://npm.io/package/messageformat.md) — 329.7K weekly downloads
- [@mintlify/scraping](https://npm.io/package/@mintlify/scraping.md) — 294.8K weekly downloads
- [@mintlify/previewing](https://npm.io/package/@mintlify/previewing.md) — 209.5K weekly downloads
- [@mintlify/prebuild](https://npm.io/package/@mintlify/prebuild.md) — 209.5K weekly downloads
- [@mintlify/link-rot](https://npm.io/package/@mintlify/link-rot.md) — 206.3K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2018-05-01
- 1.0.2 — 2018-05-01
- 1.0.1 — 2018-05-01
- 0.0.1-security — 2018-05-01

## README

# pug-i18n-postparse

## Why

Because the international support is too difficult otherwise. 

Not need to call always the t (translation) function everywhere. Just enjoy it :)

## Install

`npm i pug-i18n-postparse`

## Example

You can use pug without any special:

```pug
html
    head
        title Example
    body
        p This is a text
            a(href="/", title="Main page")  with link
```

![so simple](https://raw.githubusercontent.com/sarkiroka/pug-i18n-postparse/master/i18n.jpg "so simple")


Define the translation json

```json
{
    "de": {
        "Example": "Beispiel",
        "This is a text": "Das ist ein Text",
        "with link": "mit Link"
    },
    "hu": {
        "Example": "Példa",
        "This is a text": "Ez egy szöveg",
        "with link": "linkkel"
    }
}
```

...or if you want use different text in base language, you can specify that...

 
```json
{
    "en": {
        "Example": "An example",
        "This is a text": "This is a text",
        "with link": "with link"
    },
    "de": {
        "Example": "Beispiel",
        "This is a text": "Das ist ein Text",
        "with link": "mit Link"
    },
    "hu": {
        "Example": "Példa",
        "This is a text": "Ez egy szöveg",
        "with link": "linkkel"
    }
}
```

After that, you can use it from express

```js
const app = require('express')();
const pugI18nPostparse = require('pug-i18n-postparse');
const languageFilePath = __dirname + '/i18n.json';

app.set('view engine', 'pug');
app.set('views', __dirname); // or your views directory

app.use(pugI18nPostparse.express('en', languageFilePath)); // define the default language

app.get('/', function (req, res, next) {
    res.locals.language = 'de'; // you can pass the selected language in locals
    res.render('index');
});

app.listen(3000);
```

You can use your express middleware for language selection

```js
const app = require('express')();
const pugI18nPostparse = require('pug-i18n-postparse');
const languageFilePath = __dirname + '/i18n.json';

app.set('view engine', 'pug');
app.set('views', __dirname); // or your views directory

app.use(pugI18nPostparse.express('en', languageFilePath)); // define the default language

app.use(function(req,res,next){
    // this is a place, where you get your user preferred language - for example from request header, or user settings
    res.locals.language = 'de'; // you can pass the selected language in locals
    next();
});

app.get('/', function (req, res, next) {
    res.render('index');
});

app.listen(3000);
```

You can use your **own** i18n implementation:

```js
function myI18nImplementation(text, language){
    // your magic here
    let retValue = text.replace(/^(")?.*?(")?$/,'$1Marklar$2');
    return retValue;
}

const app = require('express')();
const pugI18nPostparse = require('pug-i18n-postparse');

app.set('view engine', 'pug');
app.set('views', __dirname); // or your views directory

app.use(pugI18nPostparse.express('en', myI18nImplementation));

app.get('/', function (req, res, next) {
    res.render('index');
});

app.listen(3000);
```

The result is:

```html
<html>
    <head>
        <title>Marklar</title>
    </head>
    <body>
        <p>Marklar <a href="/" title="Marklar">Marklar</a></p>
    </body>
</html>
```

See the [examples](https://github.com/sarkiroka/pug-i18n-postparse/tree/master/example)

---
_Source: https://npm.io/package/pug-i18n-postparse · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
