Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_76393173
jadx
提交
5281eed1
J
jadx
项目概览
2301_76393173
/
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 搜索 >>
提交
5281eed1
编写于
11月 07, 2018
作者:
J
Jan S
提交者:
skylot
11月 07, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: loading of i18n resources as UTF-8 (see #363) (PR #386)
上级
bedbf94b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
100 addition
and
103 deletion
+100
-103
jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java
jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java
+1
-1
jadx-gui/src/main/java/jadx/gui/utils/NLS.java
jadx-gui/src/main/java/jadx/gui/utils/NLS.java
+99
-102
未找到文件。
jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java
浏览文件 @
5281eed1
...
...
@@ -340,7 +340,7 @@ public class MainWindow extends JFrame {
openFile
();
}
};
openAction
.
putValue
(
Action
.
SHORT_DESCRIPTION
,
NLS
.
str
(
"file.open"
));
openAction
.
putValue
(
Action
.
SHORT_DESCRIPTION
,
NLS
.
str
(
"file.open
_action
"
));
openAction
.
putValue
(
Action
.
ACCELERATOR_KEY
,
getKeyStroke
(
KeyEvent
.
VK_O
,
KeyEvent
.
CTRL_DOWN_MASK
));
Action
saveAllAction
=
new
AbstractAction
(
NLS
.
str
(
"file.save_all"
),
ICON_SAVE_ALL
)
{
...
...
jadx-gui/src/main/java/jadx/gui/utils/NLS.java
浏览文件 @
5281eed1
package
jadx.gui.utils
;
import
java.nio.charset.Charset
;
import
java.util.HashMap
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.ResourceBundle
;
import
java.util.Vector
;
import
org.jetbrains.annotations.NotNull
;
public
class
NLS
{
private
static
final
Charset
JAVA_CHARSET
=
Charset
.
forName
(
"ISO-8859-1"
);
private
static
final
Charset
UTF8_CHARSET
=
Charset
.
forName
(
"UTF-8"
);
private
static
Vector
<
LangLocale
>
i18nLocales
=
new
Vector
<>();
private
static
Map
<
LangLocale
,
Map
<
String
,
String
>>
i18nMessagesMap
=
new
HashMap
<>();
// Use these two fields to avoid invoking Map.get() method twice.
private
static
Map
<
String
,
String
>
localizedMessagesMap
;
private
static
Map
<
String
,
String
>
fallbackMessagesMap
;
private
static
LangLocale
currentLocale
;
private
static
LangLocale
localLocale
;
static
{
localLocale
=
new
LangLocale
(
Locale
.
getDefault
());
i18nLocales
.
add
(
new
LangLocale
(
"en"
,
"US"
));
// As default language
i18nLocales
.
add
(
new
LangLocale
(
"zh"
,
"CN"
));
i18nLocales
.
add
(
new
LangLocale
(
"es"
,
"ES"
));
i18nLocales
.
forEach
(
NLS:
:
load
);
LangLocale
defLang
=
i18nLocales
.
get
(
0
);
fallbackMessagesMap
=
i18nMessagesMap
.
get
(
defLang
);
localizedMessagesMap
=
i18nMessagesMap
.
get
(
defLang
);
}
private
NLS
()
{
}
private
static
void
load
(
LangLocale
locale
)
{
ResourceBundle
bundle
=
ResourceBundle
.
getBundle
(
"i18n/Messages"
,
locale
.
get
());
Map
<
String
,
String
>
resMap
=
new
HashMap
<>();
for
(
String
key
:
bundle
.
keySet
())
{
String
str
=
bundle
.
getString
(
key
);
resMap
.
put
(
key
,
convertCharset
(
str
));
}
i18nMessagesMap
.
put
(
locale
,
resMap
);
}
@NotNull
private
static
String
convertCharset
(
String
str
)
{
return
new
String
(
str
.
getBytes
(
JAVA_CHARSET
),
UTF8_CHARSET
);
}
public
static
String
str
(
String
key
)
{
String
str
=
localizedMessagesMap
.
get
(
key
);
if
(
str
!=
null
)
{
return
str
;
}
return
fallbackMessagesMap
.
get
(
key
);
// definitely exists
}
public
static
String
str
(
String
key
,
LangLocale
locale
)
{
Map
<
String
,
String
>
strings
=
i18nMessagesMap
.
get
(
locale
);
if
(
strings
!=
null
)
{
String
str
=
strings
.
get
(
key
);
if
(
str
!=
null
)
{
return
str
;
}
}
return
fallbackMessagesMap
.
get
(
key
);
// definitely exists
}
public
static
void
setLocale
(
LangLocale
locale
)
{
if
(
i18nMessagesMap
.
containsKey
(
locale
))
{
currentLocale
=
locale
;
}
else
{
currentLocale
=
i18nLocales
.
get
(
0
);
}
localizedMessagesMap
=
i18nMessagesMap
.
get
(
currentLocale
);
}
public
static
Vector
<
LangLocale
>
getI18nLocales
()
{
return
i18nLocales
;
}
public
static
LangLocale
currentLocale
()
{
return
currentLocale
;
}
public
static
LangLocale
defaultLocale
()
{
if
(
i18nMessagesMap
.
containsKey
(
localLocale
))
{
return
localLocale
;
}
// fallback to english if unsupported
return
i18nLocales
.
get
(
0
);
}
}
package
jadx.gui.utils
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.io.Reader
;
import
java.net.URL
;
import
java.nio.charset.Charset
;
import
java.nio.charset.StandardCharsets
;
import
java.util.*
;
import
org.jetbrains.annotations.NotNull
;
public
class
NLS
{
private
static
Vector
<
LangLocale
>
i18nLocales
=
new
Vector
<>();
private
static
Map
<
LangLocale
,
ResourceBundle
>
i18nMessagesMap
=
new
HashMap
<>();
// Use these two fields to avoid invoking Map.get() method twice.
private
static
ResourceBundle
localizedMessagesMap
;
private
static
ResourceBundle
fallbackMessagesMap
;
private
static
LangLocale
currentLocale
;
private
static
LangLocale
localLocale
;
static
{
localLocale
=
new
LangLocale
(
Locale
.
getDefault
());
i18nLocales
.
add
(
new
LangLocale
(
"en"
,
"US"
));
// As default language
i18nLocales
.
add
(
new
LangLocale
(
"zh"
,
"CN"
));
i18nLocales
.
add
(
new
LangLocale
(
"es"
,
"ES"
));
i18nLocales
.
forEach
(
NLS:
:
load
);
LangLocale
defLang
=
i18nLocales
.
get
(
0
);
fallbackMessagesMap
=
i18nMessagesMap
.
get
(
defLang
);
localizedMessagesMap
=
i18nMessagesMap
.
get
(
defLang
);
}
private
NLS
()
{
}
private
static
void
load
(
LangLocale
locale
)
{
ResourceBundle
bundle
;
ClassLoader
classLoader
=
ClassLoader
.
getSystemClassLoader
();
String
resName
=
String
.
format
(
"i18n/Messages_%s.properties"
,
locale
.
get
());
URL
bundleUrl
=
classLoader
.
getResource
(
resName
);
try
(
Reader
reader
=
new
InputStreamReader
(
bundleUrl
.
openStream
(),
StandardCharsets
.
UTF_8
))
{
bundle
=
new
PropertyResourceBundle
(
reader
);
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"Failed to load "
+
resName
,
e
);
}
i18nMessagesMap
.
put
(
locale
,
bundle
);
}
public
static
String
str
(
String
key
)
{
try
{
return
localizedMessagesMap
.
getString
(
key
);
}
catch
(
MissingResourceException
e
)
{
return
fallbackMessagesMap
.
getString
(
key
);
// definitely exists
}
}
public
static
String
str
(
String
key
,
LangLocale
locale
)
{
ResourceBundle
bundle
=
i18nMessagesMap
.
get
(
locale
);
if
(
bundle
!=
null
)
{
try
{
return
bundle
.
getString
(
key
);
}
catch
(
MissingResourceException
e
)
{
}
}
return
fallbackMessagesMap
.
getString
(
key
);
// definitely exists
}
public
static
void
setLocale
(
LangLocale
locale
)
{
if
(
i18nMessagesMap
.
containsKey
(
locale
))
{
currentLocale
=
locale
;
}
else
{
currentLocale
=
i18nLocales
.
get
(
0
);
}
localizedMessagesMap
=
i18nMessagesMap
.
get
(
currentLocale
);
}
public
static
Vector
<
LangLocale
>
getI18nLocales
()
{
return
i18nLocales
;
}
public
static
LangLocale
currentLocale
()
{
return
currentLocale
;
}
public
static
LangLocale
defaultLocale
()
{
if
(
i18nMessagesMap
.
containsKey
(
localLocale
))
{
return
localLocale
;
}
// fallback to english if unsupported
return
i18nLocales
.
get
(
0
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录