Module

analysis.i18n

Message extraction for i18n support.

Walks the AST and collects translatable strings fromTransnodes and_() / _n()function calls. Outputs structured messages suitable for PO template generation or Babel integration.

Classes

ExtractedMessage 5
A translatable message extracted from a template.

A translatable message extracted from a template.

Attributes

Name Type Description
filename str
lineno int
function str
message str | tuple[str, str]
comments tuple[str, ...]
ExtractMessagesVisitor 4
Walk AST and collect translatable messages. Collects messages from: - ``Trans`` nodes (``{% trans…

Walk AST and collect translatable messages.

Collects messages from:

  • Trans nodes ({% trans %}...{% endtrans %})
  • FuncCall nodes calling _() or _n()

Methods

extract 1 list[ExtractedMessage]
Extract all translatable messages from an AST.
def extract(self, node: Node) -> list[ExtractedMessage]
Parameters
Name Type Description
node
Returns
list[ExtractedMessage]
visit_Trans 1
Extract message from ``{% trans %}`` block.
def visit_Trans(self, node: Trans) -> None
Parameters
Name Type Description
node
visit_FuncCall 1
Extract message from ``_("literal")`` or ``_n("s", "p", n)`` calls.
def visit_FuncCall(self, node: FuncCall) -> None
Parameters
Name Type Description
node
Internal Methods 1
__init__ 1
def __init__(self, filename: str = '<template>') -> None
Parameters
Name Type Description
filename Default:'<template>'