@@ -139,8 +139,12 @@ def maybe_add_localization(self, path):
139139 else :
140140 self .localization_resources [path ] = collection
141141
142- def add_transforms (self , path , reference , transforms ):
143- """Define transforms for path using reference as template.
142+ def add_transforms (self , target , reference , transforms ):
143+ """Define transforms for target using reference as template.
144+
145+ `target` is a path of the destination FTL file relative to the
146+ localization directory. `reference` is a path to the template FTL
147+ file relative to the reference directory.
144148
145149 Each transform is an extended FTL node with `Transform` nodes as some
146150 values. Transforms are stored in their lazy AST form until
@@ -169,34 +173,38 @@ def get_sources(acc, cur):
169173 else :
170174 # The reference file will be used by the merge function as
171175 # a template for serializing the merge results.
172- self .reference_resources [path ] = ast
176+ self .reference_resources [target ] = ast
173177
174178 for node in transforms :
175179 # Scan `node` for `Source` nodes and collect the information they
176180 # store into a set of dependencies.
177181 dependencies = fold (get_sources , node , set ())
178182 # Set these sources as dependencies for the current transform.
179- self .dependencies [(path , node .id .name )] = dependencies
183+ self .dependencies [(target , node .id .name )] = dependencies
184+
185+ # Read all legacy translation files defined in Source transforms.
186+ for path in set (path for path , _ in dependencies ):
187+ self .maybe_add_localization (path )
180188
181- path_transforms = self .transforms .setdefault (path , [])
189+ path_transforms = self .transforms .setdefault (target , [])
182190 path_transforms += transforms
183191
184- if path not in self .localization_resources :
185- fullpath = os .path .join (self .localization_dir , path )
192+ if target not in self .localization_resources :
193+ fullpath = os .path .join (self .localization_dir , target )
186194 try :
187195 ast = self .read_ftl_resource (fullpath )
188196 except IOError :
189197 logger = logging .getLogger ('migrate' )
190198 logger .info (
191199 'Localization file {} does not exist and '
192- 'it will be created' .format (path ))
200+ 'it will be created' .format (target ))
193201 except UnicodeDecodeError :
194202 logger = logging .getLogger ('migrate' )
195203 logger .warn (
196204 'Localization file {} will be re-created and some '
197- 'translations might be lost' .format (path ))
205+ 'translations might be lost' .format (target ))
198206 else :
199- self .localization_resources [path ] = ast
207+ self .localization_resources [target ] = ast
200208
201209 def get_source (self , path , key ):
202210 """Get an entity value from a localized legacy source.
0 commit comments