https://github.com/lamualfa/dn-i18next-mongo-backend
i18next mongodb backend https://www.i18next.com/ - Only for Deno 🦖
https://github.com/lamualfa/dn-i18next-mongo-backend
deno i18next i18next-back mongodb
Last synced: about 2 months ago
JSON representation
i18next mongodb backend https://www.i18next.com/ - Only for Deno 🦖
- Host: GitHub
- URL: https://github.com/lamualfa/dn-i18next-mongo-backend
- Owner: lamualfa
- License: wtfpl
- Created: 2020-05-22T10:19:55.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-10-26T14:45:14.000Z (over 5 years ago)
- Last Synced: 2025-01-01T04:52:54.885Z (over 1 year ago)
- Topics: deno, i18next, i18next-back, mongodb
- Language: TypeScript
- Homepage:
- Size: 253 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

[](LICENSE)
[](https://codeclimate.com/github/lamualfa/dn-i18next-mongo-backend/maintainability)
[](https://github.com/lamualfa/dn-i18next-mongo-backend)
## Are you a NodeJS user? If `true`, we provide the same library for NodeJS. See: [Mongo Backend for NodeJS](https://github.com/lamualfa/i18next-node-mongo-backend)
# Integrate [i18next](https://github.com/i18next/i18next) with [MongoDB](https://www.mongodb.com/) in Deno 🦖
# Introduction
This is a [i18next](https://github.com/i18next/i18next) backend to be used in Deno. It will load resources from a [MongoDB](https://www.mongodb.org) database.
# Usage
> **IMPORTANT**: Because we use `mongo@v0.7.0` as a driver to connect to MongoDB, please also follow the guidelines and requirements of the library. See [Mongo in Deno](https://deno.land/x/mongo#important) for further information.
```ts
import i18next from 'https://deno.land/x/i18next/index.js'
import { Backend } from 'https://deno.land/x/i18next_mongo_backend/mod.ts'
i18next.use(Backend).init({
// Backend Options
backend: options,
})
```
# Backend Options
```js
{
// Database Name
dbName: '', // Required
// Or
// MongoDB standard configuration
host: '',
port: 27017,
// Or
// Use collection - See: https://doc.deno.land/https/deno.land/x/mongo/mod.ts#Collection
collection: Collection,
// MongoDB authentication. Remove it if not needed
user: '',
password: '',
// Collection name in database will be used to store i18next data
colName: 'i18n',
// MongoDB field name
// Language data
langFieldName: 'lang',
// Namespace data
nsFieldName: 'ns',
// Data
dataFieldName: 'data',
// Remove MongoDB special character from field name - See https://jira.mongodb.org/browse/SERVER-3229
sanitizeFieldName: true,
// Error handlers
readOnError: console.error,
readMultiOnError: console.error,
createOnError: console.error,
// MongoClient Options - See: https://doc.deno.land/https/deno.land/x/mongo/mod.ts#ClientOptions
mongodb: ClientOptions
};
```
## Example Backend Options
#### Connect with `host` and `port`:
```js
{
host: 'localhost',
port: 27017,
dbName: 'test' // Required field
}
```
#### Connect with `collection` instance (_Recommended_):
If you already have your own connection, use this to avoid useless connections
```js
{
collection: Collection, // See: https://doc.deno.land/https/deno.land/x/mongo/mod.ts#Collection
dbName: 'test', // Required field
}
```
## Example of the MongoDB document that will be created:
```json
// Key name is according to provided in options
{
"lang": "en-US",
"ns": "translations",
"data": {
"key": "Thank you!"
}
}
```