1111//! losing existing translations.
1212
1313use std:: collections:: HashMap ;
14+ use std:: fs:: File ;
15+ use std:: io:: Read ;
1416use std:: path:: Path ;
1517
1618use anyhow:: { bail, Context } ;
@@ -130,7 +132,10 @@ impl<'a> SourceMap<'a> {
130132 None => return Ok ( extract_messages ( document) ) ,
131133 } ;
132134
133- // Construct a full document using all messages from `path`.
135+ // First, we try constructing a document using other messages
136+ // from the catalog. Catalogs from pre-0.1.0 included the link
137+ // definitions.
138+ //
134139 // This will have quadratic complexity in case every message
135140 // from `path` has a "[some text][1]" link which needs to be
136141 // resolved using a table of link definitions as the bottom.
@@ -146,6 +151,15 @@ impl<'a> SourceMap<'a> {
146151 full_document. push_str ( msg) ;
147152 }
148153
154+ // Second, we attempt to add the original source file.
155+ // Catalogs made with version 0.1.0 to 0.2.0 did not include
156+ // the link definitions at all, so we need to rely on the
157+ // source data (if we can find it).
158+ if let Ok ( mut file) = File :: open ( path) {
159+ full_document. push_str ( "\n \n " ) ;
160+ let _ = file. read_to_string ( & mut full_document) ;
161+ }
162+
149163 let mut messages = extract_messages ( & full_document) ;
150164 // Truncate away the messages from `full_document` which start
151165 // after `document`.
0 commit comments