@@ -117,9 +117,10 @@ class TranslationGenerator {
117117
118118 // If a compareRef is provided, fetch the old version of the files, and traverse the ASTs in parallel to extract existing translations
119119 if ( this . compareRef ) {
120- // A map of locale => translations node, where "translations node" refers to the main object in en.ts and
121- // other locale files that contains all the translations.
122120 const allLocales : Locale [ ] = [ LOCALES . EN , ...this . targetLanguages ] ;
121+
122+ // An array of labeled "translation nodes", where "translations node" refers to the main object in en.ts and
123+ // other locale files that contains all the translations.
123124 const oldTranslationNodes : Array < LabeledNode < Locale > > = [ ] ;
124125 const downloadPromises = [ ] ;
125126 for ( const targetLanguage of allLocales ) {
@@ -142,7 +143,7 @@ class TranslationGenerator {
142143 await Promise . all ( downloadPromises ) ;
143144
144145 // Traverse ASTs of all downloaded files in parallel, building a map of {locale => {translationKey => translation}}
145- // Note: that traversing in parallel is not just a performance optimization. We need the translation key
146+ // Note: traversing in parallel is not just a performance optimization. We need the translation key
146147 // from en.ts to map to translations in other files, but we can't rely on dot-notation style paths alone
147148 // because sometimes there are strings defined elsewhere, such as in functions or nested templates.
148149 // So instead, we rely on the fact that the AST structure of en.ts will very nearly match the AST structure of other locales.
@@ -154,7 +155,9 @@ class TranslationGenerator {
154155 return ;
155156 }
156157
158+ // Use English for the translation key
157159 const translationKey = this . getTranslationKey ( enNode ) ;
160+
158161 for ( const targetLanguage of this . targetLanguages ) {
159162 const translatedNode = nodes [ targetLanguage ] ;
160163 if ( ! this . shouldNodeBeTranslated ( translatedNode ) ) {
@@ -172,6 +175,7 @@ class TranslationGenerator {
172175 translationsForLocale . set ( translationKey , serializedNode ) ;
173176 translations . set ( targetLanguage , translationsForLocale ) ;
174177
178+ // For complex template expressions, we need a way to look up the English span hash for each translated span hash, so we track those here
175179 if ( ts . isTemplateExpression ( enNode ) && ts . isTemplateExpression ( translatedNode ) && ! this . isSimpleTemplateExpression ( enNode ) ) {
176180 for ( let i = 0 ; i < enNode . templateSpans . length ; i ++ ) {
177181 const enSpan = enNode . templateSpans [ i ] ;
@@ -195,6 +199,7 @@ class TranslationGenerator {
195199 const translationPromises = [ ] ;
196200 for ( const [ key , { text, context} ] of stringsToTranslate ) {
197201 if ( translationsForLocale . has ( key ) ) {
202+ // This means that the translation for this key was already parsed from an existing translation file, so we don't need to translate it with ChatGPT
198203 continue ;
199204 }
200205 const translationPromise = promisePool . add ( ( ) => this . translator . translate ( targetLanguage , text , context ) . then ( ( result ) => translationsForLocale . set ( key , result ) ) ) ;
0 commit comments