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 โœ… โœ… โœ…

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 output

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. 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

4. 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

5. 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

6. Sync Languages

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

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

7. 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

8. 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
  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.13.1.tar.gz (119.1 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.13.1-py3-none-any.whl (100.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: localization_analyzer-1.13.1.tar.gz
  • Upload date:
  • Size: 119.1 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.13.1.tar.gz
Algorithm Hash digest
SHA256 ddc097c4d8a1b943565e5ad34b4040e5256c1cd80b3298102be444bd414db4de
MD5 5020ab5689da0e0f3aea05138ea325b6
BLAKE2b-256 892f2059d5dc3c6d0e2ee1ea03d514e387f9073293eb53a5ccd47abb21e40c84

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for localization_analyzer-1.13.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7f1c18dd7437f348c4384b444f3d7c057806c688578e3f96822c63f903a03c92
MD5 f656b934de5be247ac0569c458ae83c9
BLAKE2b-256 cb92381025ad65096ed75a1af75c3e400409a52c2852cb228f00f1abe0916a7e

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