标签: resourcebundle

如何使用JSTL标记检查资源包密钥是否不存在?

我有一个资源文件,它有一些可选的键.如果不存在可选资源键,则设置默认值.似乎没有简单的方法来确定资源包中是否存在密钥.所以这就是我正在做的事情.

<fmt:message var="title" key="login.reg.signup.${signupForm.regfrom}.title" />
<c:if test='${fn:startsWith(title, "??")}'>
    <fmt:message var="title" key="login.reg.signup.default.title" /> 
</c:if>
Run Code Online (Sandbox Code Playgroud)

有没有更好的办法?

java jsp jstl resourcebundle internationalization

10
推荐指数
1
解决办法
5033
查看次数

将参数传递给从资源包到**以外的组件的消息:outputFormat**

是否有一种方便的方法将参数传递给从资源包到除h:outputFormat以外的组件的消息?

例如,这是合法的:

<h:outputFormat value="#{myBundle['parametricMessage']}">
    <f:param value="#{myBundle['someParameterValue']}"/>
</h:outputFormat>
Run Code Online (Sandbox Code Playgroud)

但我需要一个按钮,像这样(这将无法工作):

<h:commandButton value="#{myBundle['parametricMessage']}">
    <f:param value="#{myBundle['someParameterValue']}"/>
</h:commandButton>
Run Code Online (Sandbox Code Playgroud)

当然,我可以使用链接而不是按钮,我可以通过托管bean中的属性来实现,但在这个问题中,我正在寻找一种方便的方式来使用按钮...

我正在使用RichFaces 3.3.3,JSF2,facelets.

jsf resourcebundle richfaces facelets jsf-2

10
推荐指数
1
解决办法
2万
查看次数

放置在文件夹中时,找不到MessageSource的ResourceBundle

我正在尝试使用Spring的Message Source资源包.这是我这样做的方式:

@Component
public class MessageResolver implements MessageSourceAware {

    @Autowired
    private MessageSource messageSource;

    public void setMessageSource(MessageSource messageSource) {
        this.messageSource = messageSource;
    }

    public String getMessage(){
        return messageSource.getMessage("user.welcome", new Object[]{"Rama"} , Locale.US);
    }

}
Run Code Online (Sandbox Code Playgroud)

这是我的文件夹结构:

在此输入图像描述

messages_en_US.properties只包含一行:

user.welcome=Welcome {0}
Run Code Online (Sandbox Code Playgroud)

这是使用的xml配置:

<bean name="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename">
        <value>resourcebundles/messages</value>
    </property>
</bean>
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

WARNING: ResourceBundle [resourcebundles/messages] not found for MessageSource: Can't find bundle for base name resourcebundles/messages, locale en_US
Exception in thread "main" org.springframework.context.NoSuchMessageException: No message found under code 'user.welcome' for locale 'en_US'.
Run Code Online (Sandbox Code Playgroud)

但是,如果我将资源包直接移动到资源文件夹下,它工作正常.在这种情况下,这是我正在使用的xml配置:

<bean name="messageSource" …
Run Code Online (Sandbox Code Playgroud)

resources spring resourcebundle spring-mvc

10
推荐指数
3
解决办法
8万
查看次数

Bean Validation在JSF 2中的resourcebundle参数化可能性?

在JSF 2中使用带有BV的resourcebundle看起来像这样:

public class UserBean {
    @Size(min=13, message="{creditcard.length}")
    public String getCreditCard() {
        return this.creditCard;
    }
}
Run Code Online (Sandbox Code Playgroud)

我必须在其中一个属性文件中定义ResourceBundle条目,该文件可以在 faces-config.xml

creditcard.length =信用卡长度必须至少为13个字符

我们可以看到creditcard.length的值是非参数化的.

我可以进行参数化的ResourceBundle条目,可以从BV或其他地方填充吗?


这是我想要实现的简单方案:

creditcard.length =信用卡长度必须至少为{0}个字符.感谢您选择{1}信用卡.

