1.修复IDEA中无法加载resources文件夹的Bug;2.修改多语言Demo

This commit is contained in:
yangsuiyu
2020-08-28 23:20:34 +08:00
parent 5b7131febf
commit d139cbe3c5
15 changed files with 46 additions and 26 deletions

View File

@@ -936,7 +936,7 @@ When an FXController needs to be internationalized and localized, you need to ad
```java
@FXWindow(mainStage = true, title = "languageDemo")
@FXController(path = "fxml/languageDemo/languageDemo.fxml", locale = FXPlusLocale.SIMPLIFIED_CHINESE)
@FXController(path = "fxml/langDemo/langDemo.fxml", locale = FXPlusLocale.SIMPLIFIED_CHINESE)
public class ChineseController extends FXBaseController {
@FXML
public void clickToOtherLanguage() {
@@ -952,7 +952,7 @@ public class ChineseController extends FXBaseController {
```java
@FXWindow(mainStage = false, title = "languageDemo")
@FXController(path = "fxml/languageDemo/languageDemo.fxml", locale = FXPlusLocale.ENGLISH)
@FXController(path = "fxml/langDemo/langDemo.fxml", locale = FXPlusLocale.ENGLISH)
public class EnglishController extends FXBaseController {
@FXML
public void clickToOtherLanguage() {
@@ -1024,7 +1024,7 @@ register.email=\u90ae\u7bb1
#### Example
The sample code is in `cn.edu.scau.biubiusuisui.example.languageDemo`, the running result as follows:
The sample code is in `cn.edu.scau.biubiusuisui.example.langDemo`, the running result as follows:
![language_demo](README.en/language_demo.gif)

View File

@@ -962,7 +962,7 @@ public enum FXPlusLocale {
```java
@FXWindow(mainStage = true, title = "languageDemo")
@FXController(path = "fxml/languageDemo/languageDemo.fxml", locale = FXPlusLocale.SIMPLIFIED_CHINESE)
@FXController(path = "fxml/langDemo/langDemo.fxml", locale = FXPlusLocale.SIMPLIFIED_CHINESE)
public class ChineseController extends FXBaseController {
@FXML
public void clickToOtherLanguage() {
@@ -978,7 +978,7 @@ public class ChineseController extends FXBaseController {
```java
@FXWindow(mainStage = false, title = "languageDemo")
@FXController(path = "fxml/languageDemo/languageDemo.fxml", locale = FXPlusLocale.ENGLISH)
@FXController(path = "fxml/langDemo/langDemo.fxml", locale = FXPlusLocale.ENGLISH)
public class EnglishController extends FXBaseController {
@FXML
public void clickToOtherLanguage() {
@@ -1050,7 +1050,7 @@ register.email=\u90ae\u7bb1
#### 示例演示
示例代码在`cn.edu.scau.biubiusuisui.example.languageDemo`中,运行可得:
示例代码在`cn.edu.scau.biubiusuisui.example.langDemo`中,运行可得:
![language_demo](README/language_demo.gif)

22
pom.xml
View File

@@ -8,8 +8,8 @@
<groupId>com.gitee.Biubiuyuyu</groupId>
<artifactId>javafx-plus</artifactId>
<version>1.2.0-RELEASE</version>
<packaging>pom</packaging>
<!-- packaging为pom时不会加载resources 故注释-->
<!-- <packaging>pom</packaging>-->
<parent>
<groupId>org.sonatype.oss</groupId>
@@ -38,6 +38,7 @@
<version>3.1</version>
</dependency>
<!-- Junit单元测试 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -56,10 +57,24 @@
<artifactId>tomcat-embed-core</artifactId>
<version>9.0.29</version>
</dependency>
</dependencies>
<build>
<!--配置Maven 对resource文件 过滤 -->
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.fxml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -67,6 +82,7 @@
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<compilerArgs>
<!-- 过期的方法的警告-->
<arg>-Xlint:deprecation</arg>

View File

@@ -1,4 +1,4 @@
package cn.edu.scau.biubiusuisui.example.languageDemo;
package cn.edu.scau.biubiusuisui.example.langDemo;
import cn.edu.scau.biubiusuisui.annotation.FXController;
import cn.edu.scau.biubiusuisui.annotation.FXRedirect;
@@ -15,7 +15,7 @@ import javafx.fxml.FXML;
* @since JDK1.8
*/
@FXWindow(mainStage = true, title = "languageDemo")
@FXController(path = "fxml/languageDemo/languageDemo.fxml", locale = FXPlusLocale.SIMPLIFIED_CHINESE)
@FXController(path = "fxml/langDemo/langDemo.fxml", locale = FXPlusLocale.SIMPLIFIED_CHINESE)
public class ChineseController extends FXBaseController {
@FXML
public void clickToChinese() {

View File

@@ -1,4 +1,4 @@
package cn.edu.scau.biubiusuisui.example.languageDemo;
package cn.edu.scau.biubiusuisui.example.langDemo;
import cn.edu.scau.biubiusuisui.annotation.FXController;
import cn.edu.scau.biubiusuisui.annotation.FXRedirect;
@@ -14,7 +14,7 @@ import javafx.fxml.FXML;
* @since JDK1.8
*/
@FXWindow(mainStage = false, title = "languageDemo")
@FXController(path = "fxml/languageDemo/languageDemo.fxml", locale = FXPlusLocale.ENGLISH)
@FXController(path = "fxml/langDemo/langDemo.fxml", locale = FXPlusLocale.ENGLISH)
public class EnglishController extends FXBaseController {
@FXML
public void clickToChinese() {

View File

@@ -1,4 +1,4 @@
package cn.edu.scau.biubiusuisui.example.languageDemo;
package cn.edu.scau.biubiusuisui.example.langDemo;
import cn.edu.scau.biubiusuisui.annotation.FXController;
import cn.edu.scau.biubiusuisui.annotation.FXRedirect;
@@ -14,7 +14,7 @@ import javafx.fxml.FXML;
* @since JDK1.8
*/
@FXWindow(mainStage = false, title = "languageDemo")
@FXController(path = "fxml/languageDemo/languageDemo.fxml", locale = FXPlusLocale.KOREAN)
@FXController(path = "fxml/langDemo/langDemo.fxml", locale = FXPlusLocale.KOREAN)
public class KoreanController extends FXBaseController {
@FXML
public void clickToChinese() {

View File

@@ -1,4 +1,4 @@
package cn.edu.scau.biubiusuisui.example.languageDemo;
package cn.edu.scau.biubiusuisui.example.langDemo;
import cn.edu.scau.biubiusuisui.annotation.FXScan;
import cn.edu.scau.biubiusuisui.config.FXPlusApplication;
@@ -11,7 +11,7 @@ import javafx.stage.Stage;
* @date 2020/5/3 09:57
* @since JDK1.8
*/
@FXScan(base = "cn.edu.scau.biubiusuisui.example.languageDemo")
@FXScan(base = "cn.edu.scau.biubiusuisui.example.langDemo")
public class LanguageDemo extends Application {
@Override
public void start(Stage primaryStage) throws Exception {

View File

@@ -34,9 +34,13 @@ public class FileUtil {
* @description 读取resources文件夹下的file相对于resources的文件路径如 resources/config.conf 则只需 config.conf
*/
public static String readFileFromResources(String filePath) {
String path = StringUtil.getRootPath(FileUtil.class.getClassLoader().getResource(filePath));
URL url = FileUtil.class.getClassLoader().getResource(filePath);
if (url != null) {
String path = StringUtil.getRootPath(url);
return readFile(path);
}
return "";
}
/**
* @param filePath 绝对路径或相对路径

View File

@@ -119,7 +119,7 @@ public class StringUtil {
}
/**
* cn/edu/scau/biubiusuisui/resources/fxml/languageDemo/languageDemo.fxml -> fxml/languageDemo/languageDemo.fxml
* cn/edu/scau/biubiusuisui/resources/fxml/languageDemo/langDemo.fxml -> fxml/languageDemo/langDemo.fxml
*
* @param name
* @return
@@ -135,7 +135,7 @@ public class StringUtil {
}
/**
* cn/edu/scau/biubiusuisui/resources/fxml/languageDemo/languageDemo.fxml -> languageDemo
* cn/edu/scau/biubiusuisui/resources/fxml/languageDemo/langDemo.fxml -> languageDemo
*
* @param name 文件名
* @return
@@ -144,7 +144,7 @@ public class StringUtil {
public static String getFileBaseName(String name) {
String result = "";
String[] tempStrs = name.split("/");
if (1 == tempStrs.length) { //只有文件名即name: languageDemo.fxml
if (1 == tempStrs.length) { //只有文件名即name: langDemo.fxml
result = StringUtil.trimExtension(name);
} else {
result = StringUtil.trimExtension(tempStrs[tempStrs.length - 1]);

View File

@@ -1 +1 @@
dialog=弹窗
dialog=\u5f39\u7a97

View File

@@ -1 +1 @@
childrenController=子组件
childrenController=\u5b50\u7ec4\u4ef6