Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ cd python-gpt-po
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python -m python_gpt_po.main --folder test --lang nl --bulk --provider="deepseek" --list-models
python -m python_gpt_po.main --provider="deepseek" --list-models
```

## API Key Configuration
Expand Down Expand Up @@ -96,6 +96,8 @@ For a detailed explanation of all available parameters and a deep dive into the
- `--bulk`: Enable bulk translation mode.
- `--bulksize`: Set the number of entries per bulk translation (default is 50).
- `--model`: Specify the translation model (defaults are provider-specific).
- `--provider`: Specify the AI provider (openai, anthropic, or deepseek).
- `--list-models`: List available models for the selected provider. This is the only command that can be used without `--folder` and `--lang`.
- `--api_key`: API key for translation; can also be provided via environment variable.
- `--folder-language`: Infer the target language from the folder structure.

Expand Down Expand Up @@ -186,7 +188,7 @@ docker run -v $(pwd):/data -e OPENAI_API_KEY="your_key" ghcr.io/pescheckit/pytho
# Use a specific Python version (3.12)
docker run -v $(pwd):/data -e OPENAI_API_KEY="your_key" ghcr.io/pescheckit/python-gpt-po:latest-py3.12 --folder /data --lang fr

# List available models
# List available models (no need for --folder or --lang)
docker run -e OPENAI_API_KEY="your_key" ghcr.io/pescheckit/python-gpt-po:latest --provider openai --list-models
```

Expand Down
3 changes: 3 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ if [ $# -eq 0 ]; then
echo " # MacOS example"
echo " docker run -v /Users/username/Documents/translations:/input -e OPENAI_API_KEY=<your_key> ghcr.io/pescheckit/python-gpt-po --folder /input --lang fr,es"
echo
echo " # List available models (no need for --folder or --lang)"
echo " docker run -e OPENAI_API_KEY=<your_key> ghcr.io/pescheckit/python-gpt-po --provider openai --list-models"
echo
echo "For full documentation, visit: https://github.com/pescheckit/python-gpt-po"
exit 0
fi
Expand Down
4 changes: 2 additions & 2 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ Below is a detailed explanation of all command-line arguments:
*Behind the scenes:* The chosen model is passed along to the provider’s API calls. If the model is not available, a warning is logged and the default is used.

- **`--list-models`**
*Description:* Lists all available models for the selected provider and exits without processing any files.
*Behind the scenes:* Makes a test API call to retrieve a list of models and prints them to the console.
*Description:* Lists all available models for the selected provider and exits without processing any files. This is the only command that doesn't require `--folder` and `--lang` parameters.
*Behind the scenes:* Makes a test API call to retrieve a list of models and prints them to the console. When this flag is provided, the CLI parser automatically makes the usually required parameters optional.

- **`--openai-key`**
*Description:* Provides the OpenAI API key directly as a command-line argument (alternative to using `--api_key` or the environment variable).
Expand Down
23 changes: 15 additions & 8 deletions python_gpt_po/utils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,28 @@ def parse_args():
Returns:
argparse.Namespace: Parsed arguments
"""
# First pass - check if list-models is in args
# This allows us to make folder and lang not required when listing models
list_models_present = False
for arg in sys.argv:
if arg in ("--list-models", "--version"):
list_models_present = True
break
parser = CustomArgumentParser(
description="Translate .po files using AI language models",
epilog="""
Examples:
# Basic usage with OpenAI
python po_translator.py --folder ./locales --lang fr,es,de
gpt-po-translator --folder ./locales --lang fr,es,de

# Use Anthropic with detailed language names
python po_translator.py --folder ./i18n --lang nl,de --detail-lang "Dutch,German" --provider anthropic
gpt-po-translator --folder ./i18n --lang nl,de --detail-lang "Dutch,German" --provider anthropic

# List available models for a provider
python po_translator.py --provider deepseek --list-models
# List available models for a provider (no need for --folder or --lang)
gpt-po-translator --provider deepseek --list-models

# Process multiple translations in bulk with a specific model
python po_translator.py --folder ./locales --lang ja,ko --bulk --model gpt-4
gpt-po-translator --folder ./locales --lang ja,ko --bulk --model gpt-4
""",
formatter_class=lambda prog: argparse.RawDescriptionHelpFormatter(prog, max_help_position=35, width=100)
)
Expand All @@ -62,16 +69,16 @@ def parse_args():
api_group = parser.add_argument_group('API Keys')
advanced_group = parser.add_argument_group('Advanced Options')

# Required arguments
# Required arguments (not required if listing models)
required_group.add_argument(
"-f", "--folder",
required=True,
required=(not list_models_present),
metavar="FOLDER",
help="Input folder containing .po files"
)
required_group.add_argument(
"-l", "--lang",
required=True,
required=(not list_models_present),
metavar="LANG",
help="Comma-separated language codes to translate (e.g., fr,es,de)"
)
Expand Down