而我希望这样的事情:

public class UserBean {
    @Size(
        min=13, 
        message="{creditcard.length}", 
        messageParams={"13", "plantvszombie"})
    public String getCreditCard() {
        return this.creditCard;
    }
}
Run Code Online (Sandbox Code Playgroud)

当验证失败时,creditcard属性的错误消息将显示如下字符串:

信用卡长度必须至少为13个字符.感谢您选择plantvszombie信用卡.


这个ResourceBundle消息参数化是否可行?

请分享您对此事的经验.

谢谢 !

java jsf resourcebundle bean-validation jsf-2

9
推荐指数
1
解决办法
1万
查看次数

xcode ios文件无法在捆绑中识别

我想播放视频,但我注意到我的文件没有导入到捆绑包?

所以我只是将AA.mp4文件拖放到我的项目中,

它在项目导航器上显示ok,我在finder中显示它,并确认该项目中存在该文件

现在,当我试试这个

 NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
    NSFileManager *fm = [NSFileManager defaultManager];
    NSArray *dirContents = [fm contentsOfDirectoryAtPath:bundleRoot error:nil];

    NSLog(@"content of bundle ::%@", dirContents);
Run Code Online (Sandbox Code Playgroud)

看到我的包的内容,我看到每个其他文件,但不是我导入的文件???

那么我错过了什么?

谢谢!

xcode resourcebundle objective-c ios

9
推荐指数
1
解决办法
3894
查看次数

ResourceBundle.getBundle("ResourceFile",新的Locale("us","US"))在哪里查找文件?

我正在运行Eclipse并尝试创建一个简单的测试程序,尝试我们的ResourceBundle和几个不同的文件.该文件正确命名为ResourceFile_us_US.properties.但我在getBundle()调用上遇到异常,因为它显然无法找到该文件.它应该放在哪里,以便找到它?

java localization resourcebundle

8
推荐指数
3
解决办法
3万
查看次数

java.util.MissingResourceException:找不到基本名称的包

我正在测试Java的i18n功能并遇到问题,当它不在类根目录中时,我无法加载语言文件.现在我的文件在/lang目录中.

在SO中查看了几个答案,将它放在一个classes子目录中并加载它lang.Messages,使用完整的位置路由/Test/lang/Message(测试是项目名称),使用只是/lang/Message仍然我得到:

java.util.MissingResourceException: Can't find bundle for base name

错误.

还有别的尝试吗?

我的文件结构是:

Test/lang/Messages_es.properties

Test/src/test/Main.java

import java.util.Locale;
import java.util.ResourceBundle;
import javax.swing.JFrame;

public class Main {

     public static void main(String[] args) {

    Locale currentLocale;
    ResourceBundle messages;

    currentLocale = new Locale("es");

    messages = ResourceBundle.getBundle("Messages", currentLocale);
    System.out.println(messages.getString("Messagesgreetings"));
    System.out.println(messages.getString("Messagesinquiry"));
    System.out.println(messages.getString("Messagesfarewell"));
    }
}
Run Code Online (Sandbox Code Playgroud)

java resourcebundle internationalization

8
推荐指数
1
解决办法
6万
查看次数

使用从数据库加载的ResourceBundle条目在JSF中进行国际化

我正在使用JPA/EJB/JSF开发Java EE6项目,我在为实体设计多语言支持方面遇到了一些麻烦.有三个相关实体:

语言(具有id)
能力(具有id)
CompetenceName(具有能力参考,语言参考和字符串)

Competence对使用Map实现的CompetenceName有一对多的引用,每个语言都包含一个对象,其中存在一个Competence的名称.请注意,权限是动态创建的,因此它们的名称不能存在于资源包中.

在网页上列出Competences时,我希望它们以当前登录用户的语言显示,它存储在Session Scoped Managed Bean中.

