Package org.daiitech.naftah.utils.script
Class TransliterationGenerator
java.lang.Object
org.daiitech.naftah.utils.script.TransliterationGenerator
A utility class that scans Java class names, splits them into component words,
translates those words from English to Arabic using an external translation API,
and generates a
.properties file containing the transliterations.
The generated file maps lowercase English words to their Arabic transliterations (with Unicode escaping), suitable for use in localization, transliteration engines, or machine learning pipelines.
Translation is only performed on words that:
- Are at least two characters long
- Are not numeric-only
- Are not blank or null
- Do not already exist in a custom rules bundle
- Have valid Arabic output (fully Arabic characters)
Example usage:
$ java TransliterationGenerator
The resulting file will be saved as:
transliteration_ar.properties
- Author:
- Chakib Daii
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor to prevent instantiation. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidMain entry point.private static StringtranslateWord(HttpClient client, String word) Translates a single English word to Arabic using the configured translation API.
-
Field Details
-
SOURCE_LANG
The source language code used in translation requests (e.g., "en"). -
TARGET_LANG
The target language code used in translation requests (e.g., "ar"). -
API_URL
The base URL for the translation API. This should point to a service accepting POST requests with URL-encoded parameters for source/target languages and the query string.
-
-
Constructor Details
-
TransliterationGenerator
private TransliterationGenerator()Private constructor to prevent instantiation. Always throws aNaftahBugErrorwhen called.
-
-
Method Details
-
main
Main entry point. it- Scans Java class names in the project
- Splits class names into individual words
- Translates each word from English to Arabic via an external API
- Validates and filters the translations
- Saves the final mapping to a
transliteration_ar.propertiesfile
- Parameters:
args- command-line arguments (unused)- Throws:
IOException- if the translation API or file output failsInterruptedException- if the HTTP request is interrupted
-
translateWord
private static String translateWord(HttpClient client, String word) throws IOException, InterruptedException Translates a single English word to Arabic using the configured translation API.This method sends a POST request to the translation endpoint with URL-encoded parameters. It then extracts the translated string from the response body.
Assumes the API returns a JSON string with the format:
{"translatedText":"<arabic_text>"}- Parameters:
client- theHttpClientinstance to use for the requestword- the English word to translate- Returns:
- the Arabic translation of the word, or an empty string if translation fails
- Throws:
IOException- if the HTTP request failsInterruptedException- if the request is interrupted
-