├── .gitignore
├── .idea
├── .gitignore
├── artifacts
│ └── generate_strings_tool_jar.xml
├── generate_strings_tool.iml
├── inspectionProfiles
│ └── Project_Default.xml
├── libraries
│ ├── bin.xml
│ └── library.xml
├── misc.xml
├── modules.xml
├── uiDesigner.xml
└── vcs.xml
├── LICENSE
├── META-INF
└── MANIFEST.MF
├── README.md
├── generate_strings_tool.iml
├── generator_language_config
├── bin
│ ├── dom4j-1.6.1.jar
│ ├── dom4j.jar
│ ├── poi-3.8-20120326.jar
│ ├── poi-examples-3.8-20120326.jar
│ ├── poi-excelant-3.8-20120326.jar
│ ├── poi-ooxml-3.8-20120326.jar
│ ├── poi-ooxml-schemas-3.8-20120326.jar
│ ├── poi-scratchpad-3.8-20120326.jar
│ ├── stax-api-1.0.1.jar
│ └── xmlbeans-2.3.0.jar
├── generator_language_config.iml
├── library
│ ├── dom4j-1.6.1.jar
│ ├── dom4j.jar
│ ├── poi-3.8-20120326.jar
│ ├── poi-examples-3.8-20120326.jar
│ ├── poi-excelant-3.8-20120326.jar
│ ├── poi-ooxml-3.8-20120326.jar
│ ├── poi-ooxml-schemas-3.8-20120326.jar
│ ├── poi-scratchpad-3.8-20120326.jar
│ ├── stax-api-1.0.1.jar
│ └── xmlbeans-2.3.0.jar
└── src
│ ├── META-INF
│ └── MANIFEST.MF
│ └── generator_language_config
│ ├── META-INF
│ └── MANIFEST.MF
│ ├── UIMain.java
│ ├── ui
│ ├── ExcelToStringsFrame.java
│ ├── ExcelToXmlFrame.java
│ ├── MainFrame.java
│ └── XmlToExcelFrame.java
│ └── util
│ ├── ExcelFilter.java
│ ├── ExcelToStringsUtil.java
│ ├── ExcelUtil.java
│ ├── StringEntity.java
│ ├── StringsFilter.java
│ ├── StringsUtil.java
│ ├── XMLUtil.java
│ └── XmlFilter.java
└── out
├── artifacts
└── generate_strings_tool_jar
│ ├── dom4j-1.6.1.jar
│ ├── dom4j.jar
│ ├── generate_strings_tool.jar
│ ├── poi-3.8-20120326.jar
│ ├── poi-examples-3.8-20120326.jar
│ ├── poi-excelant-3.8-20120326.jar
│ ├── poi-ooxml-3.8-20120326.jar
│ ├── poi-ooxml-schemas-3.8-20120326.jar
│ ├── poi-scratchpad-3.8-20120326.jar
│ ├── stax-api-1.0.1.jar
│ └── xmlbeans-2.3.0.jar
└── production
└── generate_strings_tool
├── META-INF
└── MANIFEST.MF
└── generator_language_config
└── META-INF
└── MANIFEST.MF
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | #*.jar
15 | #*.war
16 | #*.ear
17 | #*.zip
18 | #*.tar.gz
19 | #*.rar
20 |
21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
22 | hs_err_pid*
23 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Datasource local storage ignored files
5 | /dataSources/
6 | /dataSources.local.xml
7 | # Editor-based HTTP Client requests
8 | /httpRequests/
9 |
--------------------------------------------------------------------------------
/.idea/artifacts/generate_strings_tool_jar.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | $PROJECT_DIR$/out/artifacts/generate_strings_tool_jar
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/generate_strings_tool.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/libraries/bin.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/libraries/library.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
8 | -
9 |
10 |
11 | -
12 |
13 |
14 | -
15 |
16 |
17 | -
18 |
19 |
20 |
21 |
22 |
23 | -
24 |
25 |
26 |
27 |
28 |
29 | -
30 |
31 |
32 |
33 |
34 |
35 | -
36 |
37 |
38 |
39 |
40 |
41 | -
42 |
43 |
44 |
45 |
46 | -
47 |
48 |
49 |
50 |
51 | -
52 |
53 |
54 |
55 |
56 | -
57 |
58 |
59 |
60 |
61 | -
62 |
63 |
64 |
65 |
66 | -
67 |
68 |
69 |
70 |
71 | -
72 |
73 |
74 | -
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
82 |
83 |
84 | -
85 |
86 |
87 |
88 |
89 | -
90 |
91 |
92 |
93 |
94 | -
95 |
96 |
97 |
98 |
99 | -
100 |
101 |
102 | -
103 |
104 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Main-Class: generator_language_config.UIMain
3 | Class-Path: xmlbeans-2.3.0.jar stax-api-1.0.1.jar poi-scratchpad-3.8-201
4 | 20326.jar poi-ooxml-schemas-3.8-20120326.jar poi-examples-3.8-20120326.
5 | jar poi-3.8-20120326.jar dom4j-1.6.1.jar poi-excelant-3.8-20120326.jar
6 | dom4j.jar poi-ooxml-3.8-20120326.jar
7 |
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #### 工具起源
2 |
3 | 最近在做国际化多语言适配,暂时有 18 种语言,pc 站有 30 多种好像,平常所有显示的文字交于专人负责整理和翻译,翻译完成后把整理好的Excel交给开发人员进行适配。然而并没有这样简单。。。
4 | 各种修改、调整、新增文字,每次修改后开发人员都得核对一次,然后各个在strings.xml中修改。
5 |
6 | 可想而知这是一件多么烦锁的事情,为了从这样一个重复、毫无意义的工作中解脱出来,我花了半天的时间撸了一个工具。有了工具后拿到翻译好的Excel,用工具来一键生成各国语言的资源文件。整理资源也是一样的选择strings.xml一键生成Excel。。这样是不是爽多了??
7 |
8 | #### [](#%E5%B7%A5%E5%85%B7%E7%9A%84%E4%BD%BF%E7%94%A8)工具的使用
9 |
10 | 
11 |
12 |
13 | 
14 |
15 |
16 |
17 | 写了一个简单的界面,导入项目后运行UIMain 就能愉快的玩耍了!
18 | 表格格式:
19 |
20 | * 注意事项
21 | key:固定标识,这里 Android 和 iOS 未做区分(可自行拓展后徐芬)
22 | 支持注释:key列可以使用注释(直接在Excel中写入注释)
23 |
24 | 生成结果:
25 |
26 |
27 | #### [](#%E9%80%82%E9%85%8D%E4%B8%AD%E7%9A%84%E4%B8%80%E7%82%B9%E5%B0%8F%E5%BB%BA%E8%AE%AE)拓展
28 | - 每次都会读取原本的 xml 文件或者 strings 文件,然后再写进去所以既可以支持新建 key,也可以支持在原本的 key 上修改后,会将修改后的文案直接覆盖。
29 |
30 | -源码中也包含 strings 转 Excel,xml 转 Excel,工具入口就不放出来了。
31 |
32 |
33 |
--------------------------------------------------------------------------------
/generate_strings_tool.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/generator_language_config/bin/dom4j-1.6.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/generator_language_config/bin/dom4j-1.6.1.jar
--------------------------------------------------------------------------------
/generator_language_config/bin/dom4j.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/generator_language_config/bin/dom4j.jar
--------------------------------------------------------------------------------
/generator_language_config/bin/poi-3.8-20120326.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/generator_language_config/bin/poi-3.8-20120326.jar
--------------------------------------------------------------------------------
/generator_language_config/bin/poi-examples-3.8-20120326.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/generator_language_config/bin/poi-examples-3.8-20120326.jar
--------------------------------------------------------------------------------
/generator_language_config/bin/poi-excelant-3.8-20120326.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/generator_language_config/bin/poi-excelant-3.8-20120326.jar
--------------------------------------------------------------------------------
/generator_language_config/bin/poi-ooxml-3.8-20120326.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/generator_language_config/bin/poi-ooxml-3.8-20120326.jar
--------------------------------------------------------------------------------
/generator_language_config/bin/poi-ooxml-schemas-3.8-20120326.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/generator_language_config/bin/poi-ooxml-schemas-3.8-20120326.jar
--------------------------------------------------------------------------------
/generator_language_config/bin/poi-scratchpad-3.8-20120326.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/generator_language_config/bin/poi-scratchpad-3.8-20120326.jar
--------------------------------------------------------------------------------
/generator_language_config/bin/stax-api-1.0.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/generator_language_config/bin/stax-api-1.0.1.jar
--------------------------------------------------------------------------------
/generator_language_config/bin/xmlbeans-2.3.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/generator_language_config/bin/xmlbeans-2.3.0.jar
--------------------------------------------------------------------------------
/generator_language_config/generator_language_config.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
--------------------------------------------------------------------------------
/generator_language_config/library/dom4j-1.6.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/generator_language_config/library/dom4j-1.6.1.jar
--------------------------------------------------------------------------------
/generator_language_config/library/dom4j.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/generator_language_config/library/dom4j.jar
--------------------------------------------------------------------------------
/generator_language_config/library/poi-3.8-20120326.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/generator_language_config/library/poi-3.8-20120326.jar
--------------------------------------------------------------------------------
/generator_language_config/library/poi-examples-3.8-20120326.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/generator_language_config/library/poi-examples-3.8-20120326.jar
--------------------------------------------------------------------------------
/generator_language_config/library/poi-excelant-3.8-20120326.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/generator_language_config/library/poi-excelant-3.8-20120326.jar
--------------------------------------------------------------------------------
/generator_language_config/library/poi-ooxml-3.8-20120326.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/generator_language_config/library/poi-ooxml-3.8-20120326.jar
--------------------------------------------------------------------------------
/generator_language_config/library/poi-ooxml-schemas-3.8-20120326.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/generator_language_config/library/poi-ooxml-schemas-3.8-20120326.jar
--------------------------------------------------------------------------------
/generator_language_config/library/poi-scratchpad-3.8-20120326.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/generator_language_config/library/poi-scratchpad-3.8-20120326.jar
--------------------------------------------------------------------------------
/generator_language_config/library/stax-api-1.0.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/generator_language_config/library/stax-api-1.0.1.jar
--------------------------------------------------------------------------------
/generator_language_config/library/xmlbeans-2.3.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/generator_language_config/library/xmlbeans-2.3.0.jar
--------------------------------------------------------------------------------
/generator_language_config/src/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Main-Class: generator_language_config.UIMain
3 |
4 |
--------------------------------------------------------------------------------
/generator_language_config/src/generator_language_config/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Main-Class: generator_language_config.UIMain
3 |
4 |
--------------------------------------------------------------------------------
/generator_language_config/src/generator_language_config/UIMain.java:
--------------------------------------------------------------------------------
1 | package generator_language_config;
2 |
3 | import generator_language_config.ui.MainFrame;
4 |
5 | import javax.swing.*;
6 |
7 | public class UIMain {
8 | public static void main(String[] args) {
9 | SwingUtilities.invokeLater(new Runnable() {
10 | @Override
11 | public void run() {
12 | MainFrame mainFrame = new MainFrame();
13 | }
14 | });
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/generator_language_config/src/generator_language_config/ui/ExcelToStringsFrame.java:
--------------------------------------------------------------------------------
1 | package generator_language_config.ui;
2 |
3 | import generator_language_config.util.ExcelFilter;
4 | import generator_language_config.util.ExcelToStringsUtil;
5 |
6 | import javax.swing.*;
7 | import java.awt.event.ActionEvent;
8 | import java.awt.event.ActionListener;
9 | import java.io.File;
10 | import java.io.IOException;
11 |
12 | public class ExcelToStringsFrame extends JFrame implements ActionListener {
13 | private JButton homeButton;
14 | private JButton openFileButton;
15 | private JTextField openFileTextField;
16 | private JLabel openFileLabel;
17 |
18 | private JButton outputFileButton;
19 | private JTextField outputFileTextField;
20 | private JLabel outputFileLabel;
21 |
22 | private JButton generatorButton;
23 |
24 | private File openFile;
25 | private File outputFile;
26 |
27 | public ExcelToStringsFrame() {
28 | super("Excel生成Strings-Metal");
29 | initUI();
30 | this.setResizable(false);
31 | this.setSize(500, 500);
32 | this.setVisible(true);
33 | this.setLocationRelativeTo(null);
34 | this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
35 | }
36 |
37 | private void initUI() {
38 | this.setLayout(null);
39 | homeButton = new JButton("返回");
40 | homeButton.setBounds(20, 20, 60, 40);
41 | homeButton.addActionListener(this);
42 | this.add(homeButton);
43 |
44 | openFileLabel = new JLabel("Excel:");
45 | openFileLabel.setBounds(60, 90, 40, 40);
46 |
47 | openFileTextField = new JTextField(200);
48 | openFileTextField.setBounds(110, 90, 200, 40);
49 | this.add(openFileTextField);
50 |
51 | openFileButton = new JButton("选择文件");
52 | openFileButton.setBounds(320, 90, 90, 40);
53 | openFileButton.addActionListener(this);
54 | this.add(openFileLabel);
55 | this.add(openFileTextField);
56 | this.add(openFileButton);
57 |
58 | outputFileLabel = new JLabel("生成位置:");
59 | outputFileLabel.setBounds(40, 160, 60, 40);
60 |
61 | outputFileTextField = new JTextField(200);
62 | outputFileTextField.setBounds(110, 160, 200, 40);
63 |
64 |
65 | outputFileButton = new JButton("选择文件");
66 | outputFileButton.setBounds(320, 160, 90, 40);
67 | outputFileButton.addActionListener(this);
68 | this.add(outputFileLabel);
69 | this.add(outputFileTextField);
70 | this.add(outputFileButton);
71 |
72 | generatorButton = new JButton("开始生成");
73 | generatorButton.setBounds(150, 260, 200, 40);
74 | generatorButton.addActionListener(this);
75 | this.add(generatorButton);
76 | }
77 |
78 | @Override
79 | public void actionPerformed(ActionEvent e) {
80 | if (e.getSource() == homeButton) {
81 | MainFrame frame = new MainFrame();
82 | ExcelToStringsFrame.this.dispose();
83 | } else if (e.getSource() == openFileButton) {
84 | selectExcel();
85 | } else if (e.getSource() == outputFileButton) {
86 | selectFile();
87 | } else if (e.getSource() == generatorButton) {
88 | String openFileText = openFileTextField.getText();
89 | if (openFile == null && openFileText != null && !openFileText.equals("")) {
90 | outputFile = new File(openFileText);
91 | }
92 |
93 | if (openFile == null) {
94 | JOptionPane.showMessageDialog(null, "请选择Excel", "提示", JOptionPane.WARNING_MESSAGE);
95 | return;
96 | }
97 | String text = outputFileTextField.getText();
98 |
99 | if (outputFile == null && text != null && !text.equals("")) {
100 | outputFile = new File(text);
101 | }
102 |
103 | if (outputFile == null) {
104 | JOptionPane.showMessageDialog(null, "请选择XML生成位置", "提示", JOptionPane.WARNING_MESSAGE);
105 | return;
106 | }
107 | try {
108 | ExcelToStringsUtil excelUtil = new ExcelToStringsUtil();
109 | excelUtil.readExcel(openFile, outputFile);
110 | JOptionPane.showMessageDialog(null, "生成完毕", "提示", JOptionPane.WARNING_MESSAGE);
111 | } catch (IOException e1) {
112 | JOptionPane.showMessageDialog(null, "很抱歉,发生错误!", "提示", JOptionPane.WARNING_MESSAGE);
113 | e1.printStackTrace();
114 | }
115 | }
116 | }
117 |
118 | private File selectExcel() {
119 | JFileChooser chooser = new JFileChooser();
120 | chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
121 | chooser.setAcceptAllFileFilterUsed(false);
122 | chooser.addChoosableFileFilter(new ExcelFilter());
123 | chooser.showDialog(new JLabel(), "选择");
124 | File file = chooser.getSelectedFile();
125 | if (file != null && file.isFile()) {
126 | openFile = file;
127 | openFileTextField.setText(file.getAbsolutePath());
128 | }
129 | return null;
130 | }
131 |
132 | private File selectFile() {
133 | JFileChooser chooser = new JFileChooser();
134 | chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
135 | chooser.showDialog(new JLabel(), "选择");
136 | File file = chooser.getSelectedFile();
137 | if (file != null && file.isDirectory()) {
138 | outputFile = file;
139 | outputFileTextField.setText(file.getAbsolutePath());
140 | }
141 | return null;
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/generator_language_config/src/generator_language_config/ui/ExcelToXmlFrame.java:
--------------------------------------------------------------------------------
1 | package generator_language_config.ui;
2 |
3 | import generator_language_config.util.ExcelFilter;
4 | import generator_language_config.util.ExcelUtil;
5 |
6 | import javax.swing.*;
7 | import java.awt.event.ActionEvent;
8 | import java.awt.event.ActionListener;
9 | import java.io.File;
10 | import java.io.IOException;
11 |
12 | public class ExcelToXmlFrame extends JFrame implements ActionListener {
13 | private JButton homeButton;
14 | private JButton openFileButton;
15 | private JTextField openFileTextField;
16 | private JLabel openFileLabel;
17 |
18 | private JButton outputFileButton;
19 | private JTextField outputFileTextField;
20 | private JLabel outputFileLabel;
21 |
22 | private JButton generatorButton;
23 |
24 | private File openFile;
25 | private File outputFile;
26 |
27 | public ExcelToXmlFrame() {
28 | super("Excel生成XML-Metal");
29 | initUI();
30 | this.setResizable(false);
31 | this.setSize(500, 500);
32 | this.setVisible(true);
33 | this.setLocationRelativeTo(null);
34 | this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
35 | }
36 |
37 | private void initUI() {
38 | this.setLayout(null);
39 | homeButton = new JButton("返回");
40 | homeButton.setBounds(20, 20, 60, 40);
41 | homeButton.addActionListener(this);
42 | this.add(homeButton);
43 |
44 | openFileLabel = new JLabel("Excel:");
45 | openFileLabel.setBounds(60, 90, 40, 40);
46 |
47 | openFileTextField = new JTextField(200);
48 | openFileTextField.setBounds(110, 90, 200, 40);
49 | this.add(openFileTextField);
50 |
51 | openFileButton = new JButton("选择文件");
52 | openFileButton.setBounds(320, 90, 90, 40);
53 | openFileButton.addActionListener(this);
54 | this.add(openFileLabel);
55 | this.add(openFileTextField);
56 | this.add(openFileButton);
57 |
58 | outputFileLabel = new JLabel("生成位置:");
59 | outputFileLabel.setBounds(40, 160, 60, 40);
60 |
61 | outputFileTextField = new JTextField(200);
62 | outputFileTextField.setBounds(110, 160, 200, 40);
63 |
64 |
65 | outputFileButton = new JButton("选择文件");
66 | outputFileButton.setBounds(320, 160, 90, 40);
67 | outputFileButton.addActionListener(this);
68 | this.add(outputFileLabel);
69 | this.add(outputFileTextField);
70 | this.add(outputFileButton);
71 |
72 | generatorButton = new JButton("开始生成");
73 | generatorButton.setBounds(150, 260, 200, 40);
74 | generatorButton.addActionListener(this);
75 | this.add(generatorButton);
76 | }
77 |
78 | @Override
79 | public void actionPerformed(ActionEvent e) {
80 | if (e.getSource() == homeButton) {
81 | MainFrame frame = new MainFrame();
82 | ExcelToXmlFrame.this.dispose();
83 | } else if (e.getSource() == openFileButton) {
84 | selectExcel();
85 | } else if (e.getSource() == outputFileButton) {
86 | selectFile();
87 | } else if (e.getSource() == generatorButton) {
88 | String openFileText = openFileTextField.getText();
89 | if (openFile == null && openFileText != null && !openFileText.equals("")) {
90 | outputFile = new File(openFileText);
91 | }
92 |
93 | if (openFile == null) {
94 | JOptionPane.showMessageDialog(null, "请选择Excel", "提示", JOptionPane.WARNING_MESSAGE);
95 | return;
96 | }
97 | String text = outputFileTextField.getText();
98 |
99 | if (outputFile == null && text != null && !text.equals("")) {
100 | outputFile = new File(text);
101 | }
102 |
103 | if (outputFile == null) {
104 | JOptionPane.showMessageDialog(null, "请选择XML生成位置", "提示", JOptionPane.WARNING_MESSAGE);
105 | return;
106 | }
107 | try {
108 | ExcelUtil excelUtil = new ExcelUtil();
109 | excelUtil.readExcel(openFile, outputFile);
110 | JOptionPane.showMessageDialog(null, "生成完毕", "提示", JOptionPane.WARNING_MESSAGE);
111 | } catch (IOException e1) {
112 | JOptionPane.showMessageDialog(null, "很抱歉,发生错误!", "提示", JOptionPane.WARNING_MESSAGE);
113 | e1.printStackTrace();
114 | }
115 | }
116 | }
117 |
118 | private File selectExcel() {
119 | JFileChooser chooser = new JFileChooser();
120 | chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
121 | chooser.setAcceptAllFileFilterUsed(false);
122 | chooser.addChoosableFileFilter(new ExcelFilter());
123 | chooser.showDialog(new JLabel(), "选择");
124 | File file = chooser.getSelectedFile();
125 | if (file != null && file.isFile()) {
126 | openFile = file;
127 | openFileTextField.setText(file.getAbsolutePath());
128 | }
129 | return null;
130 | }
131 |
132 | private File selectFile() {
133 | JFileChooser chooser = new JFileChooser();
134 | chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
135 | chooser.showDialog(new JLabel(), "选择");
136 | File file = chooser.getSelectedFile();
137 | if (file != null && file.isDirectory()) {
138 | outputFile = file;
139 | outputFileTextField.setText(file.getAbsolutePath());
140 | }
141 | return null;
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/generator_language_config/src/generator_language_config/ui/MainFrame.java:
--------------------------------------------------------------------------------
1 | package generator_language_config.ui;
2 |
3 | import javax.swing.*;
4 | import java.awt.event.ActionEvent;
5 | import java.awt.event.ActionListener;
6 | import java.util.HashMap;
7 |
8 | public class MainFrame extends JFrame implements ActionListener {
9 | private JButton excelToXmlButton;
10 | private JButton xmlToExcelButton;
11 | private JButton excelToStringsButton;
12 |
13 | public MainFrame() {
14 | super("多语言工具-Metal");
15 | initUI();
16 | this.setResizable(false);
17 | this.setSize(500, 400);
18 | this.setVisible(true);
19 | this.setLocationRelativeTo(null);
20 | this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
21 |
22 | }
23 |
24 | public static String androidKey = "Android-Excel生成XML";
25 | public static String iosKey = "IOS-Excel生成Strings";
26 |
27 | private void initUI() {
28 | this.setLayout(null);
29 |
30 | excelToXmlButton = new JButton(androidKey);
31 | excelToXmlButton.setBounds(130, 100, 240, 40);
32 | this.add(excelToXmlButton);
33 |
34 | // xmlToExcelButton = new JButton("XML生成Excel");
35 | // xmlToExcelButton.setBounds(130, 200, 240, 40);
36 | // this.add(xmlToExcelButton);
37 |
38 | excelToStringsButton = new JButton(iosKey);
39 | excelToStringsButton.setBounds(130, 200, 240, 40);
40 | this.add(excelToStringsButton);
41 |
42 | setEvent();
43 | }
44 |
45 | private void setEvent() {
46 | excelToXmlButton.addActionListener(this);
47 | // xmlToExcelButton.addActionListener(this);
48 | excelToStringsButton.addActionListener(this);
49 | }
50 |
51 | @Override
52 | public void actionPerformed(ActionEvent e) {
53 | String command = e.getActionCommand();
54 | if (command.equals(androidKey)) {
55 | MainFrame.this.dispose();
56 | ExcelToXmlFrame excelToXmlFrame = new ExcelToXmlFrame();
57 | } else if (command.equals("XML生成Excel")) {
58 | MainFrame.this.dispose();
59 | XmlToExcelFrame xmlToExcelFrame = new XmlToExcelFrame();
60 | } else if (command.equals(iosKey)) {
61 | MainFrame.this.dispose();
62 | ExcelToStringsFrame excelToStringsFrame = new ExcelToStringsFrame();
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/generator_language_config/src/generator_language_config/ui/XmlToExcelFrame.java:
--------------------------------------------------------------------------------
1 | package generator_language_config.ui;
2 |
3 | import generator_language_config.util.ExcelUtil;
4 | import generator_language_config.util.XmlFilter;
5 |
6 | import javax.swing.*;
7 | import java.awt.event.ActionEvent;
8 | import java.awt.event.ActionListener;
9 | import java.io.File;
10 | import java.io.IOException;
11 |
12 | public class XmlToExcelFrame extends JFrame implements ActionListener {
13 | private JButton homeButton;
14 | private JButton openFileButton;
15 | private JTextField openFileTextField;
16 | private JLabel openFileLabel;
17 |
18 | private JButton outputFileButton;
19 | private JTextField outputFileTextField;
20 | private JLabel outputFileLabel;
21 |
22 | private JButton generatorButton;
23 |
24 | private String openFilePath;
25 | private File outputFile;
26 |
27 | public XmlToExcelFrame() {
28 | super("XML生成Excel");
29 | initUI();
30 | this.setResizable(false);
31 | this.setSize(500, 500);
32 | this.setVisible(true);
33 | this.setLocationRelativeTo(null);
34 | this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
35 | }
36 |
37 | private void initUI() {
38 | this.setLayout(null);
39 | homeButton = new JButton("返回");
40 | homeButton.setBounds(20, 20, 60, 40);
41 | homeButton.addActionListener(this);
42 | this.add(homeButton);
43 |
44 | openFileLabel = new JLabel("XML:");
45 | openFileLabel.setBounds(60, 90, 40, 40);
46 |
47 | openFileTextField = new JTextField(200);
48 | openFileTextField.setBounds(110, 90, 200, 40);
49 | this.add(openFileTextField);
50 |
51 | openFileButton = new JButton("输入Res目录");
52 | openFileButton.setBounds(320, 90, 90, 40);
53 | openFileButton.addActionListener(this);
54 | this.add(openFileLabel);
55 | this.add(openFileTextField);
56 | this.add(openFileButton);
57 |
58 | outputFileLabel = new JLabel("生成位置:");
59 | outputFileLabel.setBounds(40, 160, 60, 40);
60 |
61 | outputFileTextField = new JTextField(200);
62 | outputFileTextField.setBounds(110, 160, 200, 40);
63 |
64 |
65 | outputFileButton = new JButton("选择文件");
66 | outputFileButton.setBounds(320, 160, 90, 40);
67 | outputFileButton.addActionListener(this);
68 | this.add(outputFileLabel);
69 | this.add(outputFileTextField);
70 | this.add(outputFileButton);
71 |
72 | generatorButton = new JButton("开始生成");
73 | generatorButton.setBounds(150, 260, 200, 40);
74 | generatorButton.addActionListener(this);
75 | this.add(generatorButton);
76 | }
77 |
78 | @Override
79 | public void actionPerformed(ActionEvent e) {
80 | if (e.getSource() == homeButton) {
81 | MainFrame frame = new MainFrame();
82 | XmlToExcelFrame.this.dispose();
83 | } else if (e.getSource() == openFileButton) {
84 | // selectXml();
85 | } else if (e.getSource() == outputFileButton) {
86 | selectFile();
87 | } else if (e.getSource() == generatorButton) {
88 | if (outputFile == null) {
89 | JOptionPane.showMessageDialog(null, "请选择Excel生成位置", "提示", JOptionPane.WARNING_MESSAGE);
90 | return;
91 | }
92 |
93 | String text = openFileTextField.getText();
94 |
95 | if (text == null || text.equals("")) {
96 | JOptionPane.showMessageDialog(null, "请选择XML的位置", "提示", JOptionPane.WARNING_MESSAGE);
97 | return;
98 | }
99 |
100 |
101 | try {
102 | ExcelUtil excelUtil = new ExcelUtil();
103 | excelUtil.writXLSXExcel(text, outputFile);
104 | JOptionPane.showMessageDialog(null, "生成完毕", "提示", JOptionPane.WARNING_MESSAGE);
105 | } catch (IOException e1) {
106 | JOptionPane.showMessageDialog(null, "很抱歉,发生错误!", "提示", JOptionPane.WARNING_MESSAGE);
107 | e1.printStackTrace();
108 | }
109 | }
110 | }
111 |
112 | private File selectXml() {
113 | JFileChooser chooser = new JFileChooser();
114 | chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
115 | chooser.setAcceptAllFileFilterUsed(false);
116 | chooser.addChoosableFileFilter(new XmlFilter());
117 | chooser.showDialog(new JLabel(), "选择");
118 | File file = chooser.getSelectedFile();
119 | if (file != null && file.isDirectory()) {
120 | openFilePath = file.getAbsolutePath();
121 | openFileTextField.setText(file.getAbsolutePath());
122 | }
123 | return null;
124 | }
125 |
126 | private File selectFile() {
127 | JFileChooser chooser = new JFileChooser();
128 | chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
129 | chooser.showDialog(new JLabel(), "选择");
130 | File file = chooser.getSelectedFile();
131 | if (file != null && file.isDirectory()) {
132 | outputFile = file;
133 | outputFileTextField.setText(file.getAbsolutePath());
134 | }
135 | return null;
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/generator_language_config/src/generator_language_config/util/ExcelFilter.java:
--------------------------------------------------------------------------------
1 | package generator_language_config.util;
2 |
3 | import javax.swing.filechooser.FileFilter;
4 | import java.io.File;
5 |
6 | public class ExcelFilter extends FileFilter {
7 | public static final String XLSX = "xlsx";
8 | public static final String XLS = "xls";
9 |
10 |
11 | @Override
12 | public boolean accept(File f) {
13 | if (f.isDirectory()) {
14 | return true;
15 | }
16 | String fileName = f.getName();
17 | int index = fileName.lastIndexOf('.');
18 | if (index > 0 && index < fileName.length() - 1) {
19 | String extension = fileName.substring(index + 1).toLowerCase();
20 | if (extension.equals(XLSX) || extension.equals(XLS))
21 | return true;
22 | }
23 | return false;
24 | }
25 |
26 | @Override
27 | public String getDescription() {
28 | return "xlsx,xls";
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/generator_language_config/src/generator_language_config/util/ExcelToStringsUtil.java:
--------------------------------------------------------------------------------
1 | package generator_language_config.util;
2 |
3 | import org.apache.poi.hssf.usermodel.*;
4 | import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
5 | import org.apache.poi.xssf.usermodel.XSSFCell;
6 | import org.apache.poi.xssf.usermodel.XSSFRow;
7 | import org.apache.poi.xssf.usermodel.XSSFSheet;
8 | import org.apache.poi.xssf.usermodel.XSSFWorkbook;
9 |
10 | import java.io.File;
11 | import java.io.FileInputStream;
12 | import java.io.IOException;
13 | import java.text.DecimalFormat;
14 | import java.text.SimpleDateFormat;
15 | import java.util.ArrayList;
16 | import java.util.LinkedHashMap;
17 | import java.util.List;
18 | import java.util.Map;
19 |
20 | public class ExcelToStringsUtil {
21 | private static final String KEY_FLAG = "key";
22 | public static final String ANNOTATION_FLAG = "##ANN##";
23 | public static final String DEFAULT_FLAG = "default";
24 |
25 | public void readExcel(File inputFile, File outputFile) throws IOException {
26 | if (!inputFile.exists() || !outputFile.exists()) {
27 | throw new IOException("文件不存在");
28 | }
29 | String fileName = inputFile.getName();
30 | String extension = fileName.lastIndexOf(".") == -1 ? "" : fileName.substring(fileName.lastIndexOf(".") + 1);
31 | if ("xls".equals(extension)) {
32 | readXLSExcel(inputFile, outputFile);
33 | } else if ("xlsx".equals(extension)) {
34 | readXLSXExcel(inputFile, outputFile);
35 | } else {
36 | throw new IOException("不支持的文件类型");
37 | }
38 | }
39 |
40 |
41 | private void readXLSExcel(File file, File outputFile) {
42 | try {
43 | HSSFWorkbook hwb = new HSSFWorkbook(new FileInputStream(file));
44 | HSSFSheet sheet = hwb.getSheetAt(0);
45 | HSSFRow row = sheet.getRow(sheet.getFirstRowNum());
46 | if (row == null) {
47 | throw new IOException("row 不存在");
48 | }
49 | HSSFCell cell = row.getCell(row.getFirstCellNum());
50 | String keyCell = cell.getStringCellValue();
51 | //第一行 第一列必须为key字段
52 | if (!KEY_FLAG.equalsIgnoreCase(keyCell)) {
53 | throw new IOException("key 不存在");
54 | }
55 | int startIndex = row.getFirstCellNum() + 1;
56 | int endIndex = row.getLastCellNum();
57 | List fileList = new ArrayList<>();
58 | for (int i = startIndex; i < endIndex; i++) {
59 | fileList.add(row.getCell(i).getStringCellValue());
60 | }
61 | //从第一列开始读
62 | StringsUtil util = new StringsUtil();
63 | for (int i = startIndex; i < endIndex; i++) {
64 | Map map = new LinkedHashMap<>();
65 | for (int j = sheet.getFirstRowNum(); j < sheet
66 | .getPhysicalNumberOfRows(); j++) {
67 | if (j == 0) {
68 | //跳过第一行
69 | continue;
70 | }
71 | row = sheet.getRow(j);
72 | if (row == null) {
73 | break;
74 | }
75 | String key = row.getCell(row.getFirstCellNum()).getStringCellValue();
76 | if (containAnnotationKey(key)) {
77 | map.put(ANNOTATION_FLAG + j, key.replace("", ""));
78 | continue;
79 | }
80 | HSSFCell currentCell = sheet.getRow(j).getCell(i);
81 | Object value = getCellValue(currentCell);
82 | map.put(key, value);
83 | }
84 | File xmlFile = new File(outputFile + File.separator + fileList.get(i - 1) + ".strings");
85 | makeDirectory(xmlFile);
86 | util.writStrings(xmlFile, map);
87 | }
88 | } catch (OfficeXmlFileException officeXmlFileException) {
89 | readXLSXExcel(file, outputFile);
90 | } catch (IOException e) {
91 | e.printStackTrace();
92 | }
93 | }
94 |
95 | private void readXLSXExcel(File file, File outputFile) {
96 | try {
97 | XSSFWorkbook xwb = new XSSFWorkbook(new FileInputStream(file));
98 | // 读取第一章表格内容
99 | XSSFSheet sheet = xwb.getSheetAt(0);
100 | //获取第一行 第一列
101 | XSSFRow row = sheet.getRow(sheet.getFirstRowNum());
102 | if (row == null) {
103 | throw new IOException("row 不存在");
104 | }
105 | String keyCell = row.getCell(row.getFirstCellNum()).getStringCellValue();
106 | //第一行 第一列必须为key字段
107 | if (!KEY_FLAG.equalsIgnoreCase(keyCell)) {
108 | throw new IOException("key 不存在");
109 | }
110 | int startIndex = row.getFirstCellNum() + 1;
111 | int endIndex = row.getLastCellNum();
112 | //获取Top文件目录
113 | List fileList = new ArrayList<>();
114 | for (int i = startIndex; i < endIndex; i++) {
115 | fileList.add(row.getCell(i).getStringCellValue());
116 | }
117 | //从第一列开始读
118 | StringsUtil util = new StringsUtil();
119 | for (int i = startIndex; i < endIndex; i++) {
120 | Map map = new LinkedHashMap<>();
121 | for (int j = sheet.getFirstRowNum(); j < sheet
122 | .getPhysicalNumberOfRows(); j++) {
123 | if (j == 0) {
124 | //跳过第一行
125 | continue;
126 | }
127 | row = sheet.getRow(j);
128 | if (row == null) {
129 | break;
130 | }
131 |
132 | String key = row.getCell(row.getFirstCellNum()).getStringCellValue();
133 | if (containAnnotationKey(key)) {
134 | map.put(ANNOTATION_FLAG + j, key.replace("", ""));
135 | continue;
136 | }
137 | XSSFCell currentCell = sheet.getRow(j).getCell(i);
138 | Object value = getCellValue(currentCell);
139 | map.put(key, value);
140 | }
141 | File xmlFile = new File(outputFile + File.separator + fileList.get(i - 1) + ".strings");
142 | makeDirectory(xmlFile);
143 | System.out.println(map.toString());
144 | util.writStrings(xmlFile, map);
145 | }
146 | } catch (OfficeXmlFileException officeXmlFileException) {
147 | readXLSExcel(file, outputFile);
148 | } catch (IOException e) {
149 | e.printStackTrace();
150 | }
151 | }
152 |
153 | private void makeDirectory(File file) {
154 | if (file.exists()) {
155 | // 文件已经存在,输出文件的相关信息
156 | System.out.println(file.getAbsolutePath());
157 | System.out.println(file.getName());
158 | System.out.println(file.length());
159 | } else {
160 | boolean mkdirs = false;
161 | try {
162 | mkdirs = file.createNewFile();
163 | } catch (IOException e) {
164 | e.printStackTrace();
165 | }
166 | System.out.println("创建文件夹 mkdirs = " + mkdirs);
167 | }
168 | }
169 |
170 | private boolean containAnnotationKey(String key) {
171 | return key.contains("");
172 | }
173 |
174 | private Object getCellValue(HSSFCell cell) {
175 | Object value;
176 | if (cell == null) {
177 | return value = "";
178 | }
179 | switch (cell.getCellType()) {
180 | case HSSFCell.CELL_TYPE_STRING:
181 | value = cell.getStringCellValue();
182 | break;
183 | case HSSFCell.CELL_TYPE_NUMERIC:
184 | DecimalFormat df = new DecimalFormat("0");// 格式化 number String
185 | // 字符
186 | SimpleDateFormat sdf = new SimpleDateFormat(
187 | "yyyy-MM-dd");// 格式化日期字符串
188 | DecimalFormat nf = new DecimalFormat("0");// 格式化数字
189 |
190 | if ("@".equals(cell.getCellStyle().getDataFormatString())) {
191 | value = df.format(cell.getNumericCellValue());
192 | } else if ("General".equals(cell.getCellStyle()
193 | .getDataFormatString())) {
194 | value = nf.format(cell.getNumericCellValue());
195 | } else {
196 | value = sdf.format(HSSFDateUtil.getJavaDate(cell
197 | .getNumericCellValue()));
198 | }
199 | break;
200 | case HSSFCell.CELL_TYPE_BOOLEAN:
201 | value = cell.getBooleanCellValue();
202 | break;
203 | case HSSFCell.CELL_TYPE_BLANK:
204 | value = "";
205 | break;
206 | default:
207 | value = cell.toString();
208 | }
209 |
210 | return value;
211 | }
212 |
213 | private Object getCellValue(XSSFCell cell) {
214 | Object value;
215 | if (cell == null) {
216 | return value = "";
217 | }
218 | switch (cell.getCellType()) {
219 | case XSSFCell.CELL_TYPE_STRING:
220 | value = cell.getStringCellValue();
221 | break;
222 | case XSSFCell.CELL_TYPE_NUMERIC:
223 | DecimalFormat df = new DecimalFormat("0");// 格式化 number String
224 | // 字符
225 | SimpleDateFormat sdf = new SimpleDateFormat(
226 | "yyyy-MM-dd");// 格式化日期字符串
227 | DecimalFormat nf = new DecimalFormat("0");// 格式化数字
228 |
229 | if ("@".equals(cell.getCellStyle().getDataFormatString())) {
230 | value = df.format(cell.getNumericCellValue());
231 | } else if ("General".equals(cell.getCellStyle()
232 | .getDataFormatString())) {
233 | value = nf.format(cell.getNumericCellValue());
234 | } else {
235 | value = sdf.format(HSSFDateUtil.getJavaDate(cell
236 | .getNumericCellValue()));
237 | }
238 | break;
239 | case XSSFCell.CELL_TYPE_BOOLEAN:
240 | value = cell.getBooleanCellValue();
241 | break;
242 | case XSSFCell.CELL_TYPE_BLANK:
243 | value = "";
244 | break;
245 | default:
246 | value = cell.toString();
247 | }
248 | return value;
249 | }
250 |
251 | public static String getFileNameNoEx(String filename) {
252 | if ((filename != null) && (filename.length() > 0)) {
253 | int dot = filename.lastIndexOf('.');
254 | if ((dot > -1) && (dot < (filename.length()))) {
255 | return filename.substring(0, dot);
256 | }
257 | }
258 | return filename;
259 | }
260 | }
261 |
--------------------------------------------------------------------------------
/generator_language_config/src/generator_language_config/util/ExcelUtil.java:
--------------------------------------------------------------------------------
1 | package generator_language_config.util;
2 |
3 | import org.apache.poi.hssf.usermodel.*;
4 | import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
5 | import org.apache.poi.xssf.usermodel.*;
6 | import org.dom4j.DocumentException;
7 |
8 | import java.io.*;
9 | import java.text.DecimalFormat;
10 | import java.text.SimpleDateFormat;
11 | import java.util.*;
12 |
13 | import static generator_language_config.util.ExcelToStringsUtil.getFileNameNoEx;
14 |
15 | public class ExcelUtil {
16 | private static final String KEY_FLAG = "key";
17 | public static final String ANNOTATION_FLAG = "##ANN##";
18 | public static final String DEFAULT_FLAG = "default";
19 |
20 | public void readExcel(File inputFile, File outputFile) throws IOException {
21 | if (!inputFile.exists()) {
22 | throw new IOException("Excel文件不存在");
23 | }
24 |
25 | if (!outputFile.exists()) {
26 | throw new IOException("资源文件");
27 | }
28 | String fileName = inputFile.getName();
29 | String extension = fileName.lastIndexOf(".") == -1 ? "" : fileName.substring(fileName.lastIndexOf(".") + 1);
30 | if ("xls".equals(extension)) {
31 | readXLSExcel(inputFile, outputFile);
32 | } else if ("xlsx".equals(extension)) {
33 | readXLSXExcel(inputFile, outputFile);
34 | } else {
35 | throw new IOException("不支持的文件类型");
36 | }
37 | }
38 |
39 | public void writXLSXExcel(String xmlResPath, File outputFile) throws IOException {
40 | if (xmlResPath == null || xmlResPath.equals("")) {
41 | throw new IOException("文件不存在");
42 | }
43 | try {
44 | Map files = new HashMap<>();
45 | listStringFile(xmlResPath, files);
46 |
47 | Set langs = files.keySet();
48 |
49 | Map> map = new HashMap<>();
50 |
51 |
52 | XSSFWorkbook xwb = new XSSFWorkbook();
53 | XSSFSheet sheet = xwb.createSheet("Sheet1");
54 | XSSFRow row = sheet.createRow(0);
55 | row.createCell(0).setCellValue(KEY_FLAG);
56 |
57 | filterXmlString(files, langs, map, row);
58 |
59 | XSSFCellStyle style = xwb.createCellStyle();
60 | int rowIdx = 1;
61 | for (Map.Entry> entry : map.entrySet()) {
62 | //第三步创建行row:添加表头0行
63 | if (entry.getKey().contains(ANNOTATION_FLAG)) {
64 | continue;
65 | }
66 | XSSFRow createRow = sheet.createRow(rowIdx++);
67 | createRow.createCell(0).setCellValue(entry.getKey());
68 | for (StringEntity entity : entry.getValue()) {
69 | createRow.createCell(entity.cel).setCellValue(entity.value);
70 | }
71 | }
72 | //将excel写入
73 | OutputStream stream = new FileOutputStream(outputFile.getAbsolutePath() + File.separator + getFileNameNoEx("Strings") + ".xlsx");
74 | xwb.write(stream);
75 | stream.close();
76 |
77 |
78 | } catch (Exception e) {
79 | e.printStackTrace();
80 | }
81 | }
82 |
83 | private void filterXmlString(Map files, Set langs, Map> map, XSSFRow row) throws DocumentException {
84 | int col = 1;
85 | for (String lang : langs) {
86 | row.createCell(col).setCellValue(lang);
87 | Map xmls = XMLUtil.readFormatXML(files.get(lang));
88 | for (Map.Entry entry : xmls.entrySet()) {
89 | List stringEntities = map.get(entry.getKey());
90 | if (stringEntities == null) {
91 | stringEntities = new ArrayList<>();
92 | }
93 | StringEntity stringEntity = new StringEntity(lang, entry.getKey(), entry.getValue().toString());
94 | stringEntity.cel = col;
95 | stringEntities.add(stringEntity);
96 | map.put(entry.getKey(), stringEntities);
97 | }
98 |
99 | col++;
100 | }
101 | }
102 |
103 | private void listStringFile(String xmlResPath, Map files) {
104 | File[] tempList = new File(xmlResPath).listFiles();
105 | for (File value : tempList) {
106 | if (value.isFile()) {
107 | if (value.getName().equals("strings.xml")) {
108 | String parent = value.getParent();
109 | String fileFolderName = parent.substring(parent.lastIndexOf(File.separator) + 1);
110 | files.put(fileFolderName.substring(fileFolderName.indexOf("-") + 1), value);
111 | System.out.println(fileFolderName);
112 | }
113 |
114 | } else if (value.isDirectory() && value.toString().contains("values")) {
115 | listStringFile(value.getAbsolutePath(), files);
116 | } else {
117 | // System.out.println("不生成 = " + value.toString());
118 | }
119 | }
120 | }
121 |
122 |
123 | private void readXLSExcel(File file, File outputFile) {
124 | try {
125 | HSSFWorkbook hwb = new HSSFWorkbook(new FileInputStream(file));
126 | HSSFSheet sheet = hwb.getSheetAt(0);
127 | HSSFRow row = sheet.getRow(sheet.getFirstRowNum());
128 | if (row == null) {
129 | throw new IOException("row 不存在");
130 | }
131 | HSSFCell cell = row.getCell(row.getFirstCellNum());
132 | String keyCell = cell.getStringCellValue();
133 | //第一行 第一列必须为key字段
134 | if (!KEY_FLAG.equalsIgnoreCase(keyCell)) {
135 | throw new IOException("key 不存在");
136 | }
137 | int startIndex = row.getFirstCellNum() + 1;
138 | int endIndex = row.getLastCellNum();
139 | List fileList = new ArrayList<>();
140 | for (int i = startIndex; i < endIndex; i++) {
141 | fileList.add(row.getCell(i).getStringCellValue());
142 | }
143 | //从第一列开始读
144 | for (int i = startIndex; i < endIndex; i++) {
145 | Map map = new LinkedHashMap<>();
146 | for (int j = sheet.getFirstRowNum(); j < sheet
147 | .getPhysicalNumberOfRows(); j++) {
148 | if (j == 0) {
149 | //跳过第一行
150 | continue;
151 | }
152 | row = sheet.getRow(j);
153 | if (row == null) {
154 | break;
155 | }
156 | String key = row.getCell(row.getFirstCellNum()).getStringCellValue();
157 |
158 | if (containAnnotationKey(key)) {
159 | map.put(ANNOTATION_FLAG + j, key.replace("", ""));
160 | continue;
161 | }
162 | HSSFCell currentCell = sheet.getRow(j).getCell(i);
163 | Object value = getCellValue(currentCell);
164 |
165 | map.put(key, value);
166 | }
167 | File xmlFile = new File(outputFile + File.separator + "string-" + fileList.get(i - 1) + ".xml");
168 | XMLUtil.writFormatXML(xmlFile, map);
169 | }
170 | } catch (OfficeXmlFileException officeXmlFileException) {
171 | readXLSXExcel(file, outputFile);
172 | } catch (IOException e) {
173 | e.printStackTrace();
174 | }
175 | }
176 |
177 | private void readXLSXExcel(File file, File outputFile) {
178 | try {
179 | XSSFWorkbook xwb = new XSSFWorkbook(new FileInputStream(file));
180 | // 读取第一章表格内容
181 | XSSFSheet sheet = xwb.getSheetAt(0);
182 | //获取第一行 第一列
183 | XSSFRow row = sheet.getRow(sheet.getFirstRowNum());
184 | if (row == null) {
185 | throw new IOException("row 不存在");
186 | }
187 | String keyCell = row.getCell(row.getFirstCellNum()).getStringCellValue();
188 | //第一行 第一列必须为key字段
189 | if (!KEY_FLAG.equalsIgnoreCase(keyCell)) {
190 | throw new IOException("key 不存在");
191 | }
192 | int startIndex = row.getFirstCellNum() + 1;
193 | int endIndex = row.getLastCellNum();
194 | //获取Top文件目录
195 | List fileList = new ArrayList<>();
196 | for (int i = startIndex; i < endIndex; i++) {
197 | fileList.add(row.getCell(i).getStringCellValue());
198 | }
199 | //从第一列开始读
200 | for (int i = startIndex; i < endIndex; i++) {
201 | Map map = new LinkedHashMap<>();
202 | for (int j = sheet.getFirstRowNum(); j < sheet
203 | .getPhysicalNumberOfRows(); j++) {
204 | if (j == 0) {
205 | //跳过第一行
206 | continue;
207 | }
208 | row = sheet.getRow(j);
209 | if (row == null) {
210 | break;
211 | }
212 |
213 | String key = row.getCell(row.getFirstCellNum()).getStringCellValue();
214 | if (containAnnotationKey(key)) {
215 | map.put(ANNOTATION_FLAG + j, key.replace("", ""));
216 | continue;
217 | }
218 | key = key.replace(" ", "_").
219 | replace("%", "").
220 | replace("+", "").
221 | replace("&", "").
222 | replace("<", "").
223 | replace(">", "").
224 | replace("'", "").
225 | replace(",", "_").
226 | replace(".", "").
227 | replace("=", "").
228 | replace("(", "").
229 | replace(")", "").
230 | replace("[", "").
231 | replace("}", "").
232 | replace("]", "").
233 | replace("{", "").
234 | replace("!", "").
235 | replace("@", "").
236 | replace("#", "").
237 | replace("$", "").
238 | replace("^", "").
239 | replace("*", "").
240 | replace(";", "").
241 | replace("/", "").
242 | replace("|", "").
243 | replace(":", "").
244 | toLowerCase();
245 | System.out.println(" key == " + key);
246 | XSSFCell currentCell = sheet.getRow(j).getCell(i);
247 | Object value = getCellValue(currentCell);
248 | if (value instanceof String && (((String) value).length() == 0 || ((String) value).equalsIgnoreCase(""))) {
249 | } else {
250 | map.put(key, value);
251 |
252 | }
253 | }
254 | String lang = fileList.get(i - 1);
255 | File xmlFile = new File(outputFile + File.separator + "values-" + lang + File.separator + "strings" + ".xml");
256 | if (lang.equals("en")) {
257 | xmlFile = new File(outputFile + File.separator + "values" + File.separator + "strings" + ".xml");
258 | }
259 | makeDirectory(xmlFile);
260 | System.out.println(map.toString());
261 | XMLUtil.writFormatXML(xmlFile, map);
262 | }
263 | } catch (OfficeXmlFileException officeXmlFileException) {
264 | readXLSExcel(file, outputFile);
265 | } catch (IOException e) {
266 | e.printStackTrace();
267 | }
268 | }
269 |
270 | private void makeDirectory(File file) {
271 | if (file.exists()) {
272 | // 文件已经存在,输出文件的相关信息
273 | System.out.println(file.getAbsolutePath());
274 | System.out.println(file.getName());
275 | System.out.println(file.length());
276 | } else {
277 | boolean mkdirs = file.getParentFile().mkdirs();
278 | System.out.println("创建文件夹 mkdirs = " + mkdirs);
279 | }
280 | }
281 |
282 | private boolean containAnnotationKey(String key) {
283 | return key.contains("");
284 | }
285 |
286 | private Object getCellValue(HSSFCell cell) {
287 | Object value;
288 | if (cell == null) {
289 | return value = "";
290 | }
291 | switch (cell.getCellType()) {
292 | case HSSFCell.CELL_TYPE_STRING:
293 | value = cell.getStringCellValue();
294 | break;
295 | case HSSFCell.CELL_TYPE_NUMERIC:
296 | DecimalFormat df = new DecimalFormat("0");// 格式化 number String
297 | // 字符
298 | SimpleDateFormat sdf = new SimpleDateFormat(
299 | "yyyy-MM-dd");// 格式化日期字符串
300 | DecimalFormat nf = new DecimalFormat("0");// 格式化数字
301 |
302 | if ("@".equals(cell.getCellStyle().getDataFormatString())) {
303 | value = df.format(cell.getNumericCellValue());
304 | } else if ("General".equals(cell.getCellStyle()
305 | .getDataFormatString())) {
306 | value = nf.format(cell.getNumericCellValue());
307 | } else {
308 | value = sdf.format(HSSFDateUtil.getJavaDate(cell
309 | .getNumericCellValue()));
310 | }
311 | break;
312 | case HSSFCell.CELL_TYPE_BOOLEAN:
313 | value = cell.getBooleanCellValue();
314 | break;
315 | case HSSFCell.CELL_TYPE_BLANK:
316 | value = "";
317 | break;
318 | default:
319 | value = cell.toString();
320 | }
321 |
322 | return value;
323 | }
324 |
325 | private Object getCellValue(XSSFCell cell) {
326 | Object value;
327 | if (cell == null) {
328 | return value = "";
329 | }
330 | switch (cell.getCellType()) {
331 | case XSSFCell.CELL_TYPE_STRING:
332 | value = cell.getStringCellValue();
333 | break;
334 | case XSSFCell.CELL_TYPE_NUMERIC:
335 | DecimalFormat df = new DecimalFormat("0");// 格式化 number String
336 | // 字符
337 | SimpleDateFormat sdf = new SimpleDateFormat(
338 | "yyyy-MM-dd");// 格式化日期字符串
339 | DecimalFormat nf = new DecimalFormat("0");// 格式化数字
340 |
341 | if ("@".equals(cell.getCellStyle().getDataFormatString())) {
342 | value = df.format(cell.getNumericCellValue());
343 | } else if ("General".equals(cell.getCellStyle()
344 | .getDataFormatString())) {
345 | value = nf.format(cell.getNumericCellValue());
346 | } else {
347 | value = sdf.format(HSSFDateUtil.getJavaDate(cell
348 | .getNumericCellValue()));
349 | }
350 | break;
351 | case XSSFCell.CELL_TYPE_BOOLEAN:
352 | value = cell.getBooleanCellValue();
353 | break;
354 | case XSSFCell.CELL_TYPE_BLANK:
355 | value = "";
356 | break;
357 | default:
358 | value = cell.toString();
359 | }
360 | return value;
361 | }
362 |
363 | public static String getFileNameNoEx(String filename) {
364 | if ((filename != null) && (filename.length() > 0)) {
365 | int dot = filename.lastIndexOf('.');
366 | if ((dot > -1) && (dot < (filename.length()))) {
367 | return filename.substring(0, dot);
368 | }
369 | }
370 | return filename;
371 | }
372 | }
373 |
--------------------------------------------------------------------------------
/generator_language_config/src/generator_language_config/util/StringEntity.java:
--------------------------------------------------------------------------------
1 | package generator_language_config.util;
2 |
3 | public class StringEntity {
4 | public String lang;
5 | public String key;
6 | public String value;
7 | public int cel;//第几列
8 | public int row;//第几行
9 |
10 |
11 | public StringEntity(String lang, String key, String value) {
12 | this.lang = lang;
13 | this.key = key;
14 | this.value = value;
15 | }
16 |
17 | public StringEntity() {
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/generator_language_config/src/generator_language_config/util/StringsFilter.java:
--------------------------------------------------------------------------------
1 | package generator_language_config.util;
2 |
3 | import javax.swing.filechooser.FileFilter;
4 | import java.io.File;
5 |
6 | public class StringsFilter extends FileFilter {
7 | public static final String strings = "strings";
8 |
9 |
10 | @Override
11 | public boolean accept(File f) {
12 | if (f.isDirectory()) {
13 | return true;
14 | }
15 | String fileName = f.getName();
16 | int index = fileName.lastIndexOf('.');
17 | if (index > 0 && index < fileName.length() - 1) {
18 | String extension = fileName.substring(index + 1).toLowerCase();
19 | if (extension.equals(strings))
20 | return true;
21 | }
22 | return false;
23 | }
24 |
25 | @Override
26 | public String getDescription() {
27 | return "strings";
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/generator_language_config/src/generator_language_config/util/StringsUtil.java:
--------------------------------------------------------------------------------
1 | package generator_language_config.util;
2 |
3 |
4 | import java.io.*;
5 | import java.util.ArrayList;
6 | import java.util.LinkedHashMap;
7 | import java.util.List;
8 | import java.util.Map;
9 |
10 | public class StringsUtil {
11 | private static final String KEY_FLAG = "key";
12 | public static final String ANNOTATION_FLAG = "##ANN##";
13 | public static final String DEFAULT_FLAG = "default";
14 |
15 | public void readStrings(File inputFile, File outputFile) throws IOException {
16 | if (!inputFile.exists() || !outputFile.exists()) {
17 | throw new IOException("文件不存在");
18 | }
19 | String fileName = inputFile.getName();
20 | String extension = fileName.lastIndexOf(".") == -1 ? "" : fileName.substring(fileName.lastIndexOf(".") + 1);
21 | if ("strings".equals(extension)) {
22 | readStrings1(inputFile);
23 | } else {
24 | throw new IOException("不支持的文件类型");
25 | }
26 | }
27 |
28 | public void writStrings(File file, Map map) throws IOException {
29 | try {
30 | Map readFormatXML = readStrings1(file);
31 | readFormatXML.putAll(map);
32 | map = readFormatXML;
33 | } catch (Exception e) {
34 | e.printStackTrace();
35 | }
36 |
37 | BufferedWriter br = new BufferedWriter(new FileWriter(file.getAbsolutePath()));
38 |
39 | for (String s : map.keySet()) {
40 | String line = s + " = " + map.get(s);
41 | if (!s.startsWith("\"")) {
42 | line = "\"" + s + "\"" + " = " + "\"" + map.get(s) + "\";";
43 | }
44 | br.write(line);
45 | br.newLine();
46 | br.flush();
47 | }
48 | br.close();
49 | }
50 |
51 | private LinkedHashMap readStrings1(File file) {
52 | try {
53 | FileReader reader = new FileReader(file);//定义一个fileReader对象,用来初始化BufferedReader
54 | BufferedReader bReader = new BufferedReader(reader);//new一个BufferedReader对象,将文件内容读取到缓存
55 | StringBuilder sb = new StringBuilder();//定义一个字符串缓存,将字符串存放缓存中
56 | String s = "";
57 | while ((s = bReader.readLine()) != null) {//逐行读取文件内容,不读取换行符和末尾的空格
58 | sb.append(s);//将读取的字符串添加换行符后累加存放在缓存中
59 | }
60 | bReader.close();
61 | String str = sb.toString();
62 | return getKeyAndValues(str);
63 | } catch (Exception e) {
64 | e.printStackTrace();
65 | }
66 | return new LinkedHashMap<>();
67 | }
68 |
69 | private LinkedHashMap getKeyAndValues(String s1) {
70 | LinkedHashMap map = new LinkedHashMap<>();
71 | String[] split = s1.split("\";");
72 |
73 | for (String s : split) {
74 | if (!s.startsWith("\"")) {
75 | int i = s.indexOf("\"");
76 | if (i > 0) {
77 | s = s.substring(i);
78 | }
79 | }
80 |
81 | getKeyValue(map, s);
82 | }
83 | return map;
84 | }
85 |
86 | private void getKeyValue(Map map, String s) {
87 | try {
88 |
89 | String replace = s.replace("\\\"", "");
90 | int start = replace.indexOf("\"", replace.indexOf("\"") + 1);
91 | int end = replace.indexOf("\"", start + 1);
92 |
93 | String regexString = replace.substring(start, end + 1);
94 | String[] strings = s.split(regexString);
95 | if (strings.length > 1) {
96 | map.put(strings[0].replaceFirst("\"", ""), strings[1]);
97 | System.out.println("key = " + strings[0].replaceFirst("\"", ""));
98 | System.out.println("value = " + strings[1]);
99 | } else {
100 | System.out.println("解析失败了 : " + s);
101 | }
102 | } catch (Exception e) {
103 | System.out.println("解析失败了 : " + s);
104 | }
105 | }
106 |
107 |
108 | private void makeDirectory(File file) {
109 | if (file.exists()) {
110 | // 文件已经存在,输出文件的相关信息
111 | System.out.println(file.getAbsolutePath());
112 | System.out.println(file.getName());
113 | System.out.println(file.length());
114 | } else {
115 | boolean mkdirs = file.getParentFile().mkdirs();
116 | System.out.println("创建文件夹 mkdirs = " + mkdirs);
117 | }
118 | }
119 |
120 |
121 | public List removeComments(String[] source) {
122 | // write your code here
123 | List list = new ArrayList<>();
124 | boolean block = false;
125 | String leftString = "";
126 | for (int i = 0; i < source.length; i++) {
127 | String s = source[i];
128 | if (block) {
129 | int i1 = s.indexOf("*/");
130 | if (i1 >= 0) {
131 | String rightString = s.substring(i1 + 2);
132 | leftString += rightString;
133 | source[i] = leftString;
134 | i--;
135 | block = false;
136 | }
137 | } else {
138 | int i1 = s.indexOf("//");
139 | int i2 = s.indexOf("/*");
140 | if (i1 < 0 && i2 < 0) {
141 | if (s.length() > 0) {
142 | list.add(s);
143 | }
144 | } else if (i1 < 0 || (i2 >= 0 && i2 < i1)) {
145 | block = true;
146 | leftString = s.substring(0, i2);
147 | int i3 = s.indexOf("*/", i2 + 2);
148 | if (i3 >= 0) {
149 | String rightString = s.substring(i3 + 2);
150 | leftString += rightString;
151 | source[i] = leftString;
152 | i--;
153 | block = false;
154 | }
155 | } else if (i2 < 0 || i1 < i2) {
156 | String substring = s.substring(0, i1);
157 | if (substring.length() > 0) {
158 | list.add(substring);
159 | }
160 | }
161 | }
162 | }
163 | return list;
164 | }
165 |
166 | public static String getFileNameNoEx(String filename) {
167 | if ((filename != null) && (filename.length() > 0)) {
168 | int dot = filename.lastIndexOf('.');
169 | if ((dot > -1) && (dot < (filename.length()))) {
170 | return filename.substring(0, dot);
171 | }
172 | }
173 | return filename;
174 | }
175 | }
176 |
--------------------------------------------------------------------------------
/generator_language_config/src/generator_language_config/util/XMLUtil.java:
--------------------------------------------------------------------------------
1 | package generator_language_config.util;
2 |
3 | import org.dom4j.*;
4 | import org.dom4j.io.OutputFormat;
5 | import org.dom4j.io.SAXReader;
6 | import org.dom4j.io.XMLWriter;
7 |
8 | import java.io.File;
9 | import java.io.FileOutputStream;
10 | import java.io.IOException;
11 | import java.util.LinkedHashMap;
12 | import java.util.Map;
13 |
14 | import static generator_language_config.util.ExcelUtil.ANNOTATION_FLAG;
15 |
16 | public final class XMLUtil {
17 | public static void writFormatXML(File file, Map map) {
18 |
19 | try {
20 | Map readFormatXML = readFormatXML(file);
21 | readFormatXML.putAll(map);
22 | map = readFormatXML;
23 | } catch (DocumentException e) {
24 | e.printStackTrace();
25 | }
26 |
27 | //拼装写入格式
28 | Document document = DocumentHelper.createDocument();
29 | Element root = document.addElement("resources");
30 | for (Map.Entry entry : map.entrySet()) {
31 | if (entry.getKey().contains(ANNOTATION_FLAG)) {
32 | root.addComment(entry.getValue().toString());
33 | continue;
34 | }
35 | Element element = root.addElement("string");
36 | element.addAttribute("name", entry.getKey());
37 | element.setText(entry.getValue().toString());
38 | }
39 |
40 | // 实例化输出格式对象
41 | OutputFormat format = OutputFormat.createPrettyPrint();
42 | // 设置输出编码
43 | format.setEncoding("UTF-8");
44 | XMLWriter writer;
45 | try {
46 | // 生成XMLWriter对象
47 | writer = new XMLWriter(new FileOutputStream(file), format);
48 | // 开始写入,write方法中包含上面创建的Document对象
49 | writer.write(document);
50 | writer.close();
51 | } catch (IOException e) {
52 | e.printStackTrace();
53 | }
54 | }
55 |
56 | public static Map readFormatXML(File file) throws DocumentException {
57 | if (!file.exists()) {
58 | throw new DocumentException("文件不存在");
59 | }
60 | // 创建saxReader对象
61 | SAXReader reader = new SAXReader();
62 | // 通过read方法读取一个文件 转换成Document对象
63 | Document document = reader.read(file);
64 | //获取根节点元素对象
65 | Element rootElement = document.getRootElement();
66 | Map map = new LinkedHashMap<>();
67 | for (int i = 0, size = rootElement.nodeCount(); i < size; i++) {
68 | Node node = rootElement.node(i);
69 | short nodeType = node.getNodeType();
70 | switch (nodeType) {
71 | case Node.COMMENT_NODE:
72 | map.put(ANNOTATION_FLAG + i, node.getText());
73 | break;
74 | case Node.ELEMENT_NODE:
75 | Element element = (Element) node;
76 | String attributeKey = element.attribute("name").getValue();
77 | String value = element.getText();
78 | map.put(attributeKey, value);
79 | break;
80 | }
81 | }
82 | return map;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/generator_language_config/src/generator_language_config/util/XmlFilter.java:
--------------------------------------------------------------------------------
1 | package generator_language_config.util;
2 |
3 | import javax.swing.filechooser.FileFilter;
4 | import java.io.File;
5 |
6 | public class XmlFilter extends FileFilter {
7 | public static final String TYPE_XMl = "xml";
8 |
9 | @Override
10 | public boolean accept(File f) {
11 | if (f.isDirectory()) {
12 | return true;
13 | }
14 | String fileName = f.getName();
15 | int index = fileName.lastIndexOf('.');
16 | if (index > 0 && index < fileName.length() - 1) {
17 | String extension = fileName.substring(index + 1).toLowerCase();
18 | if (extension.equals(TYPE_XMl) )
19 | return true;
20 | }
21 | return false;
22 | }
23 |
24 | @Override
25 | public String getDescription() {
26 | return TYPE_XMl;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/out/artifacts/generate_strings_tool_jar/dom4j-1.6.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/out/artifacts/generate_strings_tool_jar/dom4j-1.6.1.jar
--------------------------------------------------------------------------------
/out/artifacts/generate_strings_tool_jar/dom4j.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/out/artifacts/generate_strings_tool_jar/dom4j.jar
--------------------------------------------------------------------------------
/out/artifacts/generate_strings_tool_jar/generate_strings_tool.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/out/artifacts/generate_strings_tool_jar/generate_strings_tool.jar
--------------------------------------------------------------------------------
/out/artifacts/generate_strings_tool_jar/poi-3.8-20120326.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/out/artifacts/generate_strings_tool_jar/poi-3.8-20120326.jar
--------------------------------------------------------------------------------
/out/artifacts/generate_strings_tool_jar/poi-examples-3.8-20120326.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/out/artifacts/generate_strings_tool_jar/poi-examples-3.8-20120326.jar
--------------------------------------------------------------------------------
/out/artifacts/generate_strings_tool_jar/poi-excelant-3.8-20120326.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/out/artifacts/generate_strings_tool_jar/poi-excelant-3.8-20120326.jar
--------------------------------------------------------------------------------
/out/artifacts/generate_strings_tool_jar/poi-ooxml-3.8-20120326.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/out/artifacts/generate_strings_tool_jar/poi-ooxml-3.8-20120326.jar
--------------------------------------------------------------------------------
/out/artifacts/generate_strings_tool_jar/poi-ooxml-schemas-3.8-20120326.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/out/artifacts/generate_strings_tool_jar/poi-ooxml-schemas-3.8-20120326.jar
--------------------------------------------------------------------------------
/out/artifacts/generate_strings_tool_jar/poi-scratchpad-3.8-20120326.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/out/artifacts/generate_strings_tool_jar/poi-scratchpad-3.8-20120326.jar
--------------------------------------------------------------------------------
/out/artifacts/generate_strings_tool_jar/stax-api-1.0.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/out/artifacts/generate_strings_tool_jar/stax-api-1.0.1.jar
--------------------------------------------------------------------------------
/out/artifacts/generate_strings_tool_jar/xmlbeans-2.3.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RenshawPeng/generate_strings_tool/256f0ad1205bf3a79bd39b10695d4c76c9263d0b/out/artifacts/generate_strings_tool_jar/xmlbeans-2.3.0.jar
--------------------------------------------------------------------------------
/out/production/generate_strings_tool/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Main-Class: generator_language_config.UIMain
3 |
4 |
--------------------------------------------------------------------------------
/out/production/generate_strings_tool/generator_language_config/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Main-Class: generator_language_config.UIMain
3 |
4 |
--------------------------------------------------------------------------------