有没有什么好方法可以在不破坏MVC设计的情况下实现这一目标?我的第一个想法是通过FacesContext直接从Competence实体中的"getName"方法获取会话范围bean,并在CompetenceNames的地图中查找如下:

public class Competence
{
...
@MapKey(name="language")
@OneToMany(mappedBy="competence", cascade=CascadeType.ALL, orphanRemoval=true)
private Map<Language, CompetenceName> competenceNames;

public String getName(String controller){
    FacesContext context = FacesContext.getCurrentInstance();
    ELResolver resolver = context.getApplication().getELResolver();
    SessionController sc = (SessionController)resolver.getValue(context.getELContext(), null, "sessionController");
    Language language = sc.getLoggedInUser().getLanguage();
    if(competenceNames.get(language) != null)
        return competenceNames.get(language).getName();
    else
        return "resource missing";
}
Run Code Online (Sandbox Code Playgroud)

这个解决方案感觉非常粗糙,因为实体依赖于Controller层,并且每次我想要它的名字时都必须获取会话控制器.更符合MVC的解决方案是采用Language参数,但这意味着来自JSF的每一次调用都必须包含从会话作用域托管bean中获取的语言,这也不是一个好的解决方案.

有没有人对此问题有任何想法或设计模式?

database jsf jpa resourcebundle internationalization

8
推荐指数
1
解决办法
5922
查看次数

如何删除周围??? 在捆绑中找不到邮件时

在JSF 2.0中,如果在消息包中找不到消息,则默认情况下,该键被包围???.这是开发过程中非常有用的提示.但是,就我而言,我真的希望那些???不存在.我更喜欢只渲染密钥.

比如我这样做

#{msg.hello}
Run Code Online (Sandbox Code Playgroud)

并且键'hello'不存在,然后页面显示

???你好???

但我想展示一把钥匙

你好

消息包在JSF页面中加载,如下所示:

<f:loadBundle basename="resources.text" var="msg" />
Run Code Online (Sandbox Code Playgroud)

<f:loadBundle>标记似乎没有一个属性来操纵从该包中检索值的方式.我应该覆盖某个类或如何拦截从捆绑中检索消息的方式?

我发现了一篇非常有趣的文章:JavaServer Faces应用程序中的Context Sensitive Resource Bundle条目 - 超越了普通语言,区域和变体语言环境.但是,就我而言,我只想省略???.我认为这个解决方案相当复杂.我怎么能实现呢?

jsf resourcebundle

8
推荐指数
1
解决办法
2996
查看次数

如何使用ResourceBundle

我想,如图掌握的Java应用程序内这里.我不能.我创建了一个ListResourceBundle类似于声明的类,并尝试检索键.我不断得到一个例外.如果您查看教程,它会说使用.class文件.这不可能是对的,可以吗?

[项目树]

在此输入图像描述

[源代码]

以下是我正在使用的两个类,只是MainWindow_xx_XX.java文件中的一个,因为它们基本相同.首先是ListResourceBundle:

public class MainWindow_en_US extends ListResourceBundle {

    @Override
    protected Object[][] getContents() {
        return contents;
    }
    private Object[][] contents = {
        {"fileLabel", "File"},
        {"newSessionLabel", "New session..."},
        {"openSessionLabel", "Open session..."},
        {"saveLabel", "Save"},
        {"exitLabel", "Exit"},
        {"editLabel", "Edit"},
        {"toolsLabel", "Tools"},
        {"helpLabel", "Help"}
    };
}
Run Code Online (Sandbox Code Playgroud)

现在我用它加载它的方法:

    private static final int DEFAULT_LOCALE = 0;
    private ResourceBundle bundle;
    public static Locale locale;
    public static final Locale[] supportedLocales = {
        new Locale("en", "US"),
        new Locale("es", "ES")
    };

public MainWindow() …
Run Code Online (Sandbox Code Playgroud)

java swing netbeans resourcebundle internationalization

8
推荐指数
1
解决办法
2万
查看次数