Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_39073359
jadx
提交
5193c6a5
J
jadx
项目概览
qq_39073359
/
jadx
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jadx
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
5193c6a5
编写于
8月 03, 2022
作者:
S
Skylot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore: add tool for automatically insert new i18n lines
上级
e7212af5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
126 addition
and
0 deletion
+126
-0
jadx-gui/build.gradle
jadx-gui/build.gradle
+5
-0
jadx-gui/src/main/java/jadx/gui/utils/tools/NLSAddNewLines.java
...ui/src/main/java/jadx/gui/utils/tools/NLSAddNewLines.java
+121
-0
未找到文件。
jadx-gui/build.gradle
浏览文件 @
5193c6a5
...
...
@@ -138,3 +138,8 @@ task distWinWithJre(type: Zip, dependsOn: ['copyDistWinWithJre']) {
}
duplicatesStrategy
=
DuplicatesStrategy
.
EXCLUDE
}
task
addNewNLSLines
(
type:
JavaExec
)
{
classpath
=
sourceSets
.
main
.
runtimeClasspath
mainClass
.
set
(
'jadx.gui.utils.tools.NLSAddNewLines'
)
}
jadx-gui/src/main/java/jadx/gui/utils/tools/NLSAddNewLines.java
0 → 100644
浏览文件 @
5193c6a5
package
jadx.gui.utils.tools
;
import
java.io.IOException
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.List
;
import
java.util.stream.Stream
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* Automatically add new i18n lines from reference (EN) into others languages
*/
public
class
NLSAddNewLines
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
NLSAddNewLines
.
class
);
private
static
final
Path
I18N_PATH
=
Paths
.
get
(
"src/main/resources/i18n/"
);
private
static
final
String
GUI_MODULE_DIR
=
"jadx-gui"
;
public
static
void
main
(
String
[]
args
)
{
try
{
process
();
}
catch
(
Exception
e
)
{
LOG
.
error
(
"Failed to add new i18n lines"
,
e
);
}
}
private
static
void
process
()
throws
Exception
{
String
reference
=
"Messages_en_US.properties"
;
Path
refPath
=
getRefPath
(
reference
);
List
<
String
>
refLines
=
Files
.
readAllLines
(
refPath
);
try
(
Stream
<
Path
>
pathStream
=
Files
.
list
(
refPath
.
toAbsolutePath
().
getParent
()))
{
pathStream
.
forEach
(
path
->
{
if
(
path
.
getFileName
().
equals
(
refPath
.
getFileName
()))
{
return
;
}
try
{
applyFix
(
refLines
,
path
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
});
}
}
private
static
void
applyFix
(
List
<
String
>
refLines
,
Path
path
)
throws
IOException
{
List
<
String
>
lines
=
Files
.
readAllLines
(
path
);
int
linesCount
=
lines
.
size
();
if
(
refLines
.
size
()
<=
linesCount
)
{
LOG
.
info
(
"Skip {}, already fixed"
,
path
);
return
;
}
boolean
updated
=
false
;
for
(
int
i
=
0
;
i
<
linesCount
;
i
++)
{
String
line
=
lines
.
get
(
i
);
String
refLine
=
refLines
.
get
(
i
);
if
(!
isSameKey
(
refLine
,
line
))
{
if
(
refLine
.
isEmpty
())
{
lines
.
add
(
i
,
""
);
}
else
{
lines
.
add
(
i
,
"#"
+
refLine
);
}
updated
=
true
;
}
}
if
(
updated
)
{
LOG
.
info
(
"Updating {}"
,
path
);
Files
.
write
(
path
,
lines
,
StandardCharsets
.
UTF_8
);
}
}
private
static
boolean
isSameKey
(
String
refLine
,
String
line
)
{
int
refLen
=
refLine
.
length
();
int
len
=
line
.
length
();
if
(
refLen
==
0
)
{
return
len
==
0
;
}
if
(
len
==
0
)
{
return
false
;
}
int
pos
=
0
;
// skip comment and spaces
while
(
pos
<
len
)
{
char
ch
=
line
.
charAt
(
pos
);
if
(
ch
==
'#'
||
ch
==
' '
)
{
pos
++;
}
else
{
break
;
}
}
int
refPos
=
0
;
while
(
true
)
{
char
refCh
=
refLine
.
charAt
(
refPos
);
if
(
refCh
==
' '
||
refCh
==
'='
)
{
return
true
;
}
char
ch
=
line
.
charAt
(
pos
);
if
(
refCh
!=
ch
)
{
return
false
;
}
refPos
++;
pos
++;
}
}
private
static
Path
getRefPath
(
String
reference
)
{
Path
path
=
I18N_PATH
.
resolve
(
reference
);
if
(
Files
.
exists
(
path
))
{
return
path
;
}
Path
rootPath
=
Paths
.
get
(
GUI_MODULE_DIR
).
resolve
(
I18N_PATH
).
resolve
(
reference
);
if
(
Files
.
exists
(
rootPath
))
{
return
rootPath
;
}
throw
new
RuntimeException
(
"Can't find reference I18N: "
+
reference
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录