nestjs-i18n
Advanced tools
Comparing version 2.2.3 to 3.0.0
@@ -33,3 +33,3 @@ "use strict"; | ||
try { | ||
return yield parse_1.parseTranslations(options.path, options.loadingType || 'BY_DOMAIN'); | ||
return yield parse_1.parseTranslations(options.path); | ||
} | ||
@@ -86,3 +86,3 @@ catch (e) { | ||
try { | ||
return yield parse_1.parseTranslations(options.path, options.loadingType || 'BY_DOMAIN'); | ||
return yield parse_1.parseTranslations(options.path); | ||
} | ||
@@ -89,0 +89,0 @@ catch (e) { |
@@ -5,3 +5,2 @@ import { Type } from '@nestjs/common'; | ||
export interface I18nOptions { | ||
loadingType?: I18nLoadingType; | ||
path: string; | ||
@@ -8,0 +7,0 @@ fallbackLanguage?: string; |
import { I18nTranslation } from '../i18n.constants'; | ||
import { I18nLoadingType } from '..'; | ||
export declare function parseTranslations(i18nPath: string, loadingType: I18nLoadingType): Promise<I18nTranslation>; | ||
export declare function parseTranslations(i18nPath: string): Promise<I18nTranslation>; |
@@ -20,3 +20,3 @@ "use strict"; | ||
.filter(isDirectory); | ||
function parseTranslations(i18nPath, loadingType) { | ||
function parseTranslations(i18nPath) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -34,16 +34,8 @@ return new Promise((resolve, reject) => { | ||
files.map(file => { | ||
let key; | ||
let global = false; | ||
switch (loadingType) { | ||
case 'BY_DOMAIN': | ||
key = path.parse(file).name; | ||
break; | ||
case 'BY_LANGUAGE': | ||
key = path | ||
.dirname(path.relative(i18nPath, file)) | ||
.split(path.sep)[0]; | ||
if (key === '.') { | ||
global = true; | ||
} | ||
break; | ||
const key = path | ||
.dirname(path.relative(i18nPath, file)) | ||
.split(path.sep)[0]; | ||
if (key === '.') { | ||
global = true; | ||
} | ||
@@ -50,0 +42,0 @@ const data = JSON.parse(fs.readFileSync(file, 'utf8')); |
{ | ||
"name": "nestjs-i18n", | ||
"version": "2.2.3", | ||
"version": "3.0.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "author": "Toon van Strijp", |
@@ -17,24 +17,2 @@ [![Build Status](https://travis-ci.org/ToonvanStrijp/nestjs-i18n.svg?branch=master)](https://travis-ci.org/ToonvanStrijp/nestjs-i18n) [![Greenkeeper badge](https://badges.greenkeeper.io/ToonvanStrijp/nestjs-i18n.svg)](https://greenkeeper.io/) | ||
This module offers to types of loading in your translations files: `BY_DOMAIN` and `BY_LANGUAGE`. | ||
##### loading: BY_DOMAIN (DEPRECATED) will be removed in V3.0.0 | ||
create a directory with your translations files it can be as deeply nested as you would like as long as the keys of the translations are unique. The name of each file should be the language you're targeting. | ||
``` | ||
i18n | ||
├── auth | ||
│ ├── en.json | ||
│ └── nl.json | ||
├── company | ||
│ ├── en.json | ||
│ └── nl.json | ||
└── event | ||
├── en.json | ||
├── nl.json | ||
│ | ||
└── location | ||
├── en.json | ||
└── nl.json | ||
``` | ||
#### loading: BY_LANGUAGE | ||
create a directory and in it define your language keys as directories. When using `BY_LANGUAGE` you can also define global translations. This is useful for things that are the same in each language for example your company name. Each file that is in the root of your i18n folder will be defined globally. You can overwrite global translations by defining them within a language. | ||
@@ -125,1 +103,4 @@ ``` | ||
``` | ||
# Breaking changes: | ||
- from V3.0.0 on we load translations based on their directory name instead of file name. Change your translations files to the structure above: [info](https://github.com/ToonvanStrijp/nestjs-i18n#structure) |
16525
281
105