Skip to main content

Professional localization analyzer for Swift/iOS projects with auto-translation

Project description

Localization Analyzer

๐ŸŒ Professional localization analysis and management tool for multi-platform projects.

Python Version License Version

Why localization-analyzer?

Unlike other tools that only handle one aspect of localization, this is an all-in-one CLI that covers the entire localization workflow:

Feature localization-analyzer BartyCrouch translate-toolkit
Analyze hardcoded strings โœ… โœ… โŒ
Auto-translate โœ… โœ… โœ…
Modular .strings support โœ… โŒ โŒ
Health scoring โœ… โŒ โŒ
Dynamic key detection โœ… โŒ โŒ
Stats & reporting โœ… โŒ โœ…
Diff between languages โœ… โŒ โœ…
Validation โœ… โŒ โœ…
Sync languages โœ… โœ… โœ…
Interactive HTML dashboard โœ… โŒ โŒ
Built-in report server โœ… โŒ โŒ

Features

Analysis & Detection

  • ๐Ÿ” Smart Detection: Find hardcoded strings automatically
  • ๐ŸŽฏ Dynamic Key Detection: Skip false positives like activity.\(id)
  • ๐Ÿ“Š Health Score: Track localization quality (0-100)
  • ๐Ÿ”‘ Key Management: Detect missing and dead keys

Translation & Management

  • ๐ŸŒ Auto-Translate: Google Translate integration (free, no API key)
  • ๐Ÿ“ฆ Modular Support: Handle AI.strings, Common.strings, etc.
  • โž• Add Languages: Create new language with auto-translation
  • ๐Ÿ”„ Sync: Keep all languages in sync

Validation & Reporting

  • โœ… Validate: Check syntax, placeholders, duplicates
  • ๐Ÿ“ˆ Stats: Completion percentages per language
  • ๐Ÿ”€ Diff: Compare two languages
  • ๐Ÿ“‹ Reports: JSON, Markdown, Console, Interactive HTML Dashboard
  • ๐ŸŒ Live Preview: Built-in server to view reports in browser

Developer Experience

  • โšก Fast: Multi-threaded analysis
  • ๐Ÿ’พ Cache: Translation caching for speed
  • ๐Ÿ”ง Auto-Fix: Automatically fix hardcoded strings
  • ๐Ÿ”„ CI/CD Ready: Exit codes for pipeline integration

Installation

From PyPI (recommended)

pip install localization-analyzer

From Source

git clone https://github.com/sezginpak/localization-analyzer.git
cd localization-analyzer
pip install -e .

Quick Start

1. Initialize Configuration

cd your-project
localization-analyzer init --framework swift

This creates .localization.yml in your project root.

2. Run Analysis

localization-analyzer analyze --verbose

3. View Interactive HTML Report

# Generate HTML report and open in browser
localization-analyzer analyze --serve

# Enable edit mode (inline editing + batch editing)
localization-analyzer analyze --serve --edit

# Or just generate HTML file
localization-analyzer analyze --html report.html

Edit Mode Features:

  • ๐Ÿ–Š๏ธ Inline Edit: Double-click any text to edit and save directly
  • โ˜‘๏ธ Selection: Check items to select for batch operations
  • ๐Ÿ“ Batch Edit: Edit multiple translations at once in a modal
  • ๐Ÿ’พ Auto-Save: Changes are saved directly to .strings files

4. Check Statistics

# View completion stats for all languages
localization-analyzer stats

# Show missing keys per language
localization-analyzer stats --missing

# Export as JSON for CI/CD
localization-analyzer stats --json

5. Add New Language with Translation

# Add Spanish with auto-translation from English
localization-analyzer lang --add es --translate

# Preview first (dry-run)
localization-analyzer lang --add es --translate --dry-run

6. Translate Missing Keys

# Translate missing keys from English to German
localization-analyzer translate --source en --target de

# Force re-translate all keys
localization-analyzer translate --source en --target de --force

7. Sync Languages

# Sync all languages with English (source)
localization-analyzer sync --translate

# Sync specific language
localization-analyzer sync --lang de --translate

8. Compare Languages

# Diff between English and Spanish
localization-analyzer diff --source en --target es

# Fail if missing keys (for CI)
localization-analyzer diff --source en --target es --fail-on-missing

9. Validate Files

# Full validation
localization-analyzer validate --consistency

# Check specific aspects
localization-analyzer validate --syntax
localization-analyzer validate --placeholders

Commands Reference

Command Description
init Initialize configuration file
analyze Run comprehensive analysis
stats Show localization statistics
translate Auto-translate keys
lang Manage languages (add/remove/list/sync)
sync Synchronize all languages
diff Compare two languages
validate Validate localization files
missing Find and fix missing keys
fix Auto-fix hardcoded strings
generate Generate L10n enum
discover Auto-discover tables/modules

Configuration

Create .localization.yml in your project root:

project:
  name: MyApp
  framework: swift

paths:
  source: .
  localization: ./Resources
  exclude:
    - build/
    - Pods/
    - .build/

languages:
  primary: en
  supported:
    - en
    - es
    - de
    - tr
    - pt

# Optional: Module mapping
tables:
  AI: AI
  Common: Common
  Garden: Garden

auto_fix:
  enabled: true
  min_priority: 8
  backup: true

reports:
  formats:
    - json
    - console
    - html          # Interactive HTML dashboard
  output: ./localization_reports/

CI/CD Integration

GitHub Actions

name: Localization Check

