Class TransliterationGenerator

java.lang.Object
org.daiitech.naftah.utils.script.TransliterationGenerator

public final class TransliterationGenerator extends Object
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 Details

    • SOURCE_LANG

      private static String SOURCE_LANG
      The source language code used in translation requests (e.g., "en").
    • TARGET_LANG

      private static String TARGET_LANG
      The target language code used in translation requests (e.g., "ar").
    • API_URL

      private static String 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 a NaftahBugError when called.
  • Method Details

    • main

      public static void main(String[] args) throws IOException, InterruptedException
      Main entry point. it
      1. Scans Java class names in the project
      2. Splits class names into individual words
      3. Translates each word from English to Arabic via an external API
      4. Validates and filters the translations
      5. Saves the final mapping to a transliteration_ar.properties file
      Parameters:
      args - command-line arguments (unused)
      Throws:
      IOException - if the translation API or file output fails
      InterruptedException - 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 - the HttpClient instance to use for the request
      word - 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 fails
      InterruptedException - if the request is interrupted