Repository: wangguanquan/eec
Pull request #388 (2024-08-09 00:28:00)

删除I18N


Patch:
diff --git a/pom.xml b/pom.xml
index 9a7d0ab5..bdf0790c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
 
   <groupId>org.ttzero</groupId>
   <artifactId>eec</artifactId>
-  <version>0.5.18-SNAPSHOT</version>
+  <version>0.5.17</version>
   <name>Excel Write/Read Framework</name>
   <packaging>jar</packaging>
   <url>https://www.ttzero.org</url>
diff --git a/src/main/java/org/ttzero/excel/entity/I18N.java b/src/main/java/org/ttzero/excel/entity/I18N.java
deleted file mode 100644
index e6e70eaa..00000000
--- a/src/main/java/org/ttzero/excel/entity/I18N.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright (c) 2017-2018, guanquan.wang@yandex.com All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.ttzero.excel.entity;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * @author guanquan.wang on 2018-10-13
- */
-public class I18N {
-    /**
-     * Here converted to HashMap is to improve performance,
-     * Properties extends to Hashtable All methods are synchronous methods,
-     * I18N only needs to read without writing, so converting to HashMap can greatly improve performance
-     */
-    private Map<String, String> pro;
-
-    public I18N() {
-        init();
-    }
-
-    void init() {
-        Locale locale = Locale.getDefault();
-        String fn = "message._.properties";
-        try {
-            InputStream is = I18N.class.getClassLoader().getResourceAsStream("I18N/" + fn.replace("_", locale.toLanguageTag()));
-            if (is == null) {
-                is = I18N.class.getClassLoader().getResourceAsStream("I18N/" + fn.replace("_", "zh-CN"));
-            }
-            if (is != null) {
-                try (Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) {
-                    Properties pro = new Properties();
-                    pro.load(reader);
-                    Map<String, String> map = new HashMap<>(pro.size());
-                    for (Map.Entry<Object, Object> entry : pro.entrySet()) {
-                        map.put(entry.getKey().toString(), entry.getValue().toString());
-                    }
-                    this.pro = map;
-                }
-            }
-            // FIXME classpath
-        } catch (IOException e) {
-            // nothing...
-        }
-
-        if (pro == null) pro = new HashMap<>();
-    }
-
-    /**
-     * get message by code
-     *
-     * @param code message code
-     * @return I18N string
-     */
-    public String get(String code) {
-        return pro.getOrDefault(code, code);
-    }
-
-    /**
-     * get message by code
-     *
-     * @param code  message code
-     * @param other default value
-     * @return I18N string
-     */
-    public String getOrElse(String code, String other) {
-        return pro.getOrDefault(code, other);
-    }
-
-    /**
-     * get message by code
-     *
-     * @param code code
-     * @param args args
-     * @return I18N string
-     */
-    public String get(String code, String... args) {
-        String msg = pro.getOrDefault(code, code);
-        char[] oldValue = msg.toCharArray();
-        int[] indexs = search(oldValue);
-        int len = Math.min(indexs.length, args.length), size = 0;
-        if (len < 1) return msg;
-        for (int i = 0; i < len; size += args[i++].length()) ;
-        StringBuilder buf = new StringBuilder(oldValue.length + size - (len << 1));
-        buf.append(oldValue, 0, indexs[0]).append(args[0]);
-        for (int i = 1; i < len; i++) {
-            buf.append(oldValue, size = indexs[i - 1] + 2, indexs[i] - size).append(args[i]);
-        }
-        if (indexs[len - 1] + 2 < oldValue.length) {
-            buf.append(oldValue, size = indexs[len - 1] + 2, oldValue.length - size);
-        }
-        return buf.toString();
-    }
-
-    private static int[] search(char[] value) {
-        int[] indexs = new int[16];
-        int n = 0;
-        for (int i = 0; i < value.length - 1; i++) {
-            if (value[i] == '{' && value[i + 1] == '}') {
-                indexs[n++] = i++;
-                if (n == indexs.length) {
-                    int[] _indexs = new int[indexs.length << 1];
-                    System.arraycopy(indexs, 0, _indexs, 0, indexs.length);
-                    indexs = _indexs;
-                }
-            }
-        }
-        return Arrays.copyOfRange(indexs, 0, n);
-    }
-
-}
diff --git a/src/main/java/org/ttzero/excel/entity/Workbook.java b/src/main/java/org/ttzero/excel/entity/Workbook.java
index 76a5ab4d..4e3dd3aa 100644
--- a/src/main/java/org/ttzero/excel/entity/Workbook.java
+++ b/src/main/java/org/ttzero/excel/entity/Workbook.java
@@ -129,7 +129,6 @@ public class Workbook implements Storable {
      * 导出进度监控器
      */
     private BiConsumer<Sheet, Integer> progressConsumer;
-    private final I18N i18N;
     /**
      * 全局字符串共享区
      */
@@ -162,8 +161,7 @@ public class Workbook implements Storable {
     /**
      * 创建一个未命名工作薄
      *
-     * <p>如果writeTo方法指定的File或Path为文件夹时，未命名工作薄将会从{@code resources/I18N/message.XXX.properties}
-     * 查找名为'non-name-file'的配置，有且不为空时以该配置为文件名否则以'Non name'作为文件名</p>
+     * <p>如果writeTo方法指定的File或Path为文件夹时，未命名工作薄将会以'新建文件'作为文件名</p>
      */
     public Workbook() {
         this(null);
@@ -188,7 +186,6 @@ public class Workbook implements Storable {
         this.name = name;
         this.creator = creator;
         sheets = new Sheet[3]; // Create three worksheet
-        i18N = new I18N();
         contentType = new ContentType();
     }
 
@@ -230,15 +227,6 @@ public class Workbook implements Storable {
         return company;
     }
 
-    /**
-     * 获取全局{@link I18N}配置
-     *
-     * @return 全局I18N配置
-     */
-    public I18N getI18N() {
-        return i18N;
-    }
-
     /**
      * 获取当前工作薄包含的工作表个数
      *
@@ -360,7 +348,7 @@ public class Workbook implements Storable {
     public Styles getStyles() {
         // CSV do not need Styles
         if (styles == null && !(workbookWriter instanceof CSVWorkbookWriter))
-            styles = Styles.create(i18N);
+            styles = Styles.create();
         return styles;
     }
 
@@ -778,7 +766,7 @@ public class Workbook implements Storable {
         }
         // 创建全局样式
         if (styles == null) {
-            styles = Styles.create(i18N);
+            styles = Styles.create();
         }
     }
 
diff --git a/src/main/java/org/ttzero/excel/entity/csv/CSVWorkbookWriter.java b/src/main/java/org/ttzero/excel/entity/csv/CSVWorkbookWriter.java
index 3a2cdd32..93a44b71 100644
--- a/src/main/java/org/ttzero/excel/entity/csv/CSVWorkbookWriter.java
+++ b/src/main/java/org/ttzero/excel/entity/csv/CSVWorkbookWriter.java
@@ -136,7 +136,7 @@ public class CSVWorkbookWriter implements IWorkbookWriter {
     protected void reMarkPath(Path src, Path path) throws IOException {
         String name;
         if (StringUtil.isEmpty(name = workbook.getName())) {
-            name = workbook.getI18N().getOrElse("non-name-file", "Non name");
+            name = "新建文件";
         }
 
         Path resultPath = reMarkPath(src, path, name);
diff --git a/src/main/java/org/ttzero/excel/entity/e7/XMLCellValueAndStyle.java b/src/main/java/org/ttzero/excel/entity/e7/XMLCellValueAndStyle.java
index b729f2a9..34b41114 100644
--- a/src/main/java/org/ttzero/excel/entity/e7/XMLCellValueAndStyle.java
+++ b/src/main/java/org/ttzero/excel/entity/e7/XMLCellValueAndStyle.java
@@ -21,29 +21,4 @@ import org.ttzero.excel.entity.ICellValueAndStyle;
 /**
  * @author guanquan.wang at 2019-09-25 11:25
  */
-public class XMLCellValueAndStyle implements ICellValueAndStyle {
-
-//    /**
-//     * Int value conversion to others
-//     *
-//     * @param row  the row number
-//     * @param cell the cell
-//     * @param o    the cell value
-//     * @param hc   the header column
-//     */
-//    @Override
-//    public void conversion(Row row, Cell cell, Object o, Column hc) {
-//        Object e = hc.getConversion().conversion(o);
-//        if (e != null) {
-//            Class<?> clazz = e.getClass();
-//            setCellValue(row, cell, e, hc, clazz, false);
-//            // FIXME 转转换后是否根据转换后的类型重新设置对齐不明确，暂时不重置
-////            int style = hc.getCellStyle(clazz);
-//            cell.xf = getStyleIndex(row, hc, o, hc.getCellStyle());
-//        } else {
-//            cell.blank();
-//            cell.xf = getStyleIndex(row, hc, null, hc.getCellStyle());
-//        }
-//    }
-
-}
+public class XMLCellValueAndStyle implements ICellValueAndStyle { }
diff --git a/src/main/java/org/ttzero/excel/entity/e7/XMLWorkbookWriter.java b/src/main/java/org/ttzero/excel/entity/e7/XMLWorkbookWriter.java
index e7f5f4d6..ed95118d 100644
--- a/src/main/java/org/ttzero/excel/entity/e7/XMLWorkbookWriter.java
+++ b/src/main/java/org/ttzero/excel/entity/e7/XMLWorkbookWriter.java
@@ -411,7 +411,7 @@ public class XMLWorkbookWriter implements IWorkbookWriter {
     protected void reMarkPath(Path zip, Path path) throws IOException {
         String name;
         if (StringUtil.isEmpty(name = workbook.getName())) {
-            name = workbook.getI18N().getOrElse("non-name-file", "Non name");
+            name = "新建文件";
         }
 
         Path resultPath = reMarkPath(zip, path, name);
diff --git a/src/main/java/org/ttzero/excel/entity/style/Styles.java b/src/main/java/org/ttzero/excel/entity/style/Styles.java
index 9054e5f0..6d74fa3f 100644
--- a/src/main/java/org/ttzero/excel/entity/style/Styles.java
+++ b/src/main/java/org/ttzero/excel/entity/style/Styles.java
@@ -19,7 +19,6 @@ package org.ttzero.excel.entity.style;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.ttzero.excel.manager.TopNS;
-import org.ttzero.excel.entity.I18N;
 import org.ttzero.excel.entity.Storable;
 import org.ttzero.excel.manager.Const;
 import org.ttzero.excel.util.FileUtil;
@@ -156,10 +155,9 @@ public class Styles implements Storable {
     /**
      * Create a general style
      *
-     * @param i18N the {@link I18N}
      * @return Styles
      */
-    public static Styles create(I18N i18N) {
+    public static Styles create() {
         Styles self = new Styles();
 
         self.document = createDocument();
@@ -174,9 +172,8 @@ public class Styles implements Storable {
 
         String lang = Locale.getDefault().toLanguageTag();
         // Add chinese font
-        Font font2 = new Font(i18N.get("local-font-family"), 11); // cn
+        Font font2 = new Font("宋体", 11); // cn
         if ("zh-CN".equals(lang)) {
-            if (StringUtil.isBlank(font2.getName())) font2.setName("宋体");
             font2.setCharset(Charset.GB2312);
         } else if ("zh-TW".equals(lang)) {
             if (StringUtil.isBlank(font2.getName())) font2.setName("新細明體");
diff --git a/src/main/resources/I18N/message.zh-CN.properties b/src/main/resources/I18N/message.zh-CN.properties
deleted file mode 100644
index 3d1a729a..00000000
--- a/src/main/resources/I18N/message.zh-CN.properties
+++ /dev/null
@@ -1,4 +0,0 @@
-# properties
-local-font-family=宋体
-general=常规
-non-name-file=新建文件
\ No newline at end of file


Test patch:
diff --git a/src/test/java/org/ttzero/excel/entity/MultiHeaderColumnsTest.java b/src/test/java/org/ttzero/excel/entity/MultiHeaderColumnsTest.java
index 40a9a857..ba9a9c53 100644
--- a/src/test/java/org/ttzero/excel/entity/MultiHeaderColumnsTest.java
+++ b/src/test/java/org/ttzero/excel/entity/MultiHeaderColumnsTest.java
@@ -469,7 +469,7 @@ public class MultiHeaderColumnsTest extends SQLWorkbookTest {
                 assertEquals(expect.get("sv"), o.get("short"));
                 assertEquals(expect.get("nv"), o.get("int"));
                 assertEquals(expect.get("lv"), o.get("long"));
-                assertTrue(Timestamp.valueOf((LocalDateTime) expect.get("ldtv")).getTime() / 1000 == ((Timestamp) o.get("LocalDateTime")).getTime() / 1000);
+                assertEquals(Timestamp.valueOf((LocalDateTime) expect.get("ldtv")).getTime() / 1000, ((Timestamp) o.get("LocalDateTime")).getTime() / 1000);
                 LocalTime t0 = (LocalTime) expect.get("ltv");
                 Time t1 = (Time) o.get("LocalTime");
                 assertEquals(t0.getHour(), t1.getHours());
diff --git a/src/test/java/org/ttzero/excel/entity/style/StylesTest.java b/src/test/java/org/ttzero/excel/entity/style/StylesTest.java
index 713ee4c5..1f2371b4 100644
--- a/src/test/java/org/ttzero/excel/entity/style/StylesTest.java
+++ b/src/test/java/org/ttzero/excel/entity/style/StylesTest.java
@@ -18,7 +18,6 @@ package org.ttzero.excel.entity.style;
 
 import org.junit.Before;
 import org.junit.Test;
-import org.ttzero.excel.entity.I18N;
 
 import java.awt.Color;
 import java.io.IOException;
@@ -46,7 +45,7 @@ public class StylesTest {
     private Styles styles;
 
     @Before public void before() {
-        styles = Styles.create(new I18N());
+        styles = Styles.create();
 
         // Built-In number format
         styles.of(16 << INDEX_NUMBER_FORMAT);