on: [push, pull_request]

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.11'

      - name: Install localization-analyzer
        run: pip install localization-analyzer

      - name: Check localization health
        run: localization-analyzer analyze --fail-below 90

      - name: Validate syntax
        run: localization-analyzer validate --syntax

      - name: Check missing translations
        run: localization-analyzer stats --ci --threshold 95

GitLab CI

localization:
  image: python:3.11
  script:
    - pip install localization-analyzer
    - localization-analyzer analyze --fail-below 90
    - localization-analyzer validate --consistency

Python API

from localization_analyzer import LocalizationAnalyzer
from localization_analyzer.frameworks import SwiftAdapter
from localization_analyzer.core.file_manager import LocalizationFileManager
from pathlib import Path

# Create analyzer
adapter = SwiftAdapter()
analyzer = LocalizationAnalyzer(
    project_dir=Path('.'),
    adapter=adapter
)

# Run analysis
result = analyzer.analyze()

# Check results
print(f"Health Score: {result.health.score}/100")
print(f"Localization Rate: {result.health.localization_rate}%")
print(f"Hardcoded Strings: {len(result.hardcoded_strings)}")

# File manager for direct key management
file_manager = LocalizationFileManager(adapter, Path('./Resources'))
file_manager.load_all_keys()

# Add a key to specific module
file_manager.add_key(
    key="new.feature.title",
    translations={"en": "New Feature", "es": "Nueva Funciรณn"},
    module="Common"
)

Supported Frameworks

Framework Status File Format
Swift/iOS โœ… Full Support .strings (modular)
React ๐Ÿšง Coming Soon .json
Flutter ๐Ÿšง Coming Soon .arb
Android ๐Ÿšง Coming Soon .xml

Key Features Explained

Health Score (0-100)

Calculated based on:

  • Localization Rate: % of localized vs hardcoded strings
  • Missing Keys: Keys used in code but not in files
  • Dead Keys: Keys in files but not used in code
  • Consistency: Same keys across all languages

Dynamic Key Detection

Smart detection skips false positives:

// These won't be flagged as missing:
"activity.\(id)".localized      // Dynamic key
"style.\(rawValue)".localized   // Dynamic key

Modular .strings Support

Works with modern Swift projects:

Resources/
โ”œโ”€โ”€ en.lproj/
โ”‚   โ”œโ”€โ”€ AI.strings
โ”‚   โ”œโ”€โ”€ Common.strings
โ”‚   โ”œโ”€โ”€ Garden.strings
โ”‚   โ””โ”€โ”€ Settings.strings
โ””โ”€โ”€ es.lproj/
    โ”œโ”€โ”€ AI.strings
    โ”œโ”€โ”€ Common.strings
    โ””โ”€โ”€ ...

Translation Caching

Translations are cached to avoid re-translating:

.localization_cache/
โ””โ”€โ”€ translations.json

Development

Setup Development Environment

git clone https://github.com/sezginpak/localization-analyzer.git
cd localization-analyzer

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

Project Structure

localization-analyzer/
โ”œโ”€โ”€ localization_analyzer/
โ”‚   โ”œโ”€โ”€ core/              # Analysis engine
โ”‚   โ”‚   โ”œโ”€โ”€ analyzer.py    # Main analyzer
โ”‚   โ”‚   โ””โ”€โ”€ file_manager.py # File I/O
โ”‚   โ”œโ”€โ”€ frameworks/        # Framework adapters
โ”‚   โ”‚   โ””โ”€โ”€ swift.py       # Swift/iOS adapter
โ”‚   โ”œโ”€โ”€ features/          # Feature modules
โ”‚   โ”‚   โ”œโ”€โ”€ translator.py  # Auto-translation
โ”‚   โ”‚   โ”œโ”€โ”€ validator.py   # Validation
โ”‚   โ”‚   โ”œโ”€โ”€ stats.py       # Statistics
โ”‚   โ”‚   โ”œโ”€โ”€ diff.py        # Language diff
โ”‚   โ”‚   โ””โ”€โ”€ sync.py        # Sync languages
โ”‚   โ”œโ”€โ”€ reports/           # Report generators
โ”‚   โ””โ”€โ”€ utils/             # Utilities
โ”œโ”€โ”€ tests/                 # Test suite (40+ tests)
โ””โ”€โ”€ examples/              # Example projects

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

MIT License - see LICENSE file for details.

Author

Sezgin Paksoy

Support


Made with โค๏ธ for the iOS/Swift developer community

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

localization_analyzer-1.17.0.tar.gz (143.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

localization_analyzer-1.17.0-py3-none-any.whl (115.2 kB view details)

Uploaded Python 3

File details

Details for the file localization_analyzer-1.17.0.tar.gz.

File metadata

  • Download URL: localization_analyzer-1.17.0.tar.gz
  • Upload date:
  • Size: 143.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for localization_analyzer-1.17.0.tar.gz
Algorithm Hash digest
SHA256 d7bdf3d72666485873a8af92e501220fb88c3abaee1880152ad892c3b22c0f85
MD5 639e6cf4af291ef52e0ec13a5c4748d9
BLAKE2b-256 6feef5a8f92f72e8df24093096db6af5a3e35b3b0f4aae8de2a1231ca1f63775

See more details on using hashes here.

File details

Details for the file localization_analyzer-1.17.0-py3-none-any.whl.

File metadata

File hashes

Hashes for localization_analyzer-1.17.0-py3-none-any.whl
Algorithm Hash digest
SHA256 184f78e425c1b217de2ca5b99e09b7dc00615ea907a9fd729c52e528dd5b7f57
MD5 ef5904bd39400f6e858c8f33978e1be2
BLAKE2b-256 02e0a4630623c3c660d77136e481898c97da65ddc8cc1f83ad770a80f8bb2345

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page