Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/recursyve/nestjs-translate
https://github.com/recursyve/nestjs-translate
i18n nestjs typescript
Last synced: 4 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/recursyve/nestjs-translate
- Owner: Recursyve
- License: mit
- Created: 2018-07-15T21:38:45.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-10-06T20:24:43.000Z (about 1 year ago)
- Last Synced: 2023-10-06T21:28:36.602Z (about 1 year ago)
- Topics: i18n, nestjs, typescript
- Language: TypeScript
- Size: 286 KB
- Stars: 5
- Watchers: 4
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nestjs-translation
A i18n library for NestJs.
**This library is work in progress**
## Installation
```
npm install nestjs-translate --save
```This library works only with Nest5
## Usage
#### 1. Import `TranslateModule`The first step is to import the adding `TranslateModule.forRoot` in your AppModule. The `forRoot` function takes the path of the i18n files to load.
```typescript
@Module({
imports: [
TranslateModule.forRoot(__dirname + '/../assets/i18n')
]
})
export class ApplicationModule {
}
```#### 2. Use the `TranslateService`
For the moment, the default language is set to en. You can overwrite the language when getting a translation.
```typescript
@Injectable()
export class HomeService {
constructor(private translateService: TranslateService){}
public defaultWelcomeMessage(lang: string) {
return this.translateService.get('welcome');
}
public welcomeMessage(lang: string) {
return this.translateService.get(lang, 'welcome');
}
}```