36):
37 """Extract messages from ``searxng.msg`` files by a custom extractor_.
38
39 .. _extractor:
40 https://babel.pocoo.org/en/latest/messages.html#writing-extraction-methods
41 """
42 if fileobj.name not in _MSG_FILES:
43 raise RuntimeError("don't know how to extract messages from %s" % fileobj.name)
44
45 namespace = {}
46 exec(fileobj.read(), {}, namespace)
47
48 for obj_name in namespace['__all__']:
49 obj = namespace[obj_name]
50 if isinstance(obj, list):
51 for msg in obj:
52
53 yield 0, '_', msg, [f"{obj_name}"]
54 elif isinstance(obj, dict):
55 for k, msg in obj.items():
56 yield 0, '_', msg, [f"{obj_name}['{k}']"]
57 else:
58 raise ValueError(f"{obj_name} should be list or dict")