Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion fluent/migrate/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def getParser(path):
from .cldr import get_plural_categories
from .transforms import Source
from .merge import merge_resource
from .util import get_message
from .errors import (
EmptyLocalizationError, NotSupportedError, UnreadableReferenceError)

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

for node in transforms:
ident = node.id.name
# Scan `node` for `Source` nodes and collect the information they
# store into a set of dependencies.
dependencies = fold(get_sources, node, set())
# Set these sources as dependencies for the current transform.
self.dependencies[(target, node.id.name)] = dependencies
self.dependencies[(target, ident)] = dependencies

# The target Fluent message should exist in the reference file. If
# it doesn't, it's probably a typo.
if get_message(reference_ast.body, ident) is None:
logger = logging.getLogger('migrate')
logger.warn(
'{} "{}" was not found in {}'.format(
type(node).__name__, ident, reference))

# Keep track of localization resource paths which were defined as
# sources in the transforms.
Expand Down
4 changes: 3 additions & 1 deletion fluent/migrate/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ def to_json(merged_iter):
}


LOCALIZABLE_ENTRIES = (FTL.Message, FTL.Term)

def get_message(body, ident):
"""Get message called `ident` from the `body` iterable."""
for entity in body:
if isinstance(entity, FTL.Message) and entity.id.name == ident:
if isinstance(entity, LOCALIZABLE_ENTRIES) and entity.id.name == ident:
return entity


Expand Down