Changeset 4159 in josm
- Timestamp:
- 2011-06-23T17:51:29+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r4137 r4159 61 61 import org.openstreetmap.josm.tools.CheckParameterUtil; 62 62 import org.openstreetmap.josm.tools.GBC; 63 import org.openstreetmap.josm.tools.I18n; 63 64 import org.openstreetmap.josm.tools.ImageProvider; 64 65 … … 448 449 allPluginLibraries.addAll(info.libraries); 449 450 File pluginJar = new File(pluginDir, info.name + ".jar"); 451 I18n.addTexts(pluginJar); 450 452 URL pluginJarUrl = PluginInformation.fileToURL(pluginJar); 451 453 allPluginLibraries.add(pluginJarUrl); -
trunk/src/org/openstreetmap/josm/tools/I18n.java
r4144 r4159 3 3 4 4 import java.io.BufferedInputStream; 5 import java.io.File; 6 import java.io.FileInputStream; 5 7 import java.io.InputStream; 8 import java.io.IOException; 6 9 import java.net.URL; 7 10 import java.text.MessageFormat; … … 9 12 import java.util.Comparator; 10 13 import java.util.HashMap; 14 import java.util.jar.JarInputStream; 15 import java.util.zip.ZipEntry; 11 16 import java.util.Locale; 12 17 import java.util.Vector; … … 27 32 MODE_CS, MODE_AR, MODE_PL/*, MODE_RO*/, MODE_RU, MODE_SK/*, MODE_SL*/} 28 33 private static PluralMode pluralMode = PluralMode.MODE_NOTONE; /* english default */ 34 private static String loadedCode = "en"; 29 35 30 36 /* Localization keys for file chooser (and color chooser). */ … … 340 346 } 341 347 348 public static void addTexts(File source) 349 { 350 FileInputStream fis = null; 351 JarInputStream jar = null; 352 FileInputStream fisTrans = null; 353 JarInputStream jarTrans = null; 354 String enfile = "data/en.lang"; 355 String langfile = "data/"+loadedCode+".lang"; 356 try 357 { 358 ZipEntry e; 359 fis = new FileInputStream(source); 360 jar = new JarInputStream(fis); 361 boolean found = false; 362 while(!found && (e = jar.getNextEntry()) != null) 363 { 364 String name = e.getName(); 365 if(name.equals(enfile)) 366 found = true; 367 } 368 if(found) 369 { 370 fisTrans = new FileInputStream(source); 371 jarTrans = new JarInputStream(fisTrans); 372 found = false; 373 while(!found && (e = jarTrans.getNextEntry()) != null) 374 { 375 String name = e.getName(); 376 if(name.equals(langfile)) 377 found = true; 378 } 379 if(found) 380 load(jar, jarTrans, true); 381 } 382 } 383 catch(IOException e) 384 { 385 } 386 finally 387 { 388 try 389 { 390 if(jar != null) 391 jar.close(); 392 if(fis != null) 393 fis.close(); 394 if(jarTrans != null) 395 jarTrans.close(); 396 if(fisTrans != null) 397 fisTrans.close(); 398 } 399 catch(IOException e) 400 { 401 } 402 } 403 } 404 342 405 private static boolean load(String l) 343 406 { … … 353 416 return false; 354 417 URL tr = Main.class.getResource("/data/"+l+".lang"); 355 if(tr == null )418 if(tr == null || !languages.containsKey(l)) 356 419 { 357 420 int i = l.indexOf('_'); … … 360 423 } 361 424 tr = Main.class.getResource("/data/"+l+".lang"); 362 if(tr == null )425 if(tr == null || !languages.containsKey(l)) 363 426 return false; 364 427 } 365 366 HashMap<String, String> s = new HashMap<String, String>(); 367 HashMap<String, String[]> p = new HashMap<String, String[]>(); 428 try 429 { 430 if(load(en.openStream(), tr.openStream(), false)) 431 { 432 pluralMode = languages.get(l); 433 loadedCode = l; 434 return true; 435 } 436 } 437 catch(IOException e) 438 { 439 } 440 return false; 441 } 442 443 private static boolean load(InputStream en, InputStream tr, boolean add) 444 { 445 HashMap<String, String> s; 446 HashMap<String, String[]> p; 447 if(add) 448 { 449 s = strings; 450 p = pstrings; 451 } 452 else 453 { 454 s = new HashMap<String, String>(); 455 p = new HashMap<String, String[]>(); 456 } 368 457 /* file format: 369 458 for all single strings: … … 383 472 try 384 473 { 385 InputStream ens = new BufferedInputStream(en .openStream());386 InputStream trs = new BufferedInputStream(tr .openStream());474 InputStream ens = new BufferedInputStream(en); 475 InputStream trs = new BufferedInputStream(tr); 387 476 byte[] enlen = new byte[2]; 388 477 byte[] trlen = new byte[2]; … … 430 519 trstrings[i] = new String(str, 0, val, "utf-8"); 431 520 } 432 if(trnum > 0 ) {521 if(trnum > 0 && !p.containsKey(enstrings[0])) { 433 522 p.put(enstrings[0], trstrings); 434 523 } … … 471 560 return false; 472 561 String trstr = new String(str, 0, trval, "utf-8"); 473 s.put(enstr, trstr); 562 if(!s.containsKey(enstr)) 563 s.put(enstr, trstr); 474 564 } 475 565 } … … 477 567 } 478 568 } 479 catch( Exception e)569 catch(IOException e) 480 570 { 481 571 return false; 482 572 } 483 if(!s.isEmpty() && languages.containsKey(l))573 if(!s.isEmpty()) 484 574 { 485 575 strings = s; 486 576 pstrings = p; 487 pluralMode = languages.get(l);488 577 return true; 489 578 }
Note:
See TracChangeset
for help on using the changeset viewer.