Skip to content

Commit

Permalink
refactor(core): ♻️ do refactor and add multiple language support
Browse files Browse the repository at this point in the history
refactor(core): ♻️ do refactor and add more language support
  • Loading branch information
mcnaveen authored Aug 25, 2024
2 parents ee71f10 + 039ad1b commit e60af96
Show file tree
Hide file tree
Showing 22 changed files with 4,130 additions and 254 deletions.
68 changes: 37 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,29 @@

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

## 🌍 Languages

- English
- Dutch
- Spanish
- French
- Chinese
- Japanese

## 🚀 API

- Free API - `https://random-words-api.vercel.app/word`
- English Random Words - `https://random-words-api.vercel.app/word`
- Dutch Random Words - `https://random-words-api.vercel.app/word/dutch`
- Get Pronunciation for a Word - `https://random-words-api.vercel.app/pronounce/`
- Spanish Random Words - `https://random-words-api.vercel.app/word/spanish`
- French Random Words - `https://random-words-api.vercel.app/word/french`
- Chinese Random Words - `https://random-words-api.vercel.app/word/chinese`
- Japanese Random Words - `https://random-words-api.vercel.app/word/japanese`
- Turkish Random Words - `https://random-words-api.vercel.app/word/turkish`

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

## 🎛 Route Options

- Base URL: `https://random-words-api.vercel.app/word`

## 🎛 Route Options (English Only)
- Base URL: `https://random-words-api.vercel.app/word/english`
```text
- /noun
- /sentence
Expand Down Expand Up @@ -68,28 +79,6 @@
]
```

## 🌐 Sample Pronunciation Request

- API: `https://random-words-api.vercel.app/pronounce`
- Method: `POST`

```sh
POST http://localhost:3000/pronounce
Content-Type: application/json

{
"word": "This is amazing"
}
```

## 📣 Sample Pronunciation Response

```json
{
"pronunciation": "this is amasink"
}
```

- Check [api.rest](/test/api.rest) file for more details

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

```sh
# Clone the Repo
git clone https://github.com/mcnaveen/Random-Words-API random-words
git clone https://github.com/mcnaveen/random-words-api random-words-api

# Cd into Directory
cd random-words

# Install Dependencies
yarn install
npm install

# Start the Development Server
yarn start
npm run dev
```

## 🔀 Deploying to Heroku
Expand All @@ -132,6 +121,23 @@ OR
Project - Give Forked Repo URL - Go Live
```

## 🔐 Rate Limit

- To configure the rate limit, edit the `utils/index.js` file
- Look for `limiter` variable
- `max` is the maximum number of requests allowed in a given time window
- `windowMs` is the time window in milliseconds
- `message` is the message to be returned when the rate limit is exceeded

## 😇 Add New Language
- Create a new folder in `data` with the full language name `ex: english`
- Add the words in the `words.json` file
- It should be an array of objects with `id`, `word`, and `definition` properties
- The `id` should be a unique number for each word
- The `word` should be the word in the language
- The `definition` should be the definition of the word in English
- The `pronunciation` should be the pronunciation of the word in the language (Optional)

## :question: How to Contribute?

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

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

0 comments on commit e60af96

Please sign in to comment.