A simple command-line translation program using Node.js.
- install the dependencys
npm install - to run the program
node ./main.jsornpm start
You can also create a
shellscript and place it in thebindirectory or any directory included in yourPATH.
If you run the program without any flags, it uses the following default values:
- Source Language:
en - Target Language:
ar - Text:
hello world
You can pass command-line flags to translate a single text immediately. If no flags are used, the program enters interactive mode where you can translate multiple texts in different languages.
-lang <string>: Source language (e.g.,en,fr,es)-target <string>: Target language (e.g.,ar,de,zh)-text <string>: The text you want to translate
If no flags are provided, the program starts an interactive loop where you’ll be prompted for the following each time:
lang:
target:
text:
It will then translate the provided text accordingly.
To exit the console, type .exit at any prompt.
If any errors occur during translation, they will be logged to the console.