Skip to content

Commit f974337

Browse files
authored
Merge pull request #149 from 2Toad/jp-issue-92
Fixes #92: Add profane words for additional languages
2 parents 47f5bb1 + 30d8802 commit f974337

File tree

9 files changed

+3552
-404
lines changed

9 files changed

+3552
-404
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ tests/
1111
.nvmrc
1212
.prettierignore
1313
.prettierrc.json
14+
docker-compose.yml
1415
tsconfig.json

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ By default, this is set to `['en']` (English). You can change the default to any
5858

5959
```JavaScript
6060
const profanity = new Profanity({
61-
languages: ["en", "de"],
61+
languages: ['en', 'de'],
6262
});
6363
```
6464

6565
You can override this option by specifying the languages in `exists` or `censor`:
6666

6767
```JavaScript
68-
profanity.exists('Je suis un connard', ["fr"]);
68+
profanity.exists('Je suis un connard', ['fr']);
6969
// true
7070

71-
profanity.censor('I like big butts and je suis un connard', CensorType.Word, ["en", "de", "fr"]);
71+
profanity.censor('I like big butts and je suis un connard', CensorType.Word, ['en', 'de', 'fr']);
7272
// I like big @#$%&! and je suis un @#$%&!
7373
```
7474

contribute.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,40 @@ The Profanity project includes Husky for running Git Hooks. Running `git commit`
6969

7070
- `chai`: we must use v4.x because v5.x is pure ESM, and we require CommonJS modules
7171

72+
### Translations
73+
74+
We utilize a self-hosted instance of the Open Source [LibreTranslate](https://github.com/LibreTranslate/LibreTranslate) lib to translate the core English list of profane words.
75+
76+
#### Steps to Run Translations
77+
78+
1. Open a terminal.
79+
2. Start Docker: `docker-compose up`.
80+
3. Run the translation script: `npm run translate`.
81+
82+
#### Available Languages
83+
84+
By default, the LibreTranslate service is configured to include all available target languages from [argos-translate](https://github.com/argosopentech/argos-translate). This configuration affects:
85+
86+
- **Startup Time**: Initial service startup. Depending on your system, this can take ~5 minutes.
87+
- **Translation Time**: Translating across all languages increases processing time.
88+
- **Library Size**: The final size of the Profanity library.
89+
90+
To optimize performance, we limit the target languages by configuring the `LT_LOAD_ONLY` environment variable:
91+
92+
##### Configure Target Languages
93+
1. Open the `./docker-compose.yml` file.
94+
2. Add a comma-separated list of the [supported language codes](https://github.com/argosopentech/argos-translate/blob/master/argostranslate/languages.csv) you wish to include. Ensure English (`en`) is included, as it serves as the source language.
95+
96+
**Example Configuration:**
97+
```yaml
98+
environment:
99+
LT_LOAD_ONLY: "en,es,fr,de"
100+
```
101+
102+
> **Note:**
103+
> - To add a new language, remove existing language codes from `LT_LOAD_ONLY`
104+
> - To update existing languages after changes to the core English list, include their language codes in `LT_LOAD_ONLY`
105+
72106
### Deployment
73107

74108
Deployments to Prod consist of building and publishing the Profanity lib to NPM, and are automated through our Continuous Deployment workflow.

docker-compose.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: "3"
2+
services:
3+
libretranslate:
4+
image: libretranslate/libretranslate:latest-cuda
5+
ports:
6+
- "5000:5000"
7+
environment:
8+
- LT_LOAD_ONLY=en,ar,zh,fr,de,hi,ja,ko,pt,ru,es
9+
- NVIDIA_VISIBLE_DEVICES=all
10+
- CUDA_LAUNCH_BLOCKING=0
11+
deploy:
12+
resources:
13+
reservations:
14+
devices:
15+
- driver: nvidia
16+
count: 1
17+
capabilities: [gpu]
18+
limits:
19+
memory: 5G
20+
healthcheck:
21+
test: ["CMD", "curl", "-f", "http://localhost:5000/languages"]
22+
interval: 30s
23+
timeout: 10s
24+
retries: 3

package-lock.json

Lines changed: 116 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"lint:fix": "eslint . --fix",
2323
"format": "prettier . --write",
2424
"prepublishOnly": "npm run lint && npm test",
25-
"prepare": "husky"
25+
"prepare": "husky",
26+
"translate": "ts-node src/scripts/translate.ts"
2627
},
2728
"repository": {
2829
"type": "git",
@@ -60,6 +61,7 @@
6061
"@types/node": "^22.5.2",
6162
"@typescript-eslint/eslint-plugin": "^8.4.0",
6263
"@typescript-eslint/parser": "^8.4.0",
64+
"axios": "^1.7.9",
6365
"benchmark": "^2.1.4",
6466
"chai": "^4.5.0",
6567
"eslint": "^9.9.1",

0 commit comments

Comments
 (0)