Translation Finder
Translation file discovery library used by Weblate to identify translation files and their configuration in source repositories.
Discovery can operate on file listings alone or inspect the filesystem when more accurate detection is needed, such as determining file encoding or distinguishing formats with similar syntax.
Maintained by Weblate — a privacy-respecting localization platform built on open-source foundations.
Usage
It can be used from Python:
>>> from translation_finder import discover
>>> from pprint import pprint
>>> results = discover("translation_finder/test_data/")
>>> len(results)
40
>>> pprint(results[0].match)
{'file_format': 'aresource',
'filemask': 'app/src/res/main/values-*/strings.xml',
'name': 'android',
'template': 'app/src/res/main/values/strings.xml'}
>>> pprint(results[1].match)
{'file_format': 'po',
'filemask': 'locales/*.po',
'name': 'translation',
'new_base': 'locales/messages.pot'}
Additional information about discovery can be obtained from meta attribute:
>>> pprint(results[0].meta)
{'discovery': 'TransifexDiscovery', 'origin': 'Transifex', 'priority': 500}
>>> pprint(results[22].meta)
{'discovery': 'GettextDiscovery', 'origin': None, 'priority': 1000}
Or command line:
$ weblate-discovery translation_finder/test_data/
== Match 1 (Transifex) ==
file_format : aresource
filemask : app/src/res/main/values-*/strings.xml
name : android
template : app/src/res/main/values/strings.xml
...
== Match 7 ==
file_format : po
filemask : locales/*.po
new_base : locales/messages.pot
Non-printable characters in command-line results are displayed as visible escapes (for example, \n and \x1b). The Python API returns the original values unchanged.
Discovery result fields
Each result describes a suggested configuration. Paths are relative to the discovery root, and filemask identifies the translation files belonging to that configuration. File masks, including discovery hints, use * as their only wildcard. Question marks and brackets match literal characters, so paths such as src/[locale]/*.json preserve their bracketed directory names. Custom discovery selectors needing multiple alternatives should provide a tuple of masks, for example ("resources.resx", "resources.resw").
Two optional fields describe files with different roles:
- template
The source file containing string definitions for a monolingual configuration. This maps to Weblate’s Monolingual base language file. Translations are interpreted using the string definitions in this file.
- new_base
The file used to create translation files for additional languages. This maps to Weblate’s Template for new translations. It can be an untranslated source file, a Gettext POT file, or an existing bilingual translation whose translations will be cleared when creating the new language file. Setting new_base alone does not make a configuration monolingual.
For example, the Gettext result in the usage example has only new_base: locales/messages.pot supplies the messages for new languages, while existing PO files contain their own source strings. Similarly, Qt’s translation repository can produce this bilingual configuration, using an existing Arabic translation to create new languages:
{
"file_format": "ts",
"filemask": "translations/designer_*.ts",
"new_base": "translations/designer_ar.ts",
}
Both fields can refer to the same file. For example, the PHP and Laravel fixtures use their English source files both to define strings and to create new language files:
>>> pprint(sorted(
... (r["file_format"], r["template"], r["new_base"])
... for r in results if r["file_format"] in {"php", "laravel"}
... ))
[('laravel', 'laravel/en.php', 'laravel/en.php'),
('php', 'php/en.php', 'php/en.php')]
Either field can appear independently, both can appear, or both can be absent. An absent field means discovery did not provide that setting; it does not necessarily mean the format does not support it. Discovery backends may also read settings from repository configuration, such as Transifex configuration.
Filename-based discovery first looks for an exact name derived from the filemask for new_base. Otherwise, it prefers a discovered template when that file is eligible for creating translations. Formats using the same file extension for sources and translations then prefer a translation from the same discovered filemask. If those checks do not identify a file, discovery retains a deterministic fallback from the nearest directory containing an eligible file. These are heuristics: review suggestions when a directory contains unrelated catalogs or several possible templates.
Discovery limits
The high-level discover() API and CLI --hint option accept hints of at most 400 characters, bounding wildcard pattern compilation cost. Longer hints raise ValueError in the API or exit with status 2 in the CLI, before scanning the repository. This limit remains active with unlimited discovery budgets.
The CLI accepts nonnegative integer limits. Zero permits no work for that budget. Defaults are:
--max-candidates: 4096 generated candidates across all backends.
--max-results: 4096 returned matches.
--max-new-base-checks: 65536 new-base lookups across all backends.
--max-wildcard-checks: 1000000 language-code probes while generating file masks across all backends.
--max-masks-per-path: 32 generated masks per path.
--sniff-max-bytes: 67108864 bytes (64 MiB) sampled across the run.
--sniff-max-files: 512 content-sniffing file attempts across the run.
--max-files: 100000 indexed files.
--max-dirs: 20000 indexed directories.
--max-depth: 64 directory levels below the root.
--max-entries: 150000 directory entries examined, including excluded entries and symlinks.
--max-path-length: 4096 characters in an indexed relative path.
--max-path-bytes: 67108864 bytes (64 MiB) of collected relative file and directory paths, measured as UTF-8 with surrogatepass for undecodable names. Collection stops before retaining a path that would exceed this budget and reports path-bytes truncation. This bounds path text, not total process memory; lookup indexes add overhead.
--max-match-checks: 65536 regular expression and wildcard candidate evaluations.
For example, weblate-discover --max-results 10000 translations/ raises only the result limit. weblate-discover --unlimited translations/ disables all discovery budgets; it cannot be combined with individual limit options. Internal parser safeguards and per-result format and encoding sampling limits remain active.
The CLI prints collected matches to stdout, including partial results. If candidate, result, new-base, per-path mask, wildcard language-code, Finder, or wildcard matching limits cause truncation, it prints one warning with the limit reasons to stderr and exits with status 3. Complete discovery exits with status 0; invalid arguments exit with status 2. Sniff-budget exhaustion uses best-effort detection and does not itself report truncation.
Python callers can import DiscoveryLimits from translation_finder.api and pass it as the keyword-only limits argument to discover(). Defaults match the CLI; a field set to None disables that limit, and DiscoveryLimits.unlimited() disables all limits. Negative values raise ValueError. Inspect results.truncated and results.limit_reasons for truncation; high-level discovery does not emit Python warnings. max_results=0 returns before scanning the tree and conservatively reports truncation. Direct Finder use has the same scan and matching defaults and exposes limit_reasons; pass None for a limit to disable it. Direct backend discover() calls also use the default run-wide sniff limits.
Finder mask matching
Finder.filter_masks() accepts basename patterns such as *.po, using only * as a wildcard, and matches them against lowercased filenames in every directory. Question marks and brackets match literal characters. To select multiple alternatives, pass a tuple such as ("resources.resx", "resources.resw"). Patterns containing / raise ValueError when the generator is iterated, before any matches are yielded.
To restrict directories, pass a separate directory regular expression as dirglob, for example finder.filter_masks("*.po", dirglob="po"). Finder.filter_files() accepts regular expressions for both the basename and the optional directory filter. Both expressions are fullmatched against lowercased names.
Finder.mask_matches() matches relative paths, for example po/*.po. Its * wildcard can span directory separators; ? and brackets are literal characters. It preserves case according to platform fnmatch rules, rather than lowercasing paths as the filtering methods do.
Custom discovery backends
Custom BaseDiscovery implementations return DiscoveryCandidate objects from get_masks(). Each candidate associates the result with the paths which actually generated it, allowing content detection to inspect the group without expanding its wildcard mask again.
Backend filter_files() and candidate paths use read-only path references. These can be compact file records or PurePath objects supplied through mock listings. Use their name, parent, parts, and as_posix() interfaces; do not require concrete Path instances or access filesystem methods on the references. Read file content through self.finder.open(path). If additional path operations are necessary, explicitly construct Path(path.as_posix()).
The public Finder.mask_matches(), filter_masks(), filter_files(), and get_lc_candidates() methods continue to return relative PurePath objects, including the original path objects for mock listings. Filesystem paths are materialized on demand, so callers should not depend on object identity across calls. Finder’s lookup indexes are private implementation details.
Candidate generation, new-base resolution, and returned results are bounded across each discovery run. The returned DiscoveryResults object behaves as a list and exposes truncated and limit_reasons attributes. These report whether a safety limit made results potentially incomplete, without emitting a Python warning.
Calling get_masks() directly is a low-level interface with only the per-path mask limit. Use discover() for run-wide resource bounds and structured limit status.
from translation_finder.discovery.base import BaseDiscovery
from translation_finder.discovery.result import DiscoveryCandidate
class CustomDiscovery(BaseDiscovery):
def get_masks(self, *, eager=False, hint=None):
for path in self.filter_files():
yield DiscoveryCandidate({"filemask": "locale/*.json"}, [path])
Metadata
Release files for translation-finder 3.10.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| translation_finder-3.10.0.tar.gz | 154.1 kB | With provenance | Details for translation_finder-3.10.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| translation_finder-3.10.0-py3-none-any.whl | Python 3 | none | any | Details for translation_finder-3.10.0-py3-none-any.whl |
Total release size: 311.5 kB
Release files / translation_finder-3.10.0.tar.gz
| Download URL | translation_finder-3.10.0.tar.gz |
|---|---|
| Size | 154.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f2d3a2323e37ac9a29641b2e36299471a6babf95041c320f08c826f652870069
|
|
BLAKE2b-256 checksum How to use checksums |
373dacb3cfe43bf3c19d34756735fd6cb958b0523a26d18b67601323b3324f71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.
Transparency logRelease files / translation_finder-3.10.0-py3-none-any.whl
| Download URL | translation_finder-3.10.0-py3-none-any.whl |
|---|---|
| Size | 157.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
60de34a27da57ede154ee20d2474beef3fd73b4eeca46da9ec6dc53001582f46
|
|
BLAKE2b-256 checksum How to use checksums |
45eb08f1a27e7721cb5e88cdc2b4040cb1af8581a98cfc9f7d655a9de8ed5228
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.
Transparency logSecurity for translation-finder 3.10.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for translation_finder-3.10.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.