This project is a JavaScript application designed to correct language-specific errors in JSON files. It processes JSON files stored in nested directories, identifies language-specific errors using reference CSV files (one for Arabic and one for English), and replaces incorrect words with their correct counterparts. The corrected JSON files are saved in their original locations, and the tool logs the changes made.
- Recursive JSON File Search: Scans nested directories to locate JSON files.
- Language-Specific Corrections: Uses separate CSV files for Arabic (
ar.csv
) and English (en.csv
) corrections. - Dynamic Correction Application: Applies corrections based on the language identified in the JSON file name.
- Logging: Provides detailed logs about the corrections performed and the file paths.
- Node.js (version 14 or higher)
- npm (Node Package Manager)
-
Clone the Repository:
git clone https://github.com/your-repo/language-correction-tool.git cd language-correction-tool
-
Install Dependencies: Install the required npm packages:
npm install
-
Prepare CSV Files:
- Place your Arabic corrections in
reference/ar.csv
. - Place your English corrections in
reference/en.csv
.
The CSV files should have the following format:
Wrong,Correct incorrect_word,correct_word
- Place your Arabic corrections in
-
Set Up JSON Files:
- Place your JSON files in the desired directory (e.g.,
D:\Erp\Langs
). - Ensure the JSON file names contain
ar
for Arabic oren
for English to identify the language.
- Place your JSON files in the desired directory (e.g.,
-
Update the
rootDir
andcsvFiles
paths in theindex.js
file to match your directory structure:import { join } from "path"; import { processJsonFiles } from "./src/processJsonFiles.js"; const rootDir = "D:\\Erp\\Langs"; // Update this path to your JSON files directory const csvFiles = { ar: join(process.cwd(), "reference", "ar.csv"), // Path to Arabic corrections CSV en: join(process.cwd(), "reference", "en.csv"), // Path to English corrections CSV }; // Run the script processJsonFiles(csvFiles, rootDir);
-
Run the application:
node index.js
- The tool will log the following:
- ✅ Corrected file saved:
[file path]
(for files with corrections). - ℹ️ No corrections needed:
[file path]
(for files without corrections). - ❌ Error messages for any issues encountered.
- ✅ Corrected file saved:
language-correction-tool/
├── src/
│ ├── correctJsonValues.js # Recursively corrects JSON values
│ ├── correctString.js # Corrects a single string using the corrections map
│ ├── findJsonFiles.js # Recursively finds JSON files in a directory
│ ├── loadCorrections.js # Loads corrections from CSV files
│ └── processJsonFiles.js # Main script to process JSON files
├── reference/
│ ├── ar.csv # Arabic corrections CSV
│ └── en.csv # English corrections CSV
├── index.js # Entry point for the application
├── package.json # Project dependencies and configuration
└── README.md # Project documentation
Recursively traverses a JSON object and corrects string values using the provided corrections map.
Corrects a single string by replacing incorrect words with their correct counterparts using a regex pattern.
Recursively searches a directory for JSON files and returns their paths.
Loads corrections from a CSV file into a Map
object for quick lookup.
Orchestrates the process:
- Finds JSON files.
- Loads corrections from CSV files.
- Applies corrections to JSON files.
- Saves corrected JSON files and logs the results.
Wrong,Correct
كلمة_خاطئة,كلمة_صحيحة
خطأ,تصحيح
Wrong,Correct
incorrect_word,correct_word
error,correction
{
"message": "This is an incorrect_word example."
}
{
"message": "This is a correct_word example."
}
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Submit a pull request with a detailed description of your changes.
This project is licensed under the Apache-2.0 License. See the LICENSE file for details.
For any questions or issues, please open an issue on the GitHub repository.