我可以让Java识别我的资源捆绑包吗?
我是Java的新手(通常是编码),我正在尝试了解如何处理本地化,但是当我只是与教程一起关注时,我遇到了一个问题。...找不到我的捆绑包。
这是我的主体
package com.company;
import java.util.Locale;
import java.util.ResourceBundle;
public class Main {
public static void main(String[] args) {
Locale eng = new Locale("en" );
Locale fre = new Locale("fr");
Locale span = new Locale("es");
ResourceBundle englishBundle = ResourceBundle.getBundle("myBundle", eng);
ResourceBundle frenchBundle = ResourceBundle.getBundle("myBundle", fre);
ResourceBundle spanishBundle = ResourceBundle.getBundle("myBundle", span);
System.out.println(englishBundle.getString("hello"));
System.out.println(frenchBundle.getString("hello"));
System.out.println(spanishBundle.getString("hello"));
}
}
,我使用Intellij Create Resource Bundle创建了捆绑包,这为我提供了4个文件。
mybundle.properties
mybundle_en.properties
mybundle_es.properties
mybundle_fr.properties
都有单个翻译
我在我运行一个转换时 我得到以下例外的代码:丢失ResourceException:无法找到基本名称mybundle
的捆绑包
I'm new to Java (and coding in general) and I am trying to understand how to work with localization, but I am running into a problem when just following along with tutorials.... My bundles aren't being found.
here is my main
package com.company;
import java.util.Locale;
import java.util.ResourceBundle;
public class Main {
public static void main(String[] args) {
Locale eng = new Locale("en" );
Locale fre = new Locale("fr");
Locale span = new Locale("es");
ResourceBundle englishBundle = ResourceBundle.getBundle("myBundle", eng);
ResourceBundle frenchBundle = ResourceBundle.getBundle("myBundle", fre);
ResourceBundle spanishBundle = ResourceBundle.getBundle("myBundle", span);
System.out.println(englishBundle.getString("hello"));
System.out.println(frenchBundle.getString("hello"));
System.out.println(spanishBundle.getString("hello"));
}
}
I created the bundle using intelliJ create Resource Bundle which gave me 4 files.
myBundle.properties
myBundle_en.properties
myBundle_es.properties
myBundle_fr.properties
Each file has a single translation hello
When I run the code I get the following exception: MissingResourceException: cant find bundle for base name myBundle
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论