@@ -426,6 +426,251 @@ gpt-po-translator --folder ./locales --lang de --no-ai-comment
426426
427427---
428428
429+ ## Using Ollama (Local AI Provider)
430+
431+ ### Overview
432+
433+ Ollama allows you to run AI models locally on your machine, providing:
434+ - ** Privacy** : All translations happen locally, no data sent to cloud services
435+ - ** Cost** : No API fees - completely free
436+ - ** Offline** : Works without internet connection
437+ - ** Control** : Full control over model and infrastructure
438+
439+ ### Prerequisites
440+
441+ 1 . ** Install Ollama**
442+ ``` bash
443+ # macOS/Linux
444+ curl -fsSL https://ollama.com/install.sh | sh
445+
446+ # Or download from https://ollama.com
447+ ```
448+
449+ 2 . ** Pull a model**
450+ ``` bash
451+ # For multilingual (Arabic, Chinese, etc.)
452+ ollama pull qwen2.5
453+
454+ # For European languages only
455+ ollama pull llama3.2
456+
457+ # Other options
458+ ollama pull llama3.1 # Better quality, slower
459+ ollama pull mistral # Good for European languages
460+ ```
461+
462+ 3 . ** Start Ollama** (if not already running)
463+ ``` bash
464+ ollama serve
465+ ```
466+
467+ ### Basic Usage
468+
469+ ``` bash
470+ # Latin scripts (English, French, Spanish, etc.) - can use bulk mode
471+ gpt-po-translator --provider ollama --folder ./locales --bulk
472+
473+ # Non-Latin scripts (Arabic, Chinese, Japanese, etc.) - omit --bulk for better quality
474+ gpt-po-translator --provider ollama --model qwen2.5 --folder ./locales --lang ar
475+
476+ # Specify a model
477+ gpt-po-translator --provider ollama --model llama3.1 --folder ./locales
478+
479+ # List available models
480+ gpt-po-translator --provider ollama --list-models
481+ ```
482+
483+ > ** ⚠️ Important:** For ** non-Latin languages** , ** omit the ` --bulk ` flag** . Local models struggle with JSON formatting for Arabic/Chinese/etc., resulting in poor translation quality or errors. Single-item mode is more reliable.
484+
485+ ### Configuration
486+
487+ #### Option 1: Environment Variable
488+
489+ ``` bash
490+ export OLLAMA_BASE_URL=" http://localhost:11434"
491+ gpt-po-translator --provider ollama --folder ./locales --bulk
492+ ```
493+
494+ #### Option 2: CLI Arguments
495+
496+ ``` bash
497+ # Custom port
498+ gpt-po-translator --provider ollama \
499+ --ollama-base-url http://localhost:8080 \
500+ --folder ./locales --bulk
501+
502+ # Increase timeout for slow models
503+ gpt-po-translator --provider ollama \
504+ --ollama-timeout 300 \
505+ --folder ./locales --bulk
506+ ```
507+
508+ #### Option 3: Config File
509+
510+ Add to your ` pyproject.toml ` :
511+
512+ ``` toml
513+ [tool .gpt-po-translator .provider .ollama ]
514+ base_url = " http://localhost:11434"
515+ model = " llama3.2"
516+ timeout = 120
517+
518+ [tool .gpt-po-translator ]
519+ bulk_mode = true
520+ bulk_size = 50
521+ ```
522+
523+ Then simply run:
524+ ``` bash
525+ gpt-po-translator --provider ollama --folder ./locales
526+ ```
527+
528+ ### Advanced Scenarios
529+
530+ #### Remote Ollama Server
531+
532+ Run Ollama on a different machine:
533+
534+ ``` bash
535+ # On the Ollama server (192.168.1.100)
536+ ollama serve --host 0.0.0.0
537+
538+ # On your machine
539+ gpt-po-translator --provider ollama \
540+ --ollama-base-url http://192.168.1.100:11434 \
541+ --folder ./locales --bulk
542+ ```
543+
544+ Or set in ` pyproject.toml ` :
545+ ``` toml
546+ [tool .gpt-po-translator .provider .ollama ]
547+ base_url = " http://192.168.1.100:11434"
548+ ```
549+
550+ #### Docker with Ollama
551+
552+ Run Ollama on your host machine, then use Docker with ` --network host ` :
553+
554+ ``` bash
555+ # 1. Start Ollama on host
556+ ollama serve
557+
558+ # 2. Pull a model on host
559+ ollama pull qwen2.5
560+
561+ # 3. Run translator in Docker (Linux/macOS)
562+ docker run --rm \
563+ -v $( pwd) :/data \
564+ --network host \
565+ ghcr.io/pescheckit/python-gpt-po:latest \
566+ --provider ollama \
567+ --folder /data
568+
569+ # macOS/Windows Docker Desktop: use host.docker.internal
570+ docker run --rm \
571+ -v $( pwd) :/data \
572+ ghcr.io/pescheckit/python-gpt-po:latest \
573+ --provider ollama \
574+ --ollama-base-url http://host.docker.internal:11434 \
575+ --folder /data
576+ ```
577+
578+ ** With config file:**
579+ ``` bash
580+ # Add Ollama config to pyproject.toml in your project
581+ docker run --rm \
582+ -v $( pwd) :/data \
583+ -v $( pwd) /pyproject.toml:/data/pyproject.toml \
584+ --network host \
585+ ghcr.io/pescheckit/python-gpt-po:latest \
586+ --provider ollama \
587+ --folder /data
588+ ```
589+
590+ ### Performance Considerations
591+
592+ ** Pros:**
593+ - No API costs
594+ - Privacy and data control
595+ - No rate limits
596+ - Offline capability
597+
598+ ** Cons:**
599+ - Quality varies by model (may not match GPT-4)
600+ - Requires local resources (RAM, GPU recommended)
601+ - Initial setup needed (install Ollama, pull models)
602+
603+ ** Performance Tips:**
604+ 1 . ** Use GPU** : Install Ollama with GPU support for 10-100x speedup
605+ 2 . ** Choose appropriate models** :
606+ - Small projects: ` llama3.2 ` (fast, good quality)
607+ - Better quality: ` llama3.1 ` (slower, better accuracy)
608+ - Multilingual: ` qwen2.5 ` (excellent for non-Latin scripts like Arabic, Chinese, etc.)
609+ - Specialized: ` mistral ` , ` gemma2 `
610+ 3 . ** Increase timeout** for large models: ` --ollama-timeout 300 `
611+ 4 . ** Bulk mode vs Single mode** :
612+ - ** Bulk mode (` --bulk ` )** : Faster but requires model to return valid JSON - recommended for cloud providers
613+ - ** Single mode (no ` --bulk ` )** : Slower but more reliable for local models, especially with non-Latin scripts
614+ - For Ollama with languages like Arabic/Chinese/Japanese, ** omit ` --bulk ` ** for better quality
615+
616+ ### Recommended Models for Translation
617+
618+ | Model | Size | Speed | Quality | Best For |
619+ | -------| ------| -------| ---------| ----------|
620+ | ` llama3.2 ` | 3B | ⚡⚡⚡ Fast | ⭐⭐⭐ Good | General use, Latin scripts only |
621+ | ` llama3.1 ` | 8B | ⚡⚡ Medium | ⭐⭐⭐⭐ Better | Better quality, medium projects |
622+ | ` qwen2.5 ` | 7B | ⚡⚡ Medium | ⭐⭐⭐⭐ Excellent | ** Multilingual** (Arabic, Chinese, etc.) |
623+ | ` mistral ` | 7B | ⚡⚡ Medium | ⭐⭐⭐ Good | European languages |
624+ | ` gemma2 ` | 9B | ⚡ Slower | ⭐⭐⭐⭐ Better | High quality translations |
625+
626+ ** Note:** For non-Latin scripts (Arabic, Chinese, Japanese, etc.), use ` qwen2.5 ` or larger models ** without ` --bulk ` flag** for best results.
627+
628+ ### Troubleshooting
629+
630+ ** "Cannot connect to Ollama"**
631+ ``` bash
632+ # Check if Ollama is running
633+ curl http://localhost:11434/api/tags
634+
635+ # Start Ollama
636+ ollama serve
637+
638+ # Check if running on different port
639+ ollama serve --help
640+ ```
641+
642+ ** Slow translations**
643+ - Use GPU-enabled Ollama installation
644+ - Choose a smaller model (` llama3.2 ` instead of ` llama3.1 ` )
645+ - Increase ` --bulksize ` to batch more entries together
646+ - Close other applications to free up RAM
647+
648+ ** Model not found**
649+ ``` bash
650+ # List installed models
651+ ollama list
652+
653+ # Pull the model
654+ ollama pull llama3.2
655+ ```
656+
657+ ** Timeout errors**
658+ ``` bash
659+ # Increase timeout
660+ gpt-po-translator --provider ollama --ollama-timeout 300 --folder ./locales
661+ ```
662+
663+ ### Configuration Priority
664+
665+ Ollama settings are loaded in this order (highest to lowest):
666+
667+ 1 . ** CLI arguments** : ` --ollama-base-url ` , ` --ollama-timeout `
668+ 2 . ** Environment variables** : ` OLLAMA_BASE_URL `
669+ 3 . ** Config file** : ` pyproject.toml ` under ` [tool.gpt-po-translator.provider.ollama] `
670+ 4 . ** Defaults** : ` http://localhost:11434 ` , timeout ` 120s `
671+
672+ ---
673+
429674## Whitespace Handling in Translations
430675
431676### Overview
0 commit comments