in python/moz/l10n/paths/config.py [0:0]
def find_reference(self, target: str) -> tuple[str, dict[str, str]] | None:
"""
A reverse lookup for the reference path and variables matching `target`,
or `None` if not found.
"""
abs_target = join(self._base, normpath(target))
rel_target = normpath(relpath(abs_target, self._base)).replace(sep, "/")
for ref, pattern in self._templates:
match = pattern.fullmatch(rel_target)
if match:
vars = match.groupdict()
var_spans = {match.span(name) for name in vars}
star_values = [
group
for idx, group in enumerate(match.groups())
if match.span(idx + 1) not in var_spans
]
ref_path = normpath(ref.format(*star_values))
pot_path = ref_path + "t" if ref_path.endswith(".po") else None
pot_found = False
for pd_ref, _, _ in self._path_data:
if ref_path == pd_ref:
return ref_path, vars
if pot_path is not None and pot_path == pd_ref:
pot_found = True
if pot_found and pot_path is not None:
return pot_path, vars
for incl in self._includes:
res = incl.find_reference(abs_target)
if res is not None:
return res
return None