@ilingo/fs
Version:
This is a lightweight library for translation.
84 lines (61 loc) ⢠2.56 kB
Markdown
[](https://badge.fury.io/js/@ilingo%2Ffs)
[](https://github.com/Tada5hi/ilingo/actions/workflows/main.yml)
[](https://codecov.io/gh/tada5hi/ilingo)
[](https://snyk.io/test/github/Tada5hi/ilingo)
[](https://conventionalcommits.org)
This is a file system store for ilingo.
**Table of Contents**
- [Installation](
- [Usage](
- [License](
```bash
npm install @ilingo/fs --save
```
```typescript
import { Ilingo } from 'ilingo';
import FSStore from '@ilingo/fs';
const directory = 'language';
const ilingo = new Ilingo({
store: new FSStore({ directory }),
})
```
Locale strings should be stored in subdirectories as a group for each supported language (locale).
```bash
āāā ...
āāā language
āāā de
ā āāā app.{ts,js,json,conf}
ā āāā forum.{ts,js,json,conf}
āāā en
āāā app.{ts,js,json,conf}
āāā forum.{ts,js,json,conf}
```
To get started, create e.g. a language directory somewhere in your project.
Inside this directory, create a folder for each locale (e.g. en, de, ...), which should be supported.
The created folder represents a locale group. These groups do not have to follow any specific naming convention.
You should name the file according to the type of content it holds (e.g. app, forum, ...).
For example, letās say you want to create a file containing error messages.
You might simply name it: `error.{ts,js,json}`.
Each file should return an object containing an access key and a locale string.
**`app.{ts,js,json}`**
```typescript
module.exports = {
'key': 'The locale string to be shown.'
}
```
The object can also be (deeply) nested ā”.
**`app.{ts,js,json}`**
```typescript
module.exports = {
'nested': {
'key': 'The locale string to be shown.'
}
}
```
It is also possible to use `export default {...}` instead of `module.exports = {...}` for script files.
Made with š
Published under [MIT License](./LICENSE).