pybabel-angularjs 1.4.0__tar.gz → 1.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pybabel-angularjs
3
- Version: 1.4.0
3
+ Version: 1.5.0
4
4
  Summary: An AngularJS extractor for Babel
5
5
  Author-email: Jaromír Pufler <jaromir.pufler@gmail.com>
6
6
  License: Apache Software License
@@ -87,6 +87,7 @@ include_tags = h1, h2, p
87
87
  include_attributes = title, alt, placeholder
88
88
  allowed_tags = a, strong, br, i
89
89
  allowed_attributes_a = href, target
90
+ include_format_flags = false
90
91
  ```
91
92
 
92
93
  - `extract_attribute` changes the marker from the default `i18n`, for example
@@ -99,6 +100,11 @@ allowed_attributes_a = href, target
99
100
  - `allowed_attributes_<tag>` controls attributes allowed on a nested tag, for
100
101
  example `allowed_attributes_a = href, target`.
101
102
  - `encoding` controls template decoding and defaults to `utf-8`.
103
+ - `include_format_flags` makes the extractor return an extended five-value
104
+ result and marks messages containing AngularJS interpolation with
105
+ `angularjs-format`. It defaults to `false` because official Babel releases
106
+ accept only the standard four-value extractor result. Enable it only with a
107
+ Babel build that explicitly supports extractor-provided flags.
102
108
 
103
109
  Use `no-i18n` to exclude an automatically included tag. A `<div no-i18n>`
104
110
  excludes its entire subtree. For automatically included attributes, use the
@@ -62,6 +62,7 @@ include_tags = h1, h2, p
62
62
  include_attributes = title, alt, placeholder
63
63
  allowed_tags = a, strong, br, i
64
64
  allowed_attributes_a = href, target
65
+ include_format_flags = false
65
66
  ```
66
67
 
67
68
  - `extract_attribute` changes the marker from the default `i18n`, for example
@@ -74,6 +75,11 @@ allowed_attributes_a = href, target
74
75
  - `allowed_attributes_<tag>` controls attributes allowed on a nested tag, for
75
76
  example `allowed_attributes_a = href, target`.
76
77
  - `encoding` controls template decoding and defaults to `utf-8`.
78
+ - `include_format_flags` makes the extractor return an extended five-value
79
+ result and marks messages containing AngularJS interpolation with
80
+ `angularjs-format`. It defaults to `false` because official Babel releases
81
+ accept only the standard four-value extractor result. Enable it only with a
82
+ Babel build that explicitly supports extractor-provided flags.
77
83
 
78
84
  Use `no-i18n` to exclude an automatically included tag. A `<div no-i18n>`
79
85
  excludes its entire subtree. For automatically included attributes, use the
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pybabel-angularjs"
7
- version = "1.4.0"
7
+ version = "1.5.0"
8
8
  description = "An AngularJS extractor for Babel"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -1,9 +1,11 @@
1
1
  from html.parser import HTMLParser
2
- from typing import Iterable, Iterator, Mapping, Sequence, Any
2
+ from typing import Any, Iterable, Iterator, Mapping, Sequence
3
3
 
4
4
  import re
5
5
 
6
- type ExtractorEntry = tuple[int, str, str, list[str]]
6
+ type StandardExtractorEntry = tuple[int, str, str, list[str]]
7
+ type FlaggedExtractorEntry = tuple[int, str, str, list[str], tuple[str, ...]]
8
+ type ExtractorEntry = StandardExtractorEntry | FlaggedExtractorEntry
7
9
  type AllowedAttributesByTag = dict[str, list[str]]
8
10
  type HtmlAttributes = list[tuple[str, str | None]]
9
11
 
@@ -43,6 +45,7 @@ class AngularJSGettextHTMLParser(HTMLParser):
43
45
  include_attributes: list[str],
44
46
  extract_attribute: str,
45
47
  allowed_attributes_by_tag: AllowedAttributesByTag,
48
+ include_format_flags: bool = False,
46
49
  ) -> None:
47
50
  super().__init__()
48
51
 
@@ -50,6 +53,7 @@ class AngularJSGettextHTMLParser(HTMLParser):
50
53
  self.include_attributes: list[str] = include_attributes
51
54
  self.extract_attribute: str = extract_attribute
52
55
  self.allowed_attributes_by_tag: AllowedAttributesByTag = allowed_attributes_by_tag
56
+ self.include_format_flags = include_format_flags
53
57
 
54
58
  self.in_translate: bool = False
55
59
  self.inner_tags: list[str] = []
@@ -79,14 +83,17 @@ class AngularJSGettextHTMLParser(HTMLParser):
79
83
 
80
84
  def add_entry(self, message: str, comments: Sequence[str] | None = None, lineno: int | None = None) -> None:
81
85
  comments = comments or []
