Skip to content

feat: add support i18n #730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 54 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
96614e8
feat: add support i18n
EndyKaufman Aug 28, 2020
5acc4b9
fix: update russian translate
EndyKaufman Aug 28, 2020
d7fa086
Merge branch 'develop' into i18n
EndyKaufman Aug 28, 2020
c29ffef
feat: support translate in place, not only global
EndyKaufman Aug 28, 2020
96f9630
Merge branch 'develop' into i18n
EndyKaufman Aug 28, 2020
cc3cd24
feat: add support create json from po
EndyKaufman Sep 2, 2020
d345c05
feat: add support translate woth crowdin
EndyKaufman Sep 3, 2020
6537f24
New translations template.pot (Romanian)
EndyKaufman Sep 3, 2020
f1c3ebe
New translations template.pot (Korean)
EndyKaufman Sep 3, 2020
b523ea8
New translations template.pot (Vietnamese)
EndyKaufman Sep 3, 2020
90d64b2
New translations template.pot (Chinese Traditional)
EndyKaufman Sep 3, 2020
aed257e
New translations template.pot (Chinese Simplified)
EndyKaufman Sep 3, 2020
73a158b
New translations template.pot (Ukrainian)
EndyKaufman Sep 3, 2020
9547e3d
New translations template.pot (Turkish)
EndyKaufman Sep 3, 2020
0f277ca
New translations template.pot (Swedish)
EndyKaufman Sep 3, 2020
a31ea21
New translations template.pot (Serbian (Cyrillic))
EndyKaufman Sep 3, 2020
b005308
New translations template.pot (Russian)
EndyKaufman Sep 3, 2020
ca23599
New translations template.pot (Portuguese)
EndyKaufman Sep 3, 2020
35951a1
New translations template.pot (Polish)
EndyKaufman Sep 3, 2020
775ae97
New translations template.pot (Norwegian)
EndyKaufman Sep 3, 2020
54490bc
New translations template.pot (Dutch)
EndyKaufman Sep 3, 2020
ed5c0bd
New translations template.pot (Japanese)
EndyKaufman Sep 3, 2020
631990f
New translations template.pot (French)
EndyKaufman Sep 3, 2020
a691f0d
New translations template.pot (Italian)
EndyKaufman Sep 3, 2020
f2ccc55
New translations template.pot (Hungarian)
EndyKaufman Sep 3, 2020
64802c9
New translations template.pot (Hebrew)
EndyKaufman Sep 3, 2020
f39e207
New translations template.pot (Finnish)
EndyKaufman Sep 3, 2020
04cd970
New translations template.pot (Greek)
EndyKaufman Sep 3, 2020
e48f8bf
New translations template.pot (German)
EndyKaufman Sep 3, 2020
ad5a125
New translations template.pot (Danish)
EndyKaufman Sep 3, 2020
4eccd5c
New translations template.pot (Czech)
EndyKaufman Sep 3, 2020
265d201
New translations template.pot (Catalan)
EndyKaufman Sep 3, 2020
0b5380e
New translations template.pot (Arabic)
EndyKaufman Sep 3, 2020
e720dd3
New translations template.pot (Afrikaans)
EndyKaufman Sep 3, 2020
f55d5ff
New translations template.pot (Spanish)
EndyKaufman Sep 3, 2020
55922d2
New translations template.pot (Portuguese, Brazilian)
EndyKaufman Sep 3, 2020
c0d9013
feat: merge pull request #1 from EndyKaufman/crowdin_i18n
EndyKaufman Sep 3, 2020
85fa8e6
New translations template.pot (Chinese Traditional)
EndyKaufman Sep 3, 2020
82df1b3
New translations template.pot (Chinese Simplified)
EndyKaufman Sep 3, 2020
2985d05
New translations template.pot (Portuguese)
EndyKaufman Sep 3, 2020
83294e3
New translations template.pot (Portuguese, Brazilian)
EndyKaufman Sep 3, 2020
4079b60
feat: merge pull request #2 from EndyKaufman/crowdin_i18n
EndyKaufman Sep 3, 2020
2466d7f
feat: update tests
EndyKaufman Sep 3, 2020
392ac7b
feat: disable check correct title for semver
EndyKaufman Sep 3, 2020
bd4f057
feat: add badges with crowdin
EndyKaufman Sep 3, 2020
7c4316b
fix: add build languages for tests
EndyKaufman Sep 3, 2020
f676a74
New translations template.pot (Chinese Traditional)
EndyKaufman Sep 3, 2020
96eaebb
New translations template.pot (Chinese Simplified)
EndyKaufman Sep 3, 2020
d3783bd
New translations template.pot (Portuguese)
EndyKaufman Sep 3, 2020
25542bb
New translations template.pot (Portuguese, Brazilian)
EndyKaufman Sep 3, 2020
f03c8ff
feat: merge pull request #3 from EndyKaufman/crowdin_i18n
EndyKaufman Sep 3, 2020
4dded4c
feat: add informations for i18n contributers
EndyKaufman Sep 3, 2020
3379e5a
feat: new translations template.pot (Russian) (#4)
EndyKaufman Sep 3, 2020
648efe5
fix: enable semantic config
EndyKaufman Sep 3, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/continuous-deployment-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
with:
registry-url: https://registry.npmjs.org
- run: npm ci --ignore-scripts
- run: npm run i18n:extract
- run: npm run i18n:fix
- run: npm run prettier:check
- run: npm run lint:check
- run: npm run test:ci
Expand All @@ -20,6 +22,7 @@ jobs:
- run: npm run build:cjs
- run: npm run build:umd
- run: npm run build:types
- run: cp -r i18n build
- run: cp LICENSE build/LICENSE
- run: cp README.md build/README.md
- run: jq 'del(.devDependencies) | del(.scripts)' package.json > build/package.json
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/continuous-integration-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- run: npm ci --ignore-scripts
- run: npm run i18n:extract
- run: npm run i18n:fix
- run: npm run prettier:check
- run: npm run lint:check
tests:
Expand All @@ -24,6 +26,7 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- run: npm ci --ignore-scripts
- run: npm run i18n:extract
- run: npm run test:ci
- run: npm install codecov -g
if: ${{ matrix.node-version == '14.x' }}
Expand All @@ -36,6 +39,8 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- run: npm ci --ignore-scripts
- run: npm run i18n:extract
- run: npm run i18n:fix
- run: npm run build:es2015
- run: npm run build:esm5
- run: npm run build:cjs
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ temp
# Files for playing around locally
playground.ts
playground.js

# Buided json dictionaries of i18n
i18n/**/*.json
76 changes: 76 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![codecov](https://codecov.io/gh/typestack/class-validator/branch/develop/graph/badge.svg)](https://codecov.io/gh/typestack/class-validator)
[![npm version](https://badge.fury.io/js/class-validator.svg)](https://badge.fury.io/js/class-validator)
[![install size](https://packagephobia.now.sh/badge?p=class-validator)](https://packagephobia.now.sh/result?p=class-validator)
[![Crowdin](https://badges.crowdin.net/class-validator/localized.svg)](https://crowdin.com/project/class-validator)

Allows use of decorator and non-decorator based validation.
Internally uses [validator.js][1] to perform validation.
Expand Down Expand Up @@ -37,6 +38,7 @@ Class-validator works on both browser and node.js platforms.
- [Validation decorators](#validation-decorators)
- [Defining validation schema without decorators](#defining-validation-schema-without-decorators)
- [Validating plain objects](#validating-plain-objects)
- [Basic support i18n](#basic-support-i18n)
- [Samples](#samples)
- [Extensions](#extensions)
- [Release notes](#release-notes)
Expand Down Expand Up @@ -989,6 +991,80 @@ Here is an example of using it:

Due to nature of the decorators, the validated object has to be instantiated using `new Class()` syntax. If you have your class defined using class-validator decorators and you want to validate plain JS object (literal object or returned by JSON.parse), you need to transform it to the class instance via using [class-transformer](https://github.com/pleerock/class-transformer)).

## Basic support i18n

Translations created with the machine, if you found the mistake please add a new version of translate and write a comment in the right panel in https://crowdin.com/

Basic set custom messages

```typescript
import { IsOptional, Equals, Validator, I18N_MESSAGES } from 'class-validator';

class MyClass {
@IsOptional()
@Equals('test')
title: string = 'bad_value';
}

const RU_I18N_MESSAGES = {
...I18N_MESSAGES,
'$property must be equal to $constraint1': '$property должно быть равно $constraint1',
};

const model = new MyClass();

validator.validate(model, messages: RU_I18N_MESSAGES).then(errors => {
console.log(errors[0].constraints);
// out: title должно быть равно test
});
```

Load from file

```typescript
import { IsOptional, Equals, Validator, I18N_MESSAGES } from 'class-validator';
import { readFileSync } from 'fs';
import { resolve } from 'path';

class MyClass {
@IsOptional()
@Equals('test')
title: string = 'bad_value';
}

const RU_I18N_MESSAGES = JSON.parse(readFileSync(resolve(__dirname, './node_modules/class-validator/i18n/ru.json')).toString());

const model = new MyClass();

validator.validate(model, messages: RU_I18N_MESSAGES).then(errors => {
console.log(errors[0].constraints);
// out: title должен быть равен test
});
```

With override

```typescript
import { IsOptional, Equals, Validator, I18N_MESSAGES } from 'class-validator';

class MyClass {
@IsOptional()
@Equals('test')
title: string = 'bad_value';
}

Object.assign(I18N_MESSAGES, {
'$property must be equal to $constraint1': '$property должно быть равно $constraint1',
});

const model = new MyClass();

validator.validate(model).then(errors => {
console.log(errors[0].constraints);
// out: title должно быть равно test
});
```

## Samples

Take a look on samples in [./sample](https://github.com/pleerock/class-validator/tree/master/sample) for more examples of
Expand Down
3 changes: 3 additions & 0 deletions crowdin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
files:
- source: '*.pot'
translation: /%original_path%/%two_letters_code%.po
Loading