pybabel-angularjs 1.3.3__tar.gz → 1.4.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.
@@ -0,0 +1,110 @@
1
+ Metadata-Version: 2.4
2
+ Name: pybabel-angularjs
3
+ Version: 1.4.0
4
+ Summary: An AngularJS extractor for Babel
5
+ Author-email: Jaromír Pufler <jaromir.pufler@gmail.com>
6
+ License: Apache Software License
7
+ Project-URL: Homepage, https://github.com/chuckyblack/pybabel-angularjs
8
+ Keywords: angularjs,gettext,babel,i18n,translate
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Topic :: Software Development :: Internationalization
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Requires-Python: >=3.12
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: babel
24
+ Dynamic: license-file
25
+
26
+ # pybabel-angularjs
27
+
28
+ [![CI](https://github.com/chuckyblack/pybabel-angularjs/actions/workflows/release.yml/badge.svg?branch=master)](https://github.com/chuckyblack/pybabel-angularjs/actions/workflows/release.yml)
29
+ [![PyPI](https://img.shields.io/pypi/v/pybabel-angularjs.svg)](https://pypi.org/project/pybabel-angularjs/)
30
+
31
+ A [Babel](https://babel.pocoo.org/) message extractor for AngularJS HTML
32
+ templates. It extracts element content and attributes marked for translation,
33
+ including strings containing AngularJS expressions such as `{{ name }}`.
34
+
35
+ Requires Python 3.12 or newer.
36
+
37
+ ## Installation
38
+
39
+ ```console
40
+ python -m pip install pybabel-angularjs
41
+ ```
42
+
43
+ The package installs the `angularjs` Babel extractor entry point. Add it to a
44
+ Babel mapping file such as `babel.cfg`:
45
+
46
+ ```ini
47
+ [angularjs: **/*.html]
48
+ encoding = utf-8
49
+ ```
50
+
51
+ Then extract messages in the usual way:
52
+
53
+ ```console
54
+ pybabel extract -F babel.cfg -o messages.pot .
55
+ ```
56
+
57
+ ## Marking messages
58
+
59
+ Mark an element's content with `i18n`:
60
+
61
+ ```html
62
+ <div i18n>Hello world!</div>
63
+ <p i18n>Hello {{ name }}!</p>
64
+ ```
65
+
66
+ The value of `i18n`, when present, is included as a comment for translators:
67
+
68
+ ```html
69
+ <h1 i18n="Page heading">Welcome</h1>
70
+ ```
71
+
72
+ Mark an individual attribute by adding the `i18n-` prefix:
73
+
74
+ ```html
75
+ <input placeholder="Your name" i18n-placeholder>
76
+ ```
77
+
78
+ ## Configuration
79
+
80
+ Options are set in the extractor section of the Babel mapping file. Lists can
81
+ be separated by commas or whitespace.
82
+
83
+ ```ini
84
+ [angularjs: **/*.html]
85
+ encoding = utf-8
86
+ include_tags = h1, h2, p
87
+ include_attributes = title, alt, placeholder
88
+ allowed_tags = a, strong, br, i
89
+ allowed_attributes_a = href, target
90
+ ```
91
+
92
+ - `extract_attribute` changes the marker from the default `i18n`, for example
93
+ to `data-translate`.
94
+ - `include_tags` extracts all content from the listed tags without requiring an
95
+ explicit marker.
96
+ - `include_attributes` extracts the listed attributes wherever they occur.
97
+ - `allowed_tags` controls which nested HTML tags may appear inside a translated
98
+ message. The default is `strong, br, i`.
99
+ - `allowed_attributes_<tag>` controls attributes allowed on a nested tag, for
100
+ example `allowed_attributes_a = href, target`.
101
+ - `encoding` controls template decoding and defaults to `utf-8`.
102
+
103
+ Use `no-i18n` to exclude an automatically included tag. A `<div no-i18n>`
104
+ excludes its entire subtree. For automatically included attributes, use the
105
+ corresponding marker such as `no-i18n-title`.
106
+
107
+ ## License
108
+
109
+ Apache License 2.0. The project was heavily inspired by the original
110
+ [shoreware/pybabel-angularjs](https://bitbucket.org/shoreware/pybabel-angularjs).
@@ -0,0 +1,85 @@
1
+ # pybabel-angularjs
2
+
3
+ [![CI](https://github.com/chuckyblack/pybabel-angularjs/actions/workflows/release.yml/badge.svg?branch=master)](https://github.com/chuckyblack/pybabel-angularjs/actions/workflows/release.yml)
4
+ [![PyPI](https://img.shields.io/pypi/v/pybabel-angularjs.svg)](https://pypi.org/project/pybabel-angularjs/)
5
+
6
+ A [Babel](https://babel.pocoo.org/) message extractor for AngularJS HTML
7
+ templates. It extracts element content and attributes marked for translation,
8
+ including strings containing AngularJS expressions such as `{{ name }}`.
9
+
10
+ Requires Python 3.12 or newer.
11
+
12
+ ## Installation
13
+
14
+ ```console
15
+ python -m pip install pybabel-angularjs
16
+ ```
17
+
18
+ The package installs the `angularjs` Babel extractor entry point. Add it to a
19
+ Babel mapping file such as `babel.cfg`:
20
+
21
+ ```ini
22
+ [angularjs: **/*.html]
23
+ encoding = utf-8
24
+ ```
25
+
26
+ Then extract messages in the usual way:
27
+
28
+ ```console
29
+ pybabel extract -F babel.cfg -o messages.pot .
30
+ ```
31
+
32
+ ## Marking messages
33
+
34
+ Mark an element's content with `i18n`:
35
+
36
+ ```html
37
+ <div i18n>Hello world!</div>
38
+ <p i18n>Hello {{ name }}!</p>
39
+ ```
40
+
41
+ The value of `i18n`, when present, is included as a comment for translators:
42
+
43
+ ```html
44
+ <h1 i18n="Page heading">Welcome</h1>
45
+ ```
46
+
47
+ Mark an individual attribute by adding the `i18n-` prefix:
48
+
49
+ ```html
50
+ <input placeholder="Your name" i18n-placeholder>
51
+ ```
52
+
53
+ ## Configuration
54
+
55
+ Options are set in the extractor section of the Babel mapping file. Lists can
56
+ be separated by commas or whitespace.
57
+
58
+ ```ini
59
+ [angularjs: **/*.html]
60
+ encoding = utf-8
61
+ include_tags = h1, h2, p
62
+ include_attributes = title, alt, placeholder
63
+ allowed_tags = a, strong, br, i
64
+ allowed_attributes_a = href, target
65
+ ```
66
+
67
+ - `extract_attribute` changes the marker from the default `i18n`, for example
68
+ to `data-translate`.
69
+ - `include_tags` extracts all content from the listed tags without requiring an
70
+ explicit marker.
71
+ - `include_attributes` extracts the listed attributes wherever they occur.
72
+ - `allowed_tags` controls which nested HTML tags may appear inside a translated
73
+ message. The default is `strong, br, i`.
74
+ - `allowed_attributes_<tag>` controls attributes allowed on a nested tag, for
75
+ example `allowed_attributes_a = href, target`.
76
+ - `encoding` controls template decoding and defaults to `utf-8`.
77
+
78
+ Use `no-i18n` to exclude an automatically included tag. A `<div no-i18n>`
79
+ excludes its entire subtree. For automatically included attributes, use the
80
+ corresponding marker such as `no-i18n-title`.
81
+
82
+ ## License
83
+
84
+ Apache License 2.0. The project was heavily inspired by the original
85
+ [shoreware/pybabel-angularjs](https://bitbucket.org/shoreware/pybabel-angularjs).
@@ -0,0 +1,43 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pybabel-angularjs"
7
+ version = "1.4.0"
8
+ description = "An AngularJS extractor for Babel"
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ authors = [
12
+ { name = "Jaromír Pufler", email = "jaromir.pufler@gmail.com" },
13
+ ]
14
+ license = { text = "Apache Software License" }
15
+ keywords = ["angularjs", "gettext", "babel", "i18n", "translate"]
16
+ dependencies = [
17
+ "babel",
18
+ ]
19
+ classifiers = [
20
+ "Development Status :: 5 - Production/Stable",
21
+ "Intended Audience :: Developers",
22
+ "Topic :: Software Development :: Internationalization",
23
+ "License :: OSI Approved :: Apache Software License",
24
+ "Operating System :: OS Independent",
25
+ "Programming Language :: Python",
26
+ "Programming Language :: Python :: 3",
27
+ "Programming Language :: Python :: 3 :: Only",
28
+ "Programming Language :: Python :: 3.12",
29
+ "Programming Language :: Python :: 3.13",
30
+ "Programming Language :: Python :: 3.14",
31
+ ]
32
+
33
+ [project.urls]
34
+ Homepage = "https://github.com/chuckyblack/pybabel-angularjs"
35
+
36
+ [project.entry-points."babel.extractors"]
37
+ angularjs = "pybabel_angularjs.extractor:extract_angularjs"
38
+
39
+ [tool.setuptools]
40
+ package-dir = { "" = "src" }
41
+
42
+ [tool.setuptools.packages.find]
43
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -1,12 +1,12 @@
1
- # coding=utf-8
2
-
3
- try:
4
- from html.parser import HTMLParser
5
- except ImportError:
6
- from HTMLParser import HTMLParser
1
+ from html.parser import HTMLParser
2
+ from typing import Iterable, Iterator, Mapping, Sequence, Any
7
3
 
8
4
  import re
9
5
 
6
+ type ExtractorEntry = tuple[int, str, str, list[str]]
7
+ type AllowedAttributesByTag = dict[str, list[str]]
8
+ type HtmlAttributes = list[tuple[str, str | None]]
9
+
10
10
 
11
11
  class TagNotAllowedException(Exception):
12
12
  pass
@@ -35,34 +35,36 @@ class AngularJSGettextHTMLParser(HTMLParser):
35
35
  entries (i.e. "{$ expression $}" becomes "%(expression)")
36
36
  """
37
37
 
38
- def __init__(self, encoding, include_tags, include_attributes, extract_attribute, allowed_attributes_by_tag):
39
- try:
40
- super(AngularJSGettextHTMLParser, self).__init__()
41
- except TypeError:
42
- HTMLParser.__init__(self)
43
-
44
- self.encoding = encoding
45
- self.include_tags = include_tags
46
- self.include_attributes = include_attributes
47
- self.extract_attribute = extract_attribute
48
- self.allowed_attributes_by_tag = allowed_attributes_by_tag
49
-
50
- self.in_translate = False
51
- self.inner_tags = []
52
- self.data = ''
53
- self.entries = []
54
- self.start_lineno = 0
55
- self.plural = False
56
- self.plural_form = ''
57
- self.comments = []
58
- self.re_collapse_whitespaces = re.compile("\s+")
59
- self.in_do_not_translate = False
38
+ VOID_TAGS = ("br", "input", "img")
39
+
40
+ def __init__(
41
+ self,
42
+ include_tags: list[str],
43
+ include_attributes: list[str],
44
+ extract_attribute: str,
45
+ allowed_attributes_by_tag: AllowedAttributesByTag,
46
+ ) -> None:
47
+ super().__init__()
48
+
49
+ self.include_tags: list[str] = include_tags
50
+ self.include_attributes: list[str] = include_attributes
51
+ self.extract_attribute: str = extract_attribute
52
+ self.allowed_attributes_by_tag: AllowedAttributesByTag = allowed_attributes_by_tag
53
+
54
+ self.in_translate: bool = False
55
+ self.inner_tags: list[str] = []
56
+ self.data: list[str] = []
57
+ self.entries: list[ExtractorEntry] = []
58
+ self.start_lineno: int = 0
59
+ self.comments: list[str] = []
60
+ self.re_collapse_whitespaces: re.Pattern[str] = re.compile(r"\s+")
61
+ self.in_do_not_translate: bool = False
60
62
 
61
63
  @property
62
- def do_not_extract_attribute(self):
64
+ def do_not_extract_attribute(self) -> str:
63
65
  return "no-" + self.extract_attribute
64
66
 
65
- def normalize_string(self, string, replace_whitespace=" "):
67
+ def normalize_string(self, string: str, replace_whitespace: str = " ") -> str:
66
68
  """
67
69
  :type string: str
68
70
  :type replace_whitespace: str
@@ -71,38 +73,39 @@ class AngularJSGettextHTMLParser(HTMLParser):
71
73
  string
72
74
  .replace("\n", " ")
73
75
  .replace("\t", " ")
74
- .replace("/>", ">")
75
- .replace("</br>", "")
76
- .replace(u" ", "&nbsp;")
76
+ .replace(" ", "&nbsp;")
77
77
  )
78
- if isinstance(string, bytes):
79
- string = string.decode("utf-8")
80
78
  return self.re_collapse_whitespaces.sub(replace_whitespace, string).strip()
81
79
 
82
- def add_entry(self, message, comments=[], lineno=None):
80
+ def add_entry(self, message: str, comments: Sequence[str] | None = None, lineno: int | None = None) -> None:
81
+ comments = comments or []
83
82
  self.entries.append(
84
83
  (
85
84
  lineno or self.start_lineno,
86
- u'gettext',
85
+ "gettext",
87
86
  self.normalize_string(message),
88
87
  [self.normalize_string(comment) for comment in comments],
89
- ("angularjs-format", )
90
88
  )
91
89
  )
92
90
 
93
- def append_inner_tag(self, tag):
94
- if tag not in ("br", "input", "img"):
91
+ def append_inner_tag(self, tag: str) -> None:
92
+ if tag not in self.VOID_TAGS:
95
93
  self.inner_tags.append(tag)
96
94
 
97
- def attrdict_contains(self, attrdict, search=None):
95
+ def handle_startendtag(self, tag: str, attrs: HtmlAttributes) -> None:
96
+ self.handle_starttag(tag, attrs)
97
+ if tag not in self.VOID_TAGS:
98
+ self.handle_endtag(tag)
99
+
100
+ def attrdict_contains(self, attrdict: Mapping[str, str | None], search: Sequence[str] | None = None) -> bool:
98
101
  search = search or [self.extract_attribute, self.do_not_extract_attribute]
99
- for attr in attrdict: # type: str
100
- for string in search:
101
- if attr.startswith(string):
102
+ for attr in attrdict:
103
+ for prefix in search:
104
+ if attr.startswith(prefix):
102
105
  return True
103
106
  return False
104
107
 
105
- def handle_starttag(self, tag, attrs):
108
+ def handle_starttag(self, tag: str, attrs: HtmlAttributes) -> None:
106
109
  attrdict = dict(attrs)
107
110
  lineno = self.getpos()[0]
108
111
 
@@ -112,6 +115,11 @@ class AngularJSGettextHTMLParser(HTMLParser):
112
115
  self.append_inner_tag(tag)
113
116
  return
114
117
 
118
+ if self.in_translate and (
119
+ self.extract_attribute in attrdict or self.do_not_extract_attribute in attrdict
120
+ ):
121
+ raise ExtractAttributeNotAllowedException((lineno, tag, attrdict))
122
+
115
123
  if tag == "div" and self.do_not_extract_attribute in attrdict:
116
124
  self.in_do_not_translate = True
117
125
  if self.attrdict_contains(attrdict, [self.extract_attribute]):
@@ -119,13 +127,7 @@ class AngularJSGettextHTMLParser(HTMLParser):
119
127
  return
120
128
 
121
129
  # handle data-translate attribute for translating content
122
- if self.extract_attribute in attrdict or (tag in self.include_tags and self.do_not_extract_attribute not in attrdict):
123
- self.start_lineno = lineno
124
- self.in_translate = True
125
- comment = attrdict.get(self.extract_attribute)
126
- if comment:
127
- self.comments.append(comment)
128
- elif self.in_translate:
130
+ if self.in_translate:
129
131
  if tag not in self.allowed_attributes_by_tag:
130
132
  raise TagNotAllowedException((lineno, tag))
131
133
 
@@ -133,47 +135,51 @@ class AngularJSGettextHTMLParser(HTMLParser):
133
135
  diff_attributes = set(attrdict.keys()) - set(allowed_attributes)
134
136
  for attr in diff_attributes:
135
137
  if attr.startswith(self.extract_attribute + "-"): # i18n-
136
- pairAttr = attr.split("-", 1)[1]
138
+ pair_attr = attr.removeprefix(self.extract_attribute + "-")
137
139
  else:
138
- pairAttr = "%s-%s" % (self.extract_attribute, attr)
139
- if pairAttr not in attrdict:
140
+ pair_attr = f"{self.extract_attribute}-{attr}"
141
+ if pair_attr not in attrdict:
140
142
  raise TagAttributeNotAllowedException((lineno, tag, attrdict))
141
143
 
142
144
  if attrs:
143
- insert_value = ""
144
- for attr in attrs:
145
- name = attr[0]
146
- value = attr[1]
147
- insert_value += " " + '%s="%s"' % (name, value or "")
148
- self.data += '<%s %s>' % (tag, insert_value)
145
+ rendered_attrs = " ".join(f'{name}="{value or ""}"' for name, value in attrs)
146
+ self.data.append(f"<{tag} {rendered_attrs}>")
149
147
  else:
150
- self.data += '<%s>' % tag
148
+ self.data.append(f"<{tag}>")
151
149
 
152
150
  self.append_inner_tag(tag)
151
+ elif self.extract_attribute in attrdict or (tag in self.include_tags and self.do_not_extract_attribute not in attrdict):
152
+ self.start_lineno = lineno
153
+ self.in_translate = True
154
+ comment = attrdict.get(self.extract_attribute)
155
+ if comment:
156
+ self.comments.append(comment)
153
157
 
154
158
  already_added_attrs = []
155
159
  # auto-add attributes
156
160
  for attr in self.include_attributes:
157
- exclude_attribute = "%s-%s" % (self.do_not_extract_attribute, attr)
158
- if attr in attrdict and exclude_attribute not in attrdict:
159
- self.add_entry(attrdict[attr], [attr], lineno)
161
+ exclude_attribute = f"{self.do_not_extract_attribute}-{attr}"
162
+ value = attrdict.get(attr)
163
+ if value is not None and exclude_attribute not in attrdict:
164
+ self.add_entry(value, [attr], lineno)
160
165
  already_added_attrs.append(attr)
161
166
 
162
167
  # i18n-marked attributes
163
- for attr in attrdict: # type: str
168
+ for attr in attrdict:
164
169
  if attr.startswith(self.extract_attribute + "-"):
165
- name = attr.split("-", 1)[1]
170
+ name = attr.removeprefix(self.extract_attribute + "-")
166
171
  if name not in attrdict:
167
172
  raise MissingAttributeException((lineno, tag, name))
168
173
 
169
- if name not in already_added_attrs:
170
- self.add_entry(attrdict[name], [name], lineno)
174
+ value = attrdict[name]
175
+ if value is not None and name not in already_added_attrs:
176
+ self.add_entry(value, [name], lineno)
171
177
 
172
- def handle_data(self, data):
178
+ def handle_data(self, data: str) -> None:
173
179
  if self.in_translate:
174
- self.data += data
180
+ self.data.append(data)
175
181
 
176
- def handle_endtag(self, tag):
182
+ def handle_endtag(self, tag: str) -> None:
177
183
  if self.in_do_not_translate:
178
184
  if len(self.inner_tags) > 0:
179
185
  self.inner_tags.pop()
@@ -184,21 +190,28 @@ class AngularJSGettextHTMLParser(HTMLParser):
184
190
  if self.in_translate:
185
191
  if len(self.inner_tags) > 0:
186
192
  tag = self.inner_tags.pop()
187
- self.data += "</%s>" % tag
193
+ self.data.append(f"</{tag}>")
188
194
  return
189
195
 
190
- self.add_entry(self.data, self.comments)
196
+ self.add_entry("".join(self.data), self.comments)
191
197
  self.in_translate = False
192
- self.data = ''
198
+ self.data.clear()
193
199
  self.comments = []
194
200
 
195
201
 
196
- def get_option_list(options, name, default=[]):
202
+ def get_option_list(options: Mapping[str, str], name: str, default: list[str] | None = None) -> list[str]:
203
+ if default is None:
204
+ default = []
197
205
  value = options.get(name)
198
- return value and value.split(" ") or default
206
+ return value.replace(",", " ").split() if value else default
199
207
 
200
208
 
201
- def extract_angularjs(fileobj, keywords, comment_tags, options):
209
+ def extract_angularjs(
210
+ fileobj: Iterable[str | bytes],
211
+ keywords: Any,
212
+ comment_tags: Any,
213
+ options: Mapping[str, str],
214
+ ) -> Iterator[ExtractorEntry]:
202
215
  """Extract messages from AngularJS template (HTML) files that use the
203
216
  data-translate directive as per.
204
217
 
@@ -206,7 +219,7 @@ def extract_angularjs(fileobj, keywords, comment_tags, options):
206
219
  :param keywords: This is a standard parameter so it isaccepted but ignored.
207
220
  :param comment_tags: This is a standard parameter so it is accepted but ignored.
208
221
  :param options: Another standard parameter that is accepted but ignored.
209
- :return: an iterator over ``(lineno, funcname, message, comments, flags)`` tuples
222
+ :return: an iterator over ``(lineno, funcname, message, comments)`` tuples
210
223
  :rtype: ``iterator``
211
224
  """
212
225
  include_tags = get_option_list(options, "include_tags")
@@ -217,7 +230,6 @@ def extract_angularjs(fileobj, keywords, comment_tags, options):
217
230
  encoding = options.get('encoding', 'utf-8')
218
231
 
219
232
  parser = AngularJSGettextHTMLParser(
220
- encoding,
221
233
  include_tags,
222
234
  include_attributes,
223
235
  extract_attribute,
@@ -226,10 +238,9 @@ def extract_angularjs(fileobj, keywords, comment_tags, options):
226
238
 
227
239
  for line in fileobj:
228
240
  if isinstance(line, bytes):
229
- line = line.decode("utf-8")
241
+ line = line.decode(encoding)
230
242
  line = line.replace("&#xa;", "<br>")
231
- line = line.replace("&nbsp;", u" ")
243
+ line = line.replace("&nbsp;", " ")
232
244
  parser.feed(line)
233
245
 
234
- for entry in parser.entries:
235
- yield entry
246
+ yield from parser.entries
@@ -0,0 +1,110 @@
1
+ Metadata-Version: 2.4
2
+ Name: pybabel-angularjs
3
+ Version: 1.4.0
4
+ Summary: An AngularJS extractor for Babel
5
+ Author-email: Jaromír Pufler <jaromir.pufler@gmail.com>
6
+ License: Apache Software License
7
+ Project-URL: Homepage, https://github.com/chuckyblack/pybabel-angularjs
8
+ Keywords: angularjs,gettext,babel,i18n,translate
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Topic :: Software Development :: Internationalization
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Requires-Python: >=3.12
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: babel
24
+ Dynamic: license-file
25
+
26
+ # pybabel-angularjs
27
+
28
+ [![CI](https://github.com/chuckyblack/pybabel-angularjs/actions/workflows/release.yml/badge.svg?branch=master)](https://github.com/chuckyblack/pybabel-angularjs/actions/workflows/release.yml)
29
+ [![PyPI](https://img.shields.io/pypi/v/pybabel-angularjs.svg)](https://pypi.org/project/pybabel-angularjs/)
30
+
31
+ A [Babel](https://babel.pocoo.org/) message extractor for AngularJS HTML
32
+ templates. It extracts element content and attributes marked for translation,
33
+ including strings containing AngularJS expressions such as `{{ name }}`.
34
+
35
+ Requires Python 3.12 or newer.
36
+
37
+ ## Installation
38
+
39
+ ```console
40
+ python -m pip install pybabel-angularjs
41
+ ```
42
+
43
+ The package installs the `angularjs` Babel extractor entry point. Add it to a
44
+ Babel mapping file such as `babel.cfg`:
45
+
46
+ ```ini
47
+ [angularjs: **/*.html]
48
+ encoding = utf-8
49
+ ```
50
+
51
+ Then extract messages in the usual way:
52
+
53
+ ```console
54
+ pybabel extract -F babel.cfg -o messages.pot .
55
+ ```
56
+
57
+ ## Marking messages
58
+
59
+ Mark an element's content with `i18n`:
60
+
61
+ ```html
62
+ <div i18n>Hello world!</div>
63
+ <p i18n>Hello {{ name }}!</p>
64
+ ```
65
+
66
+ The value of `i18n`, when present, is included as a comment for translators:
67
+
68
+ ```html
69
+ <h1 i18n="Page heading">Welcome</h1>
70
+ ```
71
+
72
+ Mark an individual attribute by adding the `i18n-` prefix:
73
+
74
+ ```html
75
+ <input placeholder="Your name" i18n-placeholder>
76
+ ```
77
+
78
+ ## Configuration
79
+
80
+ Options are set in the extractor section of the Babel mapping file. Lists can
81
+ be separated by commas or whitespace.
82
+
83
+ ```ini
84
+ [angularjs: **/*.html]
85
+ encoding = utf-8
86
+ include_tags = h1, h2, p
87
+ include_attributes = title, alt, placeholder
88
+ allowed_tags = a, strong, br, i
89
+ allowed_attributes_a = href, target
90
+ ```
91
+
92
+ - `extract_attribute` changes the marker from the default `i18n`, for example
93
+ to `data-translate`.
94
+ - `include_tags` extracts all content from the listed tags without requiring an
95
+ explicit marker.
96
+ - `include_attributes` extracts the listed attributes wherever they occur.
97
+ - `allowed_tags` controls which nested HTML tags may appear inside a translated
98
+ message. The default is `strong, br, i`.
99
+ - `allowed_attributes_<tag>` controls attributes allowed on a nested tag, for
100
+ example `allowed_attributes_a = href, target`.
101
+ - `encoding` controls template decoding and defaults to `utf-8`.
102
+
103
+ Use `no-i18n` to exclude an automatically included tag. A `<div no-i18n>`
104
+ excludes its entire subtree. For automatically included attributes, use the
105
+ corresponding marker such as `no-i18n-title`.
106
+
107
+ ## License
108
+
109
+ Apache License 2.0. The project was heavily inspired by the original
110
+ [shoreware/pybabel-angularjs](https://bitbucket.org/shoreware/pybabel-angularjs).
@@ -1,8 +1,7 @@
1
1
  LICENSE
2
2
  MANIFEST.in
3
3
  README.md
4
- setup.cfg
5
- setup.py
4
+ pyproject.toml
6
5
  src/pybabel_angularjs/__init__.py
7
6
  src/pybabel_angularjs/extractor.py
8
7
  src/pybabel_angularjs.egg-info/PKG-INFO
@@ -1,3 +1,2 @@
1
1
  [babel.extractors]
2
2
  angularjs = pybabel_angularjs.extractor:extract_angularjs
3
-
@@ -1,95 +0,0 @@
1
- Metadata-Version: 1.1
2
- Name: pybabel-angularjs
3
- Version: 1.3.3
4
- Summary: An AngularJS extractor for Babel
5
- Home-page: https://github.com/chuckyblack/pybabel-angularjs
6
- Author: Jaromír Pufler
7
- Author-email: jaromir.pufler@gmail.com
8
- License: Apache Software License
9
- Description: pybabel-angularjs
10
- =================
11
-
12
- [![Build Status](https://travis-ci.org/chuckyblack/pybabel-angularjs.svg?branch=master)](https://travis-ci.org/chuckyblack/pybabel-angularjs.svg?branch=master)
13
-
14
- A Babel extractor for AngularJS templates.
15
-
16
- To translate the content of an HTML element use the `i18n`
17
- attribute:
18
-
19
- <div i18n>hello world!</div>
20
-
21
- To give somme context to your translators add value to the attribute:
22
-
23
- <div i18n="page title">hello world!</div>
24
-
25
- ## Babel configuration
26
-
27
- ### extract_attribute
28
-
29
- To change default `i18n` attribute use `extract_attribute` options:
30
-
31
- [angularjs: **/*.html]
32
- encoding = utf-8
33
- extract_attribute = translate
34
-
35
- Then use in template:
36
-
37
- <div translate="page title">hello world!</div>
38
-
39
- ### include_attributes
40
-
41
- To translate attributes of HTML nodes use `include_attributes` options:
42
-
43
- [angularjs: **/*.html]
44
- encoding = utf-8
45
- include_attributes = title, alt
46
-
47
- Then use in template:
48
-
49
- <div title="some title">hello world!</div>
50
- <img src="..." alt="some image description">
51
-
52
-
53
- ### allowed_tags
54
-
55
- Content of every translated tag is checked for tags it contains. You have to define sub-tags that can occur.
56
- Tags allowed by default are: strong, br, i
57
-
58
- [angularjs: **/*.html]
59
- encoding = utf-8
60
- allowed_tags = a, strong, br
61
-
62
-
63
- ### allowed_attributes_x
64
-
65
- Sub-tags (described in 'allowed_tags') may by default contain NO attributes at all.
66
- If you want to enable them to, you have to use this notation:
67
-
68
- [angularjs: **/*.html]
69
- encoding = utf-8
70
- allowed_tags = a, i
71
- allowed_attributes_a = href
72
- allowed_attributes_i = class
73
-
74
- The allowed_attribues_x setting needs to be accompanied by appropriate 'allowed_tags' setting.
75
-
76
-
77
- Heavily inspired by
78
- https://bitbucket.org/shoreware/pybabel-angularjs
79
-
80
- Keywords: angularjs gettext babel i18n translate
81
- Platform: UNKNOWN
82
- Classifier: Development Status :: 5 - Production/Stable
83
- Classifier: Intended Audience :: Developers
84
- Classifier: Topic :: Software Development :: Internationalization
85
- Classifier: License :: OSI Approved :: Apache Software License
86
- Classifier: Operating System :: OS Independent
87
- Classifier: Programming Language :: Python
88
- Classifier: Programming Language :: Python :: 2
89
- Classifier: Programming Language :: Python :: 2.6
90
- Classifier: Programming Language :: Python :: 2.7
91
- Classifier: Programming Language :: Python :: 3
92
- Classifier: Programming Language :: Python :: 3.2
93
- Classifier: Programming Language :: Python :: 3.3
94
- Classifier: Programming Language :: Python :: 3.4
95
- Classifier: Programming Language :: Python :: 3.5
@@ -1,70 +0,0 @@
1
- pybabel-angularjs
2
- =================
3
-
4
- [![Build Status](https://travis-ci.org/chuckyblack/pybabel-angularjs.svg?branch=master)](https://travis-ci.org/chuckyblack/pybabel-angularjs.svg?branch=master)
5
-
6
- A Babel extractor for AngularJS templates.
7
-
8
- To translate the content of an HTML element use the `i18n`
9
- attribute:
10
-
11
- <div i18n>hello world!</div>
12
-
13
- To give somme context to your translators add value to the attribute:
14
-
15
- <div i18n="page title">hello world!</div>
16
-
17
- ## Babel configuration
18
-
19
- ### extract_attribute
20
-
21
- To change default `i18n` attribute use `extract_attribute` options:
22
-
23
- [angularjs: **/*.html]
24
- encoding = utf-8
25
- extract_attribute = translate
26
-
27
- Then use in template:
28
-
29
- <div translate="page title">hello world!</div>
30
-
31
- ### include_attributes
32
-
33
- To translate attributes of HTML nodes use `include_attributes` options:
34
-
35
- [angularjs: **/*.html]
36
- encoding = utf-8
37
- include_attributes = title, alt
38
-
39
- Then use in template:
40
-
41
- <div title="some title">hello world!</div>
42
- <img src="..." alt="some image description">
43
-
44
-
45
- ### allowed_tags
46
-
47
- Content of every translated tag is checked for tags it contains. You have to define sub-tags that can occur.
48
- Tags allowed by default are: strong, br, i
49
-
50
- [angularjs: **/*.html]
51
- encoding = utf-8
52
- allowed_tags = a, strong, br
53
-
54
-
55
- ### allowed_attributes_x
56
-
57
- Sub-tags (described in 'allowed_tags') may by default contain NO attributes at all.
58
- If you want to enable them to, you have to use this notation:
59
-
60
- [angularjs: **/*.html]
61
- encoding = utf-8
62
- allowed_tags = a, i
63
- allowed_attributes_a = href
64
- allowed_attributes_i = class
65
-
66
- The allowed_attribues_x setting needs to be accompanied by appropriate 'allowed_tags' setting.
67
-
68
-
69
- Heavily inspired by
70
- https://bitbucket.org/shoreware/pybabel-angularjs
@@ -1,10 +0,0 @@
1
- [aliases]
2
- test = pytest
3
-
4
- [bdist_wheel]
5
- universal = 1
6
-
7
- [egg_info]
8
- tag_build =
9
- tag_date = 0
10
-
@@ -1,41 +0,0 @@
1
- # coding=utf-8
2
-
3
- from setuptools import setup, find_packages
4
-
5
- setup(
6
- name="pybabel-angularjs",
7
- version="1.3.3",
8
- author="Jaromír Pufler",
9
- author_email="jaromir.pufler@gmail.com",
10
- url="https://github.com/chuckyblack/pybabel-angularjs",
11
- description="An AngularJS extractor for Babel",
12
- long_description=open('README.md').read(),
13
- package_dir={'': 'src'},
14
- packages=find_packages('src'),
15
- install_requires=['babel', 'beautifulsoup4'],
16
- setup_requires=['pytest-runner'],
17
- tests_require=['pytest'],
18
- entry_points={
19
- 'babel.extractors': [
20
- 'angularjs=pybabel_angularjs.extractor:extract_angularjs',
21
- ],
22
- },
23
- license="Apache Software License",
24
- keywords="angularjs gettext babel i18n translate",
25
- classifiers=[
26
- "Development Status :: 5 - Production/Stable",
27
- "Intended Audience :: Developers",
28
- "Topic :: Software Development :: Internationalization",
29
- "License :: OSI Approved :: Apache Software License",
30
- "Operating System :: OS Independent",
31
- "Programming Language :: Python",
32
- "Programming Language :: Python :: 2",
33
- "Programming Language :: Python :: 2.6",
34
- "Programming Language :: Python :: 2.7",
35
- "Programming Language :: Python :: 3",
36
- "Programming Language :: Python :: 3.2",
37
- "Programming Language :: Python :: 3.3",
38
- "Programming Language :: Python :: 3.4",
39
- "Programming Language :: Python :: 3.5",
40
- ],
41
- )
@@ -1,95 +0,0 @@
1
- Metadata-Version: 1.1
2
- Name: pybabel-angularjs
3
- Version: 1.3.3
4
- Summary: An AngularJS extractor for Babel
5
- Home-page: https://github.com/chuckyblack/pybabel-angularjs
6
- Author: Jaromír Pufler
7
- Author-email: jaromir.pufler@gmail.com
8
- License: Apache Software License
9
- Description: pybabel-angularjs
10
- =================
11
-
12
- [![Build Status](https://travis-ci.org/chuckyblack/pybabel-angularjs.svg?branch=master)](https://travis-ci.org/chuckyblack/pybabel-angularjs.svg?branch=master)
13
-
14
- A Babel extractor for AngularJS templates.
15
-
16
- To translate the content of an HTML element use the `i18n`
17
- attribute:
18
-
19
- <div i18n>hello world!</div>
20
-
21
- To give somme context to your translators add value to the attribute:
22
-
23
- <div i18n="page title">hello world!</div>
24
-
25
- ## Babel configuration
26
-
27
- ### extract_attribute
28
-
29
- To change default `i18n` attribute use `extract_attribute` options:
30
-
31
- [angularjs: **/*.html]
32
- encoding = utf-8
33
- extract_attribute = translate
34
-
35
- Then use in template:
36
-
37
- <div translate="page title">hello world!</div>
38
-
39
- ### include_attributes
40
-
41
- To translate attributes of HTML nodes use `include_attributes` options:
42
-
43
- [angularjs: **/*.html]
44
- encoding = utf-8
45
- include_attributes = title, alt
46
-
47
- Then use in template:
48
-
49
- <div title="some title">hello world!</div>
50
- <img src="..." alt="some image description">
51
-
52
-
53
- ### allowed_tags
54
-
55
- Content of every translated tag is checked for tags it contains. You have to define sub-tags that can occur.
56
- Tags allowed by default are: strong, br, i
57
-
58
- [angularjs: **/*.html]
59
- encoding = utf-8
60
- allowed_tags = a, strong, br
61
-
62
-
63
- ### allowed_attributes_x
64
-
65
- Sub-tags (described in 'allowed_tags') may by default contain NO attributes at all.
66
- If you want to enable them to, you have to use this notation:
67
-
68
- [angularjs: **/*.html]
69
- encoding = utf-8
70
- allowed_tags = a, i
71
- allowed_attributes_a = href
72
- allowed_attributes_i = class
73
-
74
- The allowed_attribues_x setting needs to be accompanied by appropriate 'allowed_tags' setting.
75
-
76
-
77
- Heavily inspired by
78
- https://bitbucket.org/shoreware/pybabel-angularjs
79
-
80
- Keywords: angularjs gettext babel i18n translate
81
- Platform: UNKNOWN
82
- Classifier: Development Status :: 5 - Production/Stable
83
- Classifier: Intended Audience :: Developers
84
- Classifier: Topic :: Software Development :: Internationalization
85
- Classifier: License :: OSI Approved :: Apache Software License
86
- Classifier: Operating System :: OS Independent
87
- Classifier: Programming Language :: Python
88
- Classifier: Programming Language :: Python :: 2
89
- Classifier: Programming Language :: Python :: 2.6
90
- Classifier: Programming Language :: Python :: 2.7
91
- Classifier: Programming Language :: Python :: 3
92
- Classifier: Programming Language :: Python :: 3.2
93
- Classifier: Programming Language :: Python :: 3.3
94
- Classifier: Programming Language :: Python :: 3.4
95
- Classifier: Programming Language :: Python :: 3.5
@@ -1,2 +0,0 @@
1
- babel
2
- beautifulsoup4