Skip to content

Commit e60af96

Browse files
authored
refactor(core): ♻️ do refactor and add multiple language support
refactor(core): ♻️ do refactor and add more language support
2 parents ee71f10 + 039ad1b commit e60af96

File tree

22 files changed

+4130
-254
lines changed

22 files changed

+4130
-254
lines changed

README.md

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,29 @@
1010

1111
🦄 Get Random Words (with pronunciation) for Free using this API
1212

13+
## 🌍 Languages
14+
15+
- English
16+
- Dutch
17+
- Spanish
18+
- French
19+
- Chinese
20+
- Japanese
21+
1322
## 🚀 API
1423

15-
- Free API - `https://random-words-api.vercel.app/word`
24+
- English Random Words - `https://random-words-api.vercel.app/word`
1625
- Dutch Random Words - `https://random-words-api.vercel.app/word/dutch`
17-
- Get Pronunciation for a Word - `https://random-words-api.vercel.app/pronounce/`
26+
- Spanish Random Words - `https://random-words-api.vercel.app/word/spanish`
27+
- French Random Words - `https://random-words-api.vercel.app/word/french`
28+
- Chinese Random Words - `https://random-words-api.vercel.app/word/chinese`
29+
- Japanese Random Words - `https://random-words-api.vercel.app/word/japanese`
30+
- Turkish Random Words - `https://random-words-api.vercel.app/word/turkish`
1831

