Skip to content

Commit d1bc398

Browse files
committed
Bug 1435181 - Warn about unknown FTL entities in transforms
1 parent 27203c2 commit d1bc398

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

fluent/migrate/context.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def getParser(path):
2323
from .cldr import get_plural_categories
2424
from .transforms import Source
2525
from .merge import merge_resource
26+
from .util import get_message
2627
from .errors import (
2728
EmptyLocalizationError, NotSupportedError, UnreadableReferenceError)
2829

@@ -205,11 +206,20 @@ def get_sources(acc, cur):
205206
self.reference_resources[target] = reference_ast
206207

207208
for node in transforms:
209+
ident = node.id.name
208210
# Scan `node` for `Source` nodes and collect the information they
209211
# store into a set of dependencies.
210212
dependencies = fold(get_sources, node, set())
211213
# Set these sources as dependencies for the current transform.
212-
self.dependencies[(target, node.id.name)] = dependencies
214+
self.dependencies[(target, ident)] = dependencies
215+
216+
# The target Fluent message should exist in the reference file. If
217+
# it doesn't, it's probably a typo.
218+
if get_message(reference_ast.body, ident) is None:
219+
logger = logging.getLogger('migrate')
220+
logger.warn(
221+
'{} "{}" was not found in {}'.format(
222+
type(node).__name__, ident, reference))
213223

214224
# Keep track of localization resource paths which were defined as
215225
# sources in the transforms.

fluent/migrate/util.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ def to_json(merged_iter):
4242
}
4343

4444

45+
LOCALIZABLE_ENTRIES = (FTL.Message, FTL.Term)
46+
4547
def get_message(body, ident):
4648
"""Get message called `ident` from the `body` iterable."""
4749
for entity in body:
48-
if isinstance(entity, FTL.Message) and entity.id.name == ident:
50+
if isinstance(entity, LOCALIZABLE_ENTRIES) and entity.id.name == ident:
4951
return entity
5052

5153

0 commit comments

Comments
 (0)