retrieval.po_loader¶
Per-entry loader for gettext .po files, used to turn a PO repository into a
translation memory. Stdlib-only (re, dataclasses, pathlib); no polib.
Each live entry becomes one chunk-granularity Document:
docidis"{path}:{start}-{end}"; the span covers the whole entry block (translator comments included), so it is a preciseReadtarget.textismsgctxt,msgid,msgid_pluralandmsgstrjoined by newlines (an untranslated entry contributes only its English text).metadatacarrieskind("po_entry"),msgid,msgstr,fuzzy,translated,line(themsgidline) andreferences, plusmsgctxt,msgid_pluralandmsgstr_pluralwhen present.
The header entry (msgid "") and obsolete #~ entries are never indexed.
Fuzzy and untranslated entries are indexed and flagged so callers can filter.
.pot templates are not discovered.
The module registers itself as the .po record loader (see
record_loaders). text combines msgid and msgstr by
design, so entries match English and Chinese queries alike (cross-lingual).
Per-entry loader for gettext .po files (translation-memory indexing).
Stdlib-only (re, dataclasses, pathlib) — no polib. A lenient
line parser turns each live PO entry into one chunk-granularity Document
so a translator can search msgid/msgstr pairs and Read the exact entry.
Policy:
- The header entry (
msgid ""withoutmsgctxt) is never indexed. - Obsolete entries (
#~lines) are never indexed. - Fuzzy and untranslated entries are indexed but flagged in
metadataso callers can filter. - A
Document's span (start_line..end_line) covers the whole entry block, translator comments included.contextstays empty on purpose so the tree-sitter retriever does not prefix it into the ranked text.
The parser never raises on malformed input; unrecognised lines are skipped.
This module registers itself as the .po record loader (see
retrieval.record_loaders) and is listed in
record_loaders.BUILTIN_LOADER_MODULES.
is_po_path(path)
¶
True if path has a .po suffix (case-insensitive).
Convenience predicate; the engine itself routes via record_loaders.lookup.
Source code in engine/retrieval/po_loader.py
50 51 52 53 54 55 | |
parse_po(text)
¶
Parse PO text into live entries (header included, obsolete excluded).
Source code in engine/retrieval/po_loader.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
po_entries_to_documents(rel_path, text, url='')
¶
One Document per live, non-header entry of the PO file text.
Source code in engine/retrieval/po_loader.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
unescape_po_string(quoted_body)
¶
Decode a quoted PO string literal ("...") into its text.
Uses an explicit escape map rather than unicode_escape, which would
corrupt non-ASCII (Chinese) text. Unknown escapes keep the backslash.
Source code in engine/retrieval/po_loader.py
64 65 66 67 68 69 70 71 72 73 74 75 | |