Metadata-Version: 2.4
Name: localelens
Version: 0.1.1
Summary: Offline JSON and ARB translation resource quality checks
License-Expression: MIT
Project-URL: Homepage, https://github.com/ahmedsaeed1-eng/localelens
Project-URL: Issues, https://github.com/ahmedsaeed1-eng/localelens/issues
Keywords: localization,i18n,arb,json,qa
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# LocaleLens

<img src="assets/logo.svg" alt="LocaleLens: paired language keys" width="88" align="right">

**Every key. Every locale. No network.**

Offline localization QA for JSON and Flutter ARB resources.

`v0.1.1` · Python 3.10+ · zero runtime dependencies · [MIT](LICENSE)

[![GitHub stars](https://img.shields.io/github/stars/ahmedsaeed1-eng/localelens?style=flat-square&color=F5CF70)](https://github.com/ahmedsaeed1-eng/localelens/stargazers) ![Offline](https://img.shields.io/badge/runtime-offline-073B3B?style=flat-square) ![11 tests passed locally](https://img.shields.io/badge/local%20tests-11%20passed-238A66?style=flat-square) [![CI](https://github.com/ahmedsaeed1-eng/localelens/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/ahmedsaeed1-eng/localelens/actions/workflows/ci.yml) [![MIT](https://img.shields.io/badge/license-MIT-087f8c?style=flat-square)](LICENSE)

---

## The missing translation

An English settings screen has a Cancel button. Its Arabic resource has the same key, but the value is empty. A key-count comparison would miss the problem.

| Key | English (en) | العربية (ar) |
|---|---|---:|
| welcome | Hello {name}! | <span dir="rtl">أهلاً {name}!</span> |
| settings.save | Save | <span dir="rtl">حفظ</span> |
| settings.cancel | Cancel | *(empty)* |

These are examples from the included resources: [English](fixtures/en.arb) and [Arabic](fixtures/ar.arb).

From the source directory, compare the files:

```sh
python -m localelens fixtures/en.arb fixtures/ar.arb --format markdown
```

The actual example result:

**1 error · 0 warnings**

| Severity | Code | JSON pointer | Detail |
|---|---|---|---|
| error | blank | `/settings/cancel` | nonblank source translated to blank string |

The command exits with code 1. Fix the translation or review the reported key, then rerun the comparison. A supplied [clean Arabic fixture](fixtures/ar_clean.arb) demonstrates a passing report.

## What gets checked

Compare a reference locale with a translated locale and get a stable, actionable report. No API keys, no online service, no modification of translation files.

| Check | Result |
|---|---|
| Missing keys or array positions | Error |
| Extra keys or array positions | Warning |
| Different JSON value types | Error |
| Nonblank reference translated as blank | Error |
| Named or positional placeholder mismatch | Error |
| Latin-only text in an Arabic locale (`--rtl`) | Warning |
| Additional replacement characters or suspicious ASCII `???` runs (`--check-unicode`) | Warning |

Deep paths are expressed as [JSON Pointers](https://datatracker.ietf.org/doc/html/rfc6901), so keys containing `/` or `~` stay unambiguous. When an entire object is missing, one issue identifies the missing subtree. ARB metadata keys starting with `@` are ignored at the root.

## Run it locally

Python 3.10+ is the only runtime prerequisite. From the source directory:

```sh
python -m localelens fixtures/en.arb fixtures/ar.arb
python -m localelens fixtures/en.arb fixtures/ar_clean.arb --format markdown --rtl
```

Install locally if you prefer a standalone command (requires setuptools for building):

```sh
python -m pip install .
localelens fixtures/en.arb fixtures/ar.arb --format markdown
```

## CLI reference

```text
localelens SOURCE TARGET [--format json|markdown] [--rtl]
           [--skip-placeholders] [--check-unicode] [--fail-on error|warning|never]
```

`json` is the default output format. Reports are printed to stdout so they can be redirected to an artifact. Input errors go to stderr. Reports explicitly use UTF-8 output, even if the inherited terminal encoding is not UTF-8. Invalid UTF-8, unpaired Unicode surrogates and nonfinite numbers are rejected. The comparison does not modify either resource.

| Exit code | Meaning |
|---|---|
| 0 | Checks passed (or selected failure threshold not reached) |
| 1 | Report contains issues meeting the selected threshold |
| 2 | Invalid arguments, JSON, unsupported resource type, or file read error |

For stricter CI, pass `--fail-on warning`. For reporting without fail-on-issue behavior, pass `--fail-on never`; invalid input still exits 2.

### JSON report from the example

```json
{
  "summary": {"errors": 1, "warnings": 0},
  "issues": [
    {"severity": "error", "code": "blank", "path": "/settings/cancel", "detail": "nonblank source translated to blank string"}
  ]
}
```

### Placeholder scope

Checks recognize named placeholders (`{name}`, `{{name}}`), common ICU argument starts such as `{count, plural, ...}`, and basic printf `%s`, `%d`, `%i`, `%f` with optional positional indexes (`%2$s`). Named placeholder presence rather than raw occurrence counts is compared so locale-specific plural variants do not trigger spurious failures. Complex ICU quoting, printf width/precision, nested custom syntaxes, plural-category completeness and translation meaning are outside this utility's scope; use `--skip-placeholders` if the project uses unsupported conventions. `--rtl` only flags Latin-only strings for human review, not incorrect layout or linguistic quality.

### Optional Unicode review

Use `--check-unicode` to flag newly introduced U+FFFD replacement characters and additional runs of at least three ASCII question marks. These patterns may indicate corruption; they are only warnings and cannot prove which original characters were lost. Ordinary Arabic punctuation `؟` is unaffected. To fail CI on these warnings, add `--fail-on warning`.

## Reliability and tests

```sh
python -m unittest discover -s tests -v
```

The included fixtures are synthetic English and Arabic resources. Inputs must have valid UTF-8 JSON object roots and be at most 10 MiB each. Duplicate keys and nonstandard JSON constants are rejected. Tests exercise the real CLI, structural checks, placeholder handling, ARB metadata, determinism and exit codes. CI is configured for Python 3.10/3.12 on Linux and Windows; the platforms are verified by the workflow when it runs.

## License

MIT. See [LICENSE](LICENSE) and [third-party notices](THIRD_PARTY.md).
