Ignore:
Timestamp:
2018-03-04T22:09:01+01:00 (20 months ago)
Author:
stoecker
Message:

see #11392 - take new shorter I18n implementation also for plugins

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/I18n.java

    r13503 r13507  
    2020import java.util.Locale;
    2121import java.util.Map;
    22 import java.util.jar.JarInputStream;
    2322import java.util.zip.ZipEntry;
    2423import java.util.zip.ZipFile;
     
    370369    /**
    371370     * I18n initialization for plugins.
    372      * @param source file path/name of the JAR file containing translation strings
     371     * @param source file path/name of the JAR or Zip file containing translation strings
    373372     * @since 4159
    374373     */
    375374    public static void addTexts(File source) {
    376         if ("en".equals(loadedCode))
    377             return;
    378         final String enfile = "data/en.lang";
    379         final String langfile = "data/"+loadedCode+".lang";
    380         try (
    381             InputStream fis = Files.newInputStream(source.toPath());
    382             JarInputStream jar = new JarInputStream(fis)
    383         ) {
    384             ZipEntry e;
    385             boolean found = false;
    386             while (!found && (e = jar.getNextEntry()) != null) {
    387                 String name = e.getName();
    388                 if (enfile.equals(name))
    389                     found = true;
    390             }
    391             if (found) {
    392                 try (
    393                     InputStream fisTrans = Files.newInputStream(source.toPath());
    394                     JarInputStream jarTrans = new JarInputStream(fisTrans)
    395                 ) {
    396                     found = false;
    397                     while (!found && (e = jarTrans.getNextEntry()) != null) {
    398                         String name = e.getName();
    399                         if (name.equals(langfile))
    400                             found = true;
    401                     }
    402                     if (found)
    403                         load(jar, jarTrans, true);
    404                 }
    405             }
    406         } catch (IOException | InvalidPathException e) {
    407             Logging.trace(e);
    408         }
    409     }
    410 
    411     /**
    412      * I18n initialization for Zip based resources.
    413      * @param source input Zip source
    414      * @since 13502
    415      */
    416     public static void addTextsZip(File source) {
    417375        if ("en".equals(loadedCode))
    418376            return;
Note: See TracChangeset for help on using the changeset viewer.