1 | # Introduction
|
2 |
|
3 | [![Travis](https://img.shields.io/travis/i18next/i18next-node-fs-backend/master.svg?style=flat-square)](https://travis-ci.org/i18next/i18next-node-fs-backend)
|
4 | [![Coveralls](https://img.shields.io/coveralls/i18next/i18next-node-fs-backend/master.svg?style=flat-square)](https://coveralls.io/github/i18next/i18next-node-fs-backend)
|
5 | [![npm version](https://img.shields.io/npm/v/i18next-node-fs-backend.svg?style=flat-square)](https://www.npmjs.com/package/i18next-node-fs-backend)
|
6 | [![David](https://img.shields.io/david/i18next/i18next-node-fs-backend.svg?style=flat-square)](https://david-dm.org/i18next/i18next-node-fs-backend)
|
7 |
|
8 | This is a i18next backend to be used node.js. It will load resources from filesystem. Right now it supports following filetypes:
|
9 |
|
10 | - .json
|
11 | - .json5
|
12 | - .yml
|
13 | - .cson
|
14 |
|
15 | # Getting started
|
16 |
|
17 | Source can be loaded via [npm](https://www.npmjs.com/package/i18next-node-fs-backend).
|
18 |
|
19 | ```
|
20 | $ npm install i18next-node-fs-backend
|
21 | ```
|
22 |
|
23 | Wiring up:
|
24 |
|
25 | ```js
|
26 | var i18next = require("i18next");
|
27 | var Backend = require("i18next-node-fs-backend");
|
28 |
|
29 | i18next.use(Backend).init(i18nextOptions);
|
30 | ```
|
31 |
|
32 | As with all modules you can either pass the constructor function (class) to the i18next.use or a concrete instance.
|
33 |
|
34 | ## Backend Options
|
35 |
|
36 | ```js
|
37 | {
|
38 | // path where resources get loaded from
|
39 | loadPath: '/locales/{{lng}}/{{ns}}.json',
|
40 |
|
41 | // path to post missing resources
|
42 | addPath: '/locales/{{lng}}/{{ns}}.missing.json',
|
43 |
|
44 | // jsonIndent to use when storing json files
|
45 | jsonIndent: 2,
|
46 |
|
47 | // custom parser
|
48 | parse: function(data) { return data; }
|
49 | }
|
50 | ```
|
51 |
|
52 | **hint** {{lng}}, {{ns}} use the same prefix, suffix you define in interpolation for translations!!!
|
53 |
|
54 | Options can be passed in:
|
55 |
|
56 | **preferred** - by setting options.backend in i18next.init:
|
57 |
|
58 | ```js
|
59 | var i18next = require("i18next");
|
60 | var Backend = require("i18next-node-fs-backend");
|
61 |
|
62 | i18next.use(Backend).init({
|
63 | backend: options
|
64 | });
|
65 | ```
|
66 |
|
67 | on construction:
|
68 |
|
69 | ```js
|
70 | var Backend = require("i18next-node-fs-backend");
|
71 | var backend = new Backend(null, options);
|
72 | ```
|
73 |
|
74 | by calling init:
|
75 |
|
76 | ```js
|
77 | var Backend = require("i18next-node-fs-backend");
|
78 | var backend = new Backend();
|
79 | backend.init(options);
|
80 | ```
|
81 |
|
82 | ---
|
83 |
|
84 | <h3 align="center">Gold Sponsors</h3>
|
85 |
|
86 | <p align="center">
|
87 | <a href="https://locize.com/" target="_blank">
|
88 | <img src="https://raw.githubusercontent.com/i18next/i18next/master/assets/locize_sponsor_240.gif" width="240px">
|
89 | </a>
|
90 | </p>
|