@@ -84,39 +84,8 @@ def parseValue(sh, translationsFile, key, expression) {
8484 }
8585}
8686
87- /*
88- * Translates a template into many files in the outputDirectory,
89- * given a translations file in INI style; e.g.:
90- *
91- * [filename1]
92- * variable1 = value1
93- * variable2 = value2
94- * ...
95- * [filename2]
96- * variable1 = value3
97- * variable2 = value4
98- * ...
99- */
100- def translate (templateSubdirectory , templateFile , translationsFile ) {
101- debug(" translate('$templateSubdirectory ', '$templateFile ', '$translationsFile ')" )
102-
103- // initialize the Velocity engine
104- engine = new org.apache.velocity.app.VelocityEngine ();
105- p = new java.util.Properties ();
106- // fail if template uses an invalid expression; e.g., an undefined variable
107- p. setProperty(" runtime.references.strict" , " true" );
108- // tell Velocity where the templates are located
109- p. setProperty(" file.resource.loader.path" , " $templateSubdirectory " );
110- // tell Velocity to log to stderr rather than to a velocity.log file
111- p. setProperty(org.apache.velocity.runtime.RuntimeConstants . RUNTIME_LOG_LOGSYSTEM_CLASS ,
112- " org.apache.velocity.runtime.log.SystemLogChute" );
113- engine. init(p);
114-
115- // read translation lines
116- outputFilename = null ;
117- context = globalContext = new org.apache.velocity.VelocityContext ();
118- reader = new java.io.BufferedReader (new java.io.FileReader (" $templateSubdirectory /$translationsFile " ));
119-
87+ /* Reads a translations File */
88+ def readTranslation (engine , globalContext , reader , templateSubdirectory , templateFile , translationsFile , isInclude ){
12089 sh = new groovy.lang.GroovyShell ();
12190 for (;;) {
12291 // read the line
@@ -125,6 +94,11 @@ def translate(templateSubdirectory, templateFile, translationsFile) {
12594 if (line == null ) break ;
12695 // check if the line starts a new section
12796 if (line. startsWith(" [" ) && line. endsWith(" ]" )) {
97+ // if we are parsing a .include file, return when we hit any sections
98+ if (isInclude){
99+ println (" [WARNING] $translationsFile : Section definition in .include file. Ending processing of $translationsFile " );
100+ return context;
101+ }
128102 // write out the previous file
129103 processTemplate(engine, context, templateFile, outputFilename);
130104
@@ -145,7 +119,15 @@ def translate(templateSubdirectory, templateFile, translationsFile) {
145119 // ignore comments
146120 if (trimmedLine. startsWith(" #" )) continue ;
147121
148- // parse key/value pair lines separate by equals
122+ // include any global files
123+ if (trimmedLine. startsWith(" .include" )){
124+ includeFile = line. substring(9 );
125+ globalReader = new java.io.BufferedReader (new java.io.FileReader (" $templateSubdirectory /$includeFile " ));
126+ encapsulatedContext = new org.apache.velocity.VelocityContext (context)
127+ context = readTranslation(engine, encapsulatedContext, globalReader, templateSubdirectory, templateFile, includeFile, true )
128+ continue ;
129+ }
130+
149131 if (! line. contains(' =' )) {
150132 print (" [WARNING] $translationsFile : Ignoring spurious line: $line " );
151133 continue ;
@@ -176,6 +158,45 @@ def translate(templateSubdirectory, templateFile, translationsFile) {
176158
177159 context. put(key, parseValue(sh, translationsFile, key, value));
178160 }
161+
162+ return context;
163+ }
164+
165+ /*
166+ * Translates a template into many files in the outputDirectory,
167+ * given a translations file in INI style; e.g.:
168+ *
169+ * [filename1]
170+ * variable1 = value1
171+ * variable2 = value2
172+ * ...
173+ * [filename2]
174+ * variable1 = value3
175+ * variable2 = value4
176+ * ...
177+ */
178+ def translate (templateSubdirectory , templateFile , translationsFile ) {
179+ debug(" translate('$templateSubdirectory ', '$templateFile ', '$translationsFile ')" )
180+
181+ // initialize the Velocity engine
182+ engine = new org.apache.velocity.app.VelocityEngine ();
183+ p = new java.util.Properties ();
184+ // fail if template uses an invalid expression; e.g., an undefined variable
185+ p. setProperty(" runtime.references.strict" , " true" );
186+ // tell Velocity where the templates are located
187+ p. setProperty(" file.resource.loader.path" , " $templateSubdirectory " );
188+ // tell Velocity to log to stderr rather than to a velocity.log file
189+ p. setProperty(org.apache.velocity.runtime.RuntimeConstants . RUNTIME_LOG_LOGSYSTEM_CLASS ,
190+ " org.apache.velocity.runtime.log.SystemLogChute" );
191+ engine. init(p);
192+
193+ // read translation lines
194+ outputFilename = null ;
195+ context = globalContext = new org.apache.velocity.VelocityContext ();
196+ reader = new java.io.BufferedReader (new java.io.FileReader (" $templateSubdirectory /$translationsFile " ));
197+
198+ readTranslation(engine, context, reader, templateSubdirectory, templateFile, translationsFile, false );
199+
179200 reader. close();
180201
181202 // process the template
0 commit comments