1932
- PWA Demo - [Check Here](https://words.sanweb.info/)
2033

21-
## 🎛 Route Options
22-
23-
- Base URL: `https://random-words-api.vercel.app/word`
24-
34+
## 🎛 Route Options (English Only)
35+
- Base URL: `https://random-words-api.vercel.app/word/english`
2536
```text
2637
- /noun
2738
- /sentence
@@ -68,28 +79,6 @@
6879
]
6980
```
7081

71-
## 🌐 Sample Pronunciation Request
72-
73-
- API: `https://random-words-api.vercel.app/pronounce`
74-
- Method: `POST`
75-
76-
```sh
77-
POST http://localhost:3000/pronounce
78-
Content-Type: application/json
79-
80-
{
81-
"word": "This is amazing"
82-
}
83-
```
84-
85-
## 📣 Sample Pronunciation Response
86-
87-
```json
88-
{
89-
"pronunciation": "this is amasink"
90-
}
91-
```
92-
9382
- Check [api.rest](/test/api.rest) file for more details
9483

9584
## 💡 Learn New word
@@ -101,16 +90,16 @@ Content-Type: application/json
10190

10291
```sh
10392
# Clone the Repo
104-
git clone https://github.com/mcnaveen/Random-Words-API random-words
93+
git clone https://github.com/mcnaveen/random-words-api random-words-api
10594

10695
# Cd into Directory
10796
cd random-words
10897

10998
# Install Dependencies
110-
yarn install
99+
npm install
111100

112101
# Start the Development Server
113-
yarn start
102+
npm run dev
114103
```
115104

116105
## 🔀 Deploying to Heroku
@@ -132,6 +121,23 @@ OR
132121
Project - Give Forked Repo URL - Go Live
133122
```
134123

124+
## 🔐 Rate Limit
125+
126+
- To configure the rate limit, edit the `utils/index.js` file
127+
- Look for `limiter` variable
128+
- `max` is the maximum number of requests allowed in a given time window
129+
- `windowMs` is the time window in milliseconds
130+
- `message` is the message to be returned when the rate limit is exceeded
131+
132+
## 😇 Add New Language
133+
- Create a new folder in `data` with the full language name `ex: english`
134+
- Add the words in the `words.json` file
135+
- It should be an array of objects with `id`, `word`, and `definition` properties
136+
- The `id` should be a unique number for each word
137+
- The `word` should be the word in the language
138+
- The `definition` should be the definition of the word in English
139+
- The `pronunciation` should be the pronunciation of the word in the language (Optional)
140+
135141
## :question: How to Contribute?
136142

137143
Make your changes and follow the below instructions. We follow conventional commits.

app.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "wotd",
3-
"description": "Word of the Day.",
2+
"name": "random-words-api",
3+
"description": "API for getting random words in different languages",
44
"repository": "https://github.com/mcnaveen/Random-Words-API",
5-
"keywords": ["expressjs", "nodejs", "json"]
5+
"keywords": ["expressjs", "nodejs", "json", "random-words", "api"]
66
}

data/chinese/words.json

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
[
2+
{"id": 1, "word": "", "definition": "love"},
3+
{"id": 2, "word": "朋友", "definition": "friend"},
4+
{"id": 3, "word": "学校", "definition": "school"},
5+
{"id": 4, "word": "", "definition": "book"},
6+
{"id": 5, "word": "电脑", "definition": "computer"},
7+
{"id": 6, "word": "家庭", "definition": "family"},
8+
{"id": 7, "word": "工作", "definition": "work"},
9+
{"id": 8, "word": "幸福", "definition": "happiness"},
10+
{"id": 9, "word": "", "definition": "water"},
11+
{"id": 10, "word": "食物", "definition": "food"},
12+
{"id": 11, "word": "汽车", "definition": "car"},
13+
{"id": 12, "word": "电影", "definition": "movie"},
14+
{"id": 13, "word": "音乐", "definition": "music"},
15+
{"id": 14, "word": "城市", "definition": "city"},
16+
{"id": 15, "word": "旅行", "definition": "travel"},
17+
{"id": 16, "word": "健康", "definition": "health"},
18+
{"id": 17, "word": "运动", "definition": "exercise"},
19+
{"id": 18, "word": "老师", "definition": "teacher"},
20+
{"id": 19, "word": "学生", "definition": "student"},
21+
{"id": 20, "word": "电话", "definition": "telephone"},
22+
{"id": 21, "word": "电影", "definition": "film"},
23+
{"id": 22, "word": "艺术", "definition": "art"},
24+
{"id": 23, "word": "文化", "definition": "culture"},
25+
{"id": 24, "word": "语言", "definition": "language"},
26+
{"id": 25, "word": "历史", "definition": "history"},
27+
{"id": 26, "word": "科学", "definition": "science"},
28+
{"id": 27, "word": "数学", "definition": "mathematics"},
29+
{"id": 28, "word": "经济", "definition": "economics"},
30+
{"id": 29, "word": "政治", "definition": "politics"},
31+
{"id": 30, "word": "社会", "definition": "society"},
32+
{"id": 31, "word": "文学", "definition": "literature"},
33+
{"id": 32, "word": "哲学", "definition": "philosophy"},
34+
{"id": 33, "word": "法律", "definition": "law"},
35+
{"id": 34, "word": "医学", "definition": "medicine"},
36+
{"id": 35, "word": "工程", "definition": "engineering"},
37+
{"id": 36, "word": "计算机", "definition": "computer science"},
38+
{"id": 37, "word": "互联网", "definition": "internet"},
39+
{"id": 38, "word": "技术", "definition": "technology"},
40+
{"id": 39, "word": "交通", "definition": "transportation"},
41+
{"id": 40, "word": "自然", "definition": "nature"},
42+
{"id": 41, "word": "环境", "definition": "environment"},
43+
{"id": 42, "word": "空气", "definition": "air"},
44+
{"id": 43, "word": "土地", "definition": "land"},
45+
{"id": 44, "word": "能源", "definition": "energy"},
46+
{"id": 45, "word": "气候", "definition": "climate"},
47+
{"id": 46, "word": "动物", "definition": "animal"},
48+
{"id": 47, "word": "植物", "definition": "plant"},
49+
{"id": 48, "word": "海洋", "definition": "ocean"},
50+
{"id": 49, "word": "", "definition": "mountain"},
51+
{"id": 50, "word": "河流", "definition": "river"},
52+
{"id": 51, "word": "湖泊", "definition": "lake"},
53+
{"id": 52, "word": "天气", "definition": "weather"},
54+
{"id": 53, "word": "", "definition": "wind"},
55+
{"id": 54, "word": "", "definition": "rain"},
56+
{"id": 55, "word": "", "definition": "snow"},
57+
{"id": 56, "word": "太阳", "definition": "sun"},
58+
{"id": 57, "word": "月亮", "definition": "moon"},
59+
{"id": 58, "word": "星星", "definition": "star"},
60+
{"id": 59, "word": "宇宙", "definition": "universe"},
61+
{"id": 60, "word": "银河", "definition": "galaxy"},
62+
{"id": 61, "word": "太空", "definition": "space"},
63+
{"id": 62, "word": "星座", "definition": "constellation"},
64+
{"id": 63, "word": "地球", "definition": "Earth"},
65+
{"id": 64, "word": "太阳系", "definition": "solar system"},
66+
{"id": 65, "word": "黑洞", "definition": "black hole"},
67+
{"id": 66, "word": "星球", "definition": "planet"},
68+
{"id": 67, "word": "卫星", "definition": "satellite"},
69+
{"id": 68, "word": "宇航员", "definition": "astronaut"},
70+
{"id": 69, "word": "火箭", "definition": "rocket"},
71+
{"id": 70, "word": "飞船", "definition": "spaceship"},
72+
{"id": 71, "word": "探测器", "definition": "probe"},
73+
{"id": 72, "word": "任务", "definition": "mission"},
74+
{"id": 73, "word": "实验", "definition": "experiment"},
75+
{"id": 74, "word": "理论", "definition": "theory"},
76+
{"id": 75, "word": "发现", "definition": "discovery"},
77+
{"id": 76, "word": "研究", "definition": "research"},
78+
{"id": 77, "word": "数据", "definition": "data"},
79+
{"id": 78, "word": "信息", "definition": "information"},
80+
{"id": 79, "word": "知识", "definition": "knowledge"},
81+
{"id": 80, "word": "智慧", "definition": "wisdom"},
82+
{"id": 81, "word": "思考", "definition": "thinking"},
83+
{"id": 82, "word": "解决", "definition": "solve"},
84+
{"id": 83, "word": "创新", "definition": "innovation"},
85+
{"id": 84, "word": "发明", "definition": "invention"},
86+
{"id": 85, "word": "创造", "definition": "create"},
87+
{"id": 86, "word": "艺术家", "definition": "artist"},
88+
{"id": 87, "word": "画家", "definition": "painter"},
89+
{"id": 88, "word": "音乐家", "definition": "musician"},
90+
{"id": 89, "word": "作家", "definition": "writer"},
91+
{"id": 90, "word": "导演", "definition": "director"},
92+
{"id": 91, "word": "演员", "definition": "actor"},
93+
{"id": 92, "word": "舞蹈", "definition": "dance"},
94+
{"id": 93, "word": "戏剧", "definition": "drama"},
95+
{"id": 94, "word": "文学作品", "definition": "literary work"},
96+
{"id": 95, "word": "小说", "definition": "novel"},
97+
{"id": 96, "word": "诗歌", "definition": "poetry"},
98+
{"id": 97, "word": "散文", "definition": "prose"},
99+
{"id": 98, "word": "历史书", "definition": "history book"},
100+
{"id": 99, "word": "百科全书", "definition": "encyclopedia"},
101+
{"id": 100, "word": "字典", "definition": "dictionary"}
102+
]

data/dutch/words.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2500,4 +2500,3 @@
25002500
"definition": "Affairs"
25012501
}
25022502
]
2503-

data/french/words.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
[
2+
{ "id": 1, "word": "amour", "definition": "love" },
3+
{ "id": 2, "word": "ami", "definition": "friend" },
4+
{ "id": 3, "word": "école", "definition": "school" },
5+
{ "id": 4, "word": "livre", "definition": "book" },
6+
{ "id": 5, "word": "ordinateur", "definition": "computer" },
7+
{ "id": 6, "word": "famille", "definition": "family" },
8+
{ "id": 7, "word": "travail", "definition": "work" },
9+
{ "id": 8, "word": "bonheur", "definition": "happiness" },
10+
{ "id": 9, "word": "eau", "definition": "water" },
11+
{ "id": 10, "word": "nourriture", "definition": "food" },
12+
{ "id": 11, "word": "voiture", "definition": "car" },
13+
{ "id": 12, "word": "film", "definition": "movie" },
14+
{ "id": 13, "word": "musique", "definition": "music" },
15+
{ "id": 14, "word": "ville", "definition": "city" },
16+
{ "id": 15, "word": "voyage", "definition": "travel" },
17+
{ "id": 16, "word": "santé", "definition": "health" },
18+
{ "id": 17, "word": "exercice", "definition": "exercise" },
19+
{ "id": 18, "word": "enseignant", "definition": "teacher" },
20+
{ "id": 19, "word": "élève", "definition": "student" },
21+
{ "id": 20, "word": "téléphone", "definition": "telephone" },
22+
{ "id": 21, "word": "maison", "definition": "house" },
23+
{ "id": 22, "word": "porte", "definition": "door" },
24+
{ "id": 23, "word": "fenêtre", "definition": "window" },
25+
{ "id": 24, "word": "chaise", "definition": "chair" },
26+
{ "id": 25, "word": "table", "definition": "table" },
27+
{ "id": 26, "word": "soupe", "definition": "soup" },
28+
{ "id": 27, "word": "pain", "definition": "bread" },
29+
{ "id": 28, "word": "lait", "definition": "milk" },
30+
{ "id": 29, "word": "fruit", "definition": "fruit" },
31+
{ "id": 30, "word": "légume", "definition": "vegetable" },
32+
{ "id": 31, "word": "enfant", "definition": "child" },
33+
{ "id": 32, "word": "adulte", "definition": "adult" },
34+
{ "id": 33, "word": "étoile", "definition": "star" },
35+
{ "id": 34, "word": "lune", "definition": "moon" },
36+
{ "id": 35, "word": "soleil", "definition": "sun" },
37+
{ "id": 36, "word": "nuage", "definition": "cloud" },
38+
{ "id": 37, "word": "pluie", "definition": "rain" },
39+
{ "id": 38, "word": "vent", "definition": "wind" },
40+
{ "id": 39, "word": "neige", "definition": "snow" },
41+
{ "id": 40, "word": "mer", "definition": "sea" },
42+
{ "id": 41, "word": "montagne", "definition": "mountain" },
43+
{ "id": 42, "word": "rivière", "definition": "river" },
44+
{ "id": 43, "word": "lac", "definition": "lake" },
45+
{ "id": 44, "word": "plage", "definition": "beach" },
46+
{ "id": 45, "word": "forêt", "definition": "forest" },
47+
{ "id": 46, "word": "désert", "definition": "desert" },
48+
{ "id": 47, "word": "île", "definition": "island" },
49+
{ "id": 48, "word": "village", "definition": "village" },
50+
{ "id": 49, "word": "citoyen", "definition": "citizen" },
51+
{ "id": 50, "word": "gens", "definition": "people" }
52+
]

0 commit comments

Comments
 (0)