@@ -191,6 +191,88 @@ public synchronized Enumeration<Object> keys() {
191
191
Writer out = new OutputStreamWriter (os , I18N .ENCODING );
192
192
newProp .store (out , newChapter .getName ());
193
193
}
194
+
195
+ @ SuppressWarnings ("serial" )
196
+ public static final void compare (String projectPath , final String chapterId , String defaultLocale ,
197
+ String destLocale ) throws FileNotFoundException , IOException {
198
+ String modelPath = projectPath + Project .MODEL_PATH ;
199
+ File defaultChapter = new File (modelPath , chapterId + PROPERTIES_EXT );
200
+ File destChapter = new File (modelPath , chapterId + "_" + destLocale + PROPERTIES_EXT );
201
+
202
+ Properties defaultProp = new Properties () {
203
+ @ Override
204
+ public synchronized Enumeration <Object > keys () {
205
+ return Collections .enumeration (new TreeSet <Object >(keySet ()));
206
+ }
207
+ };
208
+ Properties destProp = new Properties () {
209
+ @ Override
210
+ public synchronized Enumeration <Object > keys () {
211
+ return Collections .enumeration (new TreeSet <Object >(keySet ()));
212
+ }
213
+ };
214
+
215
+ defaultProp .load (new InputStreamReader (new FileInputStream (defaultChapter ), I18N .ENCODING ));
216
+ destProp .load (new InputStreamReader (new FileInputStream (destChapter ), I18N .ENCODING ));
217
+
218
+ // SEARCH FOR NOT EXISTING DEST KEYS
219
+ for (Object key : defaultProp .keySet ()) {
220
+ if (destProp .get (key ) == null ) {
221
+ System .out .println ("Key not found in '" + destLocale + "' locale: " + key );
222
+ }
223
+ }
224
+
225
+ // SEARCH FOR NOT EXISTING DEFAULT CHAPTER KEYS
226
+ for (Object key : destProp .keySet ()) {
227
+ if (defaultProp .get (key ) == null ) {
228
+ System .out .println ("Key not found in default locale: " + key );
229
+ }
230
+ }
231
+ }
232
+
233
+ @ SuppressWarnings ("serial" )
234
+ public static final void sync (String projectPath , final String chapterId , String defaultLocale ,
235
+ String destLocale ) throws FileNotFoundException , IOException {
236
+ String modelPath = projectPath + Project .MODEL_PATH ;
237
+ File defaultChapter = new File (modelPath , chapterId + PROPERTIES_EXT );
238
+ File destChapter = new File (modelPath , chapterId + "_" + destLocale + PROPERTIES_EXT );
239
+
240
+ Properties defaultProp = new Properties () {
241
+ @ Override
242
+ public synchronized Enumeration <Object > keys () {
243
+ return Collections .enumeration (new TreeSet <Object >(keySet ()));
244
+ }
245
+ };
246
+ Properties destProp = new Properties () {
247
+ @ Override
248
+ public synchronized Enumeration <Object > keys () {
249
+ return Collections .enumeration (new TreeSet <Object >(keySet ()));
250
+ }
251
+ };
252
+
253
+ defaultProp .load (new InputStreamReader (new FileInputStream (defaultChapter ), I18N .ENCODING ));
254
+ destProp .load (new InputStreamReader (new FileInputStream (destChapter ), I18N .ENCODING ));
255
+
256
+ // SEARCH FOR NOT EXISTING DEST KEYS
257
+ for (String key : defaultProp .stringPropertyNames ()) {
258
+ if (destProp .get (key ) == null ) {
259
+ System .out .println ("ADDING Key not found in '" + destLocale + "' locale: " + key + "=" + defaultProp .getProperty (key ));
260
+ destProp .setProperty (key , "**" + defaultProp .getProperty (key ));
261
+ }
262
+ }
263
+
264
+ // SEARCH FOR NOT EXISTING DEFAULT CHAPTER KEYS
265
+ for (String key : destProp .stringPropertyNames ()) {
266
+ if (defaultProp .get (key ) == null ) {
267
+ System .out .println ("DELETE MANUALLY Key not found in default locale: " + key );
268
+ }
269
+ }
270
+
271
+ // save dest .properties
272
+ FileOutputStream os = new FileOutputStream (destChapter );
273
+ Writer out = new OutputStreamWriter (os , I18N .ENCODING );
274
+ destProp .store (out , destChapter .getName ());
275
+ }
194
276
195
277
public static final String translatePhrase (String phrase , String sourceLangCode , String destLangCode ) throws UnsupportedEncodingException {
196
278
// String query = MessageFormat.format(GOOGLE_TRANSLATE_URL, phrase,
@@ -214,9 +296,12 @@ public static final String translatePhrase(String phrase, String sourceLangCode,
214
296
}
215
297
216
298
public static void usage () {
217
- System .out .println ("Usage:\n " + "\t I18NUtils tsv2properties project_path chapter_id default_locale"
218
- + "\t I18NUtils properties2tsv project_path chapter_id default_locale"
219
- + "\t I18NUtils newlocale project_path chapter_id default_locale new_locale" );
299
+ System .out .println ("Usage:"
300
+ + "\n \t I18NUtils tsv2properties project_path chapter_id default_locale"
301
+ + "\n \t I18NUtils properties2tsv project_path chapter_id default_locale"
302
+ + "\n \t I18NUtils newlocale project_path chapter_id default_locale new_locale"
303
+ + "\n \t I18NUtils sync project_path chapter_id dest_locale"
304
+ + "\n \t I18NUtils compare project_path chapter_id dest_locale" );
220
305
}
221
306
222
307
public static final void main (String [] args ) throws FileNotFoundException , IOException {
@@ -245,6 +330,22 @@ public static final void main(String[] args) throws FileNotFoundException, IOExc
245
330
246
331
newLocale (args [1 ], args [2 ], args [3 ], args [4 ]);
247
332
System .out .println (args [2 ] + "_" + args [4 ] + PROPERTIES_EXT + " generated sucessfully." );
333
+ } else if (args [0 ].equals ("compare" )) {
334
+ if (args .length != 4 ) {
335
+ usage ();
336
+ System .exit (-1 );
337
+ }
338
+
339
+ compare (args [1 ], args [2 ], null , args [3 ]);
340
+ System .out .println ("Compare ENDED." );
341
+ } else if (args [0 ].equals ("sync" )) {
342
+ if (args .length != 4 ) {
343
+ usage ();
344
+ System .exit (-1 );
345
+ }
346
+
347
+ sync (args [1 ], args [2 ], null , args [3 ]);
348
+ System .out .println ("Sync ENDED." );
248
349
}
249
350
}
250
351
}
0 commit comments