82
- self.entries.append(
83
- (
84
- lineno or self.start_lineno,
85
- "gettext",
86
- self.normalize_string(message),
87
- [self.normalize_string(comment) for comment in comments],
88
- )
86
+ entry: StandardExtractorEntry = (
87
+ lineno or self.start_lineno,
88
+ "gettext",
89
+ self.normalize_string(message),
90
+ [self.normalize_string(comment) for comment in comments],
89
91
  )
92
+ if self.include_format_flags:
93
+ flags = ("angularjs-format",) if "{{" in message else ()
94
+ self.entries.append((*entry, flags))
95
+ else:
96
+ self.entries.append(entry)
90
97
 
91
98
  def append_inner_tag(self, tag: str) -> None:
92
99
  if tag not in self.VOID_TAGS:
@@ -206,6 +213,20 @@ def get_option_list(options: Mapping[str, str], name: str, default: list[str] |
206
213
  return value.replace(",", " ").split() if value else default
207
214
 
208
215
 
216
+ def get_option_bool(options: Mapping[str, str], name: str, default: bool = False) -> bool:
217
+ value = options.get(name)
218
+ if value is None:
219
+ return default
220
+ if isinstance(value, bool):
221
+ return value
222
+ normalized_value = value.strip().lower()
223
+ if normalized_value in {"1", "true", "yes", "on"}:
224
+ return True
225
+ if normalized_value in {"0", "false", "no", "off"}:
226
+ return False
227
+ raise ValueError(f"Invalid boolean value for {name}: {value!r}")
228
+
229
+
209
230
  def extract_angularjs(
210
231
  fileobj: Iterable[str | bytes],
211
232
  keywords: Any,
@@ -218,14 +239,16 @@ def extract_angularjs(
218
239
  :param fileobj: the file-like object the messages should be extracted from
219
240
  :param keywords: This is a standard parameter so it isaccepted but ignored.
220
241
  :param comment_tags: This is a standard parameter so it is accepted but ignored.
221
- :param options: Another standard parameter that is accepted but ignored.
222
- :return: an iterator over ``(lineno, funcname, message, comments)`` tuples
242
+ :param options: Extractor configuration options.
243
+ :return: an iterator over ``(lineno, funcname, message, comments)`` tuples,
244
+ optionally extended by a fifth ``flags`` value
223
245
  :rtype: ``iterator``
224
246
  """
225
247
  include_tags = get_option_list(options, "include_tags")
226
248
  include_attributes = get_option_list(options, "include_attributes")
227
249
  allowed_tags = get_option_list(options, "allowed_tags", ["strong", "br", "i"])
228
250
  extract_attribute = options.get("extract_attribute") or "i18n"
251
+ include_format_flags = get_option_bool(options, "include_format_flags")
229
252
  allowed_attributes_by_tag = {tag: get_option_list(options, "allowed_attributes_" + tag) for tag in allowed_tags}
230
253
  encoding = options.get('encoding', 'utf-8')
231
254
 
@@ -233,7 +256,8 @@ def extract_angularjs(
233
256
  include_tags,
234
257
  include_attributes,
235
258
  extract_attribute,
236
- allowed_attributes_by_tag
259
+ allowed_attributes_by_tag,
260
+ include_format_flags,
237
261
  )
238
262
 
239
263
  for line in fileobj:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pybabel-angularjs
3
- Version: 1.4.0
3
+ Version: 1.5.0
4
4
  Summary: An AngularJS extractor for Babel
5
5
  Author-email: Jaromír Pufler <jaromir.pufler@gmail.com>
6
6
  License: Apache Software License
@@ -87,6 +87,7 @@ include_tags = h1, h2, p
87
87
  include_attributes = title, alt, placeholder
88
88
  allowed_tags = a, strong, br, i
89
89
  allowed_attributes_a = href, target
90
+ include_format_flags = false
90
91
  ```
91
92
 
92
93
  - `extract_attribute` changes the marker from the default `i18n`, for example
@@ -99,6 +100,11 @@ allowed_attributes_a = href, target
99
100
  - `allowed_attributes_<tag>` controls attributes allowed on a nested tag, for
100
101
  example `allowed_attributes_a = href, target`.
101
102
  - `encoding` controls template decoding and defaults to `utf-8`.
103
+ - `include_format_flags` makes the extractor return an extended five-value
104
+ result and marks messages containing AngularJS interpolation with
105
+ `angularjs-format`. It defaults to `false` because official Babel releases
106
+ accept only the standard four-value extractor result. Enable it only with a
107
+ Babel build that explicitly supports extractor-provided flags.
102
108
 
103
109
  Use `no-i18n` to exclude an automatically included tag. A `<div no-i18n>`
104
110
  excludes its entire subtree. For automatically included attributes, use the