How to use xliff as resource bundle ?

I used to do Java i18n as following base on resource bundle in properties file format:
Locale myLocale = new Locale("es", "ES");
ResourceBundle bundle = ResourceBundle.getBundle("HelloResourceBundle", myLocale);
System.out.println(bundle.getString("Hello"));I realized that there is new bundle called xliff like:
<trans-unit id="Hello">
<source>Hello how are you</source>
<note>This is message to say hello</note>
</trans-unit>Does java resource bundle support xliff file similar to properties file? if not, could anybody give an example how to handle xliff file?
Thanks

Following code worked for me:
import oracle.javatools.resourcebundle.BundleFactory;
import java.util.ResourceBundle;
* This method retrieves localized strings from a given XLIF resource bundle.
* @param bundleName The XLIF bundle from which the localized string is to be retrieved.
* @param key The key of the localized string.
* @return The localized string retrieved from the given XLIF bundle.
public static String getXlifLocalizedString(String bundleName, String key) {
if (StringUtils.isEmpty(key)) {
return key;
if (StringUtils.isEmpty(bundleName)) {
return "[" + key + "]";
String localizedString = null;
ResourceBundle resourceBundle = null;
try {
resourceBundle = BundleFactory.getBundle(bundleName);
localizedString = resourceBundle.getString(key);
} catch (Exception e) {
LOG.log(Level.SEVERE, "Problem in loading XLIF resource bundle: " + bundleName, e);
return "[" + key + "]";
return localizedString;
}

Similar Messages

  • How to use XLIFF file as resource bundle in Java code

    We use xliff as resource bundle for our ADF application. it is has been no problem to have localized message displayed on UI. how ever, I'm wonderring how to use Java code to access xliff as resource bundle which similar to access properties resource bundle. for example:
    Locale myLocale = new Locale("es", "ES");
    ResourceBundle bundle = ResourceBundle.getBundle("HelloResourceBundle", myLocale);
    System.out.println(bundle.getString("Hello"));is it posible to create "HelloResourceBundle" in xliff format?
    Thanks

    Following code worked for me:
    import oracle.javatools.resourcebundle.BundleFactory;
    import java.util.ResourceBundle;
    * This method retrieves localized strings from a given XLIF resource bundle.
    * @param bundleName The XLIF bundle from which the localized string is to be retrieved.
    * @param key The key of the localized string.
    * @return The localized string retrieved from the given XLIF bundle.
    public static String getXlifLocalizedString(String bundleName, String key) {
    if (StringUtils.isEmpty(key)) {
    return key;
    if (StringUtils.isEmpty(bundleName)) {
    return "[" + key + "]";
    String localizedString = null;
    ResourceBundle resourceBundle = null;
    try {
    resourceBundle = BundleFactory.getBundle(bundleName);
    localizedString = resourceBundle.getString(key);
    } catch (Exception e) {
    LOG.log(Level.SEVERE, "Problem in loading XLIF resource bundle: " + bundleName, e);
    return "[" + key + "]";
    return localizedString;
    }

  • How to compare and edit Resource bundle file using java programe

    Hi All
    I have two resource bundle with key, value and some comments. I need to write a java code to compare both of the values of the keys and if the values are different then i want to replace the second value with the first value.
    Its a programe which will udpate the second file with the first file values.
    I tried using Properties class but it didnt worked because when i am saving the file using store method it removes all the comments and the order of text also got disturbed.
    How I need to do this any help appriciated.
    Please elt me know if someone needs more info.
    Thanks in advance.

    Let's assume the ini file is a mapping type storage (key=value) so lets use Properties object. (works with java 1.4 & up)
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Properties;
    public class Test {
         private static Properties props;
         public static void main(String[] args) throws IOException {
              File file = new File("test.ini");//This is out ini file
              props = new Properties();//Create the properties object
              read(file);//Read the ini file
              //Once we've populated the Properties object. set/add a property using the setProperty() method.
              props.setProperty("testing", "value");
              write(file);//Write to ini file
         public static void read(File file) throws IOException {
              FileInputStream fis = new FileInputStream(file);//Create a FileInputStream
              props.load(fis);//load the ini to the Properties file
              fis.close();//close
         public static void write(File file) throws IOException {
              FileOutputStream fos = new FileOutputStream(file);//Create a FileOutputStream
              props.store(fos, "");//write the Properties object values to our ini file
              fos.close();//close
    }

  • Using numbers as resource bundle message references

    I searched (hopefully using the right keywords) but didn't find anything regarding this...how do you use numeric resources in your resource bundle?
    I'm just trying to reuse the message bundle from a different app...the bundle uses all numbers.
    2260=My message
    This tag is in my page...
    <h:outputText value="#{message.2260}"/>
    But I receive the error below...
    Am I missing something? Is there a workaround for this if it is a shortcoming?
    Thanks....
    2004-10-13 09:29:22,093 DEBUG [com.sun.faces.taglib.html_basic.OutputTextTag] - <id: null class: com.sun.faces.taglib.html_basic.OutputTextTag>
    javax.faces.el.ReferenceSyntaxException: Encountered ".2260" at line 1, column 10.
    Was expecting one of:
        ">" ...
        "gt" ...
        "<" ...
        "lt" ...
        "==" ...
        "eq" ...
        "<=" ...
        "le" ...
        ">=" ...
        "ge" ...
        "!=" ...
        "ne" ...
        "+" ...
        "div" ...
        "mod" ...
        "and" ...
        "or" ...
        "||" ...
            at com.sun.faces.application.ApplicationImpl.checkSyntax(ApplicationImpl.java:912)
            at com.sun.faces.application.ApplicationImpl.createValueBinding(ApplicationImpl.java:399)
            at com.sun.faces.util.Util.getValueBinding(Util.java:943)
            at com.sun.faces.taglib.html_basic.OutputTextTag.setProperties(OutputTextTag.java:101)
            at javax.faces.webapp.UIComponentTag.createComponent(UIComponentTag.java:1026)
            at javax.faces.webapp.UIComponentTag.createChild(UIComponentTag.java:1045)
            at javax.faces.webapp.UIComponentTag.findComponent(UIComponentTag.java:732)
            at javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:425)
            at com.sun.faces.taglib.html_basic.OutputTextTag.doStartTag(OutputTextTag.java:149)
            at org.apache.jsp.changeHomeSite_jsp._jspx_meth_h_outputText_16(changeHomeSite_jsp.java:1374)
            at org.apache.jsp.changeHomeSite_jsp._jspx_meth_h_form_0(changeHomeSite_jsp.java:1091)
            at org.apache.jsp.changeHomeSite_jsp._jspx_meth_f_view_0(changeHomeSite_jsp.java:142)
            at org.apache.jsp.changeHomeSite_jsp._jspService(changeHomeSite_jsp.java:93)
            at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
            at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
            at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
            at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
            at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:703)
            at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
            at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
            at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
            at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
            at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:142)
            at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
            at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
            at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
            at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
            at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
            at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
            at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
            at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
            at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
            at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
            at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
            at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
            at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:793)
            at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:702)
            at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:571)
            at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:644)
            at java.lang.Thread.run(Thread.java:534)
    Caused by: com.sun.faces.el.impl.parser.ParseException: Encountered ".2260" at line 1, column 10.
    Was expecting one of:
        ">" ...
        "gt" ...
        "<" ...
        "lt" ...
        "==" ...
        "eq" ...
        "<=" ...
        "le" ...
        ">=" ...
        "ge" ...
        "!=" ...
        "ne" ...
        "+" ...
        "div" ...
        "mod" ...
        "and" ...
        "or" ...
        "||" ...
            at com.sun.faces.el.impl.parser.ELParserImpl.generateParseException(ELParserImpl.java:2229)
            at com.sun.faces.el.impl.parser.ELParserImpl.jj_consume_token(ELParserImpl.java:2097)
            at com.sun.faces.el.impl.parser.ELParserImpl.AttrValueExpression(ELParserImpl.java:105)
            at com.sun.faces.el.impl.parser.ELParserImpl.ExpressionString(ELParserImpl.java:45)
            at com.sun.faces.el.impl.ExpressionEvaluatorImpl.parseExpressionString(ExpressionEvaluatorImpl.java:277)
            at com.sun.faces.el.impl.ExpressionEvaluatorImpl.parseExpression(ExpressionEvaluatorImpl.java:194)
            at com.sun.faces.application.ApplicationImpl.checkSyntax(ApplicationImpl.java:904)
            ... 54 more

    That's it, thanks. (Sub 10 minute response? Supercool--does that merit dukies? (new to posting to the forums))

  • How to use a Java Resource in my java source

    Hello,
    I need to know how to use my external JAR I loaded in the database using this line below:
    CREATE OR REPLACE JAVA RESOURCE NAMED "MyJar" USING BFILE (BFILE_DIR,'MyExternal.jar');
    In fact, I have a Java file using this JAR, but I do not know how to tell to the java source that it have to use this JAR.
    ==========Java Source importing the Jar===================
    package com.gemalto.ws.snmp;
    import java.io.IOException;
    import java.util.Vector;
    import org.snmp4j.Snmp;
    import org.snmp4j.smi.*;
    import org.snmp4j.TransportMapping;
    import org.snmp4j.transport.DefaultUdpTransportMapping;
    import org.snmp4j.CommunityTarget;
    import org.snmp4j.mp.SnmpConstants;
    import org.snmp4j.PDU;
    import org.snmp4j.event.ResponseEvent;
    public class SNMPAgent
    ==========================
    Could you give the SQL request or loadjava command line permitting to do use my java resource file?
    Thks

    The JAR is already load by using CREATE JAVA RESOURCE ... or "loadjava -resolve –force -user p/p@SID –genmissing -jarasresource MyJar.jar"
    If we can create a resource by SQL or loadjava, how can I use it in my java code?
    Edited by: 847873 on 28 mars 2011 06:05
    Edited by: 847873 on 28 mars 2011 06:07

  • Using "{" character in resource bundle.

    Hello,
    I was to use a "{", "}" characters in resource bundle. The problem is that, when I get the resource value, I use the method: MessageUtils.substituteParams in order to replace parameters like {0}, {1}, ...
    Is there a way of escaping the "{", "}" characters with subtitureParams method ? I tried "\{" and it still didn't work.

    Please see the java-api docs for your answer:
    http://java.sun.com/j2se/1.5.0/docs/api/java/text/MessageFormat.html
    Using "\u2019" only works because it is an alternative quote character, but it is not the same as the standard ascii single quote (')
    If you want to include a ' in your format string, then put two next to each other like '' (like Pascal if anyone remembers that ...)
    If you want to quote anything else, then use single quotes to surround the quoted text eg. "The message is '{not a param string}'"

  • How to use a Java Resource??

    Hello,
    I need to know how to use my external JAR I loaded in the database (hosted in Oracle 10.2.04) using this line below:
    CREATE OR REPLACE JAVA RESOURCE NAMED "MyJar" USING BFILE (BFILE_DIR,'MyExternal.jar');
    In fact, I have a Java file using this JAR, but I do not know how to tell to the java source that it have to use this JAR.
    ==========Java Source importing the Jar===================
    package com.gemalto.ws.snmp;
    import java.io.IOException;
    import java.util.Vector;
    import org.snmp4j.Snmp;
    import org.snmp4j.smi.*;
    import org.snmp4j.TransportMapping;
    import org.snmp4j.transport.DefaultUdpTransportMapping;
    import org.snmp4j.CommunityTarget;
    import org.snmp4j.mp.SnmpConstants;
    import org.snmp4j.PDU;
    import org.snmp4j.event.ResponseEvent;
    public class SNMPAgent
    ==========================
    Could you give the SQL request or loadjava command line permitting to do use my java resource file?
    Thks

    Hi,
    I think you should not load the jar as java resource.
    And I think there is no need to tell to the java source that it have to use the JAR. It will automatically look for the library.
    You should load the jar file using the loadjava utility.
    If it can helps, here is how I proceed :
    /* LOAD .JAR FILE */
    loadjava -user your_user/password@host -resolve -verbose -nodefiner C:\jdevstudio1013\jdev\lib\your_lib.jar
    /* LOAD PROGRAM */
    loadjava -user your_user/password@host -resolve -verbose -nodefiner C:\jdevstudio1013\jdev\mywork\your_program.java
    /* CREATE THE PL/SQL FUNCTION */
    create or replace procedure your_function(arg1 in varchar2, arg2 in varchar2) authid current_user as
    language java name 'your_program.your_function(java.lang.String, java.lang.String)';
    /* EXECUTE */
    select your_function('hello','world') from dual;

  • How to enumerate keys in Resource Bundle?

    Is there any way to enumerate all the keys (but not the values) of resource bundle?

    If rb is a ResourceBundle, you can enumerate the keys and values in its 'content' property with the following code:
    for (var key:String in rb.content)
        var value:* = rb.content[key];
    Gordon Smith
    Adobe Flex SDK Team

  • Issue while configuring XLIFF as resource bundle

    We are using Jdeveloper 11.1.1.7.0 ver. We are configuring ADF Faces project for XLIFF by creating xliff file in resources folder and adding xliff file to project properties.
    In design time we are able to see the configured values when we use expression builder however, we are getting following exception at runtime:
    java.util.MissingResourceException: Can't find bundle for base name UIRes, locale en
      at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1521)
      at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1260)

    I am getting issue while configuring report in integrated mode! The issue and the solution to that is as mentioned  here.
    I tried to set the Report Server Service account to Use Another Account
    but when i try to apply i get the issue as below.
    Microsoft.ReportingServices.WmiProvider.WMIProviderException: An unknown error has occurred in the WMI Provider. Error Code 800708AC
    ---> System.Runtime.InteropServices.COMException (0x800708AC): The group name could not be found. (Exception from HRESULT: 0x800708AC)
    --- End of inner exception stack trace ---
    at Microsoft.ReportingServices.WmiProvider.RSWmiAdmin.ThrowOnError(ManagementBaseObject mo)
    at Microsoft.ReportingServices.WmiProvider.RSWmiAdmin.SetWindowsServiceIdentity(String accountName, String password, Boolean useBuiltinAccount)
    at ReportServicesConfigUI.WMIProvider.RSReportServerAdmin.SetWindowsServiceIdentity(String accountName, String password, Boolean useBuiltinAccount)
    Kindly help!
    I have the same error after a change in domain policies and after reconfigure the password of the domain account user used for the Report Server Service Account.
    I don't use a group!!!
    Thank You for any help!
    Alessio

  • How faces-config with two resource bundle???

    Hi all,
    In my application,
    I want to put several message bundle in faces-config.xml.
    How can I do that?
    I defined two message bundle like
    <application>
    <default-render-kit-id>oracle.adf.core</default-render-kit-id>
    <message-bundle>com.resource1</message-bundle>
    <message-bundle>com.resource2</message-bundle>
    <locale-config>
    <supported-locale>en</supported-locale>
    </locale-config>
    </application>
    but the application cannot get messages in resource1 file.

    Hi,
    you need to load the bundles on the page
    <f:loadBundle basename="Bundle" var="msg"/>
    <f:loadBundle basename="Bundle2" var="msg2"/>
    <af:outputText value="#{msg[\'message.key\']}"/>
    <af:outputText value="#{msg2[\'message.key\']}"/>
    Then you can use strings in both properties files. If you only need the strings of one file, delete the other reference
    Frank

  • How to use tomcat JNDI  resource in eclipse

    hi all, In my project i am using JSF,Tomcat,eclipse... i am planing to implement annotaions as part of my application
    I want to use Jndi resource as part of my project by using java annotaions
    for this i configured my server.xml in tomcat as
    <Context docBase="ALWREPORTSNEW" path="/ALWREPORTSNEW"
    reloadable="true"
    source="org.eclipse.jst.jee.server:ALWREPORTSNEW" >
    <Resource auth="Container"
    driverClassName="com.mysql.jdbc.Driver" maxActive="10000"
    maxIdle="3000" maxWait="10000" name="jdbc/enrollmentschema"
    password="adminadmin" removeAbandoned="true"
    removeAbandonedTimeout="300" type="javax.sql.DataSource"
    url="jdbc:mysql://localhost:3306/enrollment_schema_old"
    username="root" />
    </Context>And i configured web.xml as
    <resource-ref>
    <description>Enrollment Schema Connection pooling</description>
    <res-ref-name>jdbc/enrollmentschema</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>And some where in my project i am using annotaion as follows. i am getting NULL when trying access that annotaion .
    @Resource(name = "jdbc/mobileEnrollProd") DataSource mobileds;
    @Resource(name = "jdbc/enrollmentschema")
    private DataSource enrollds;
    public String UploadBankWise() {
    System.out.println("--------- ds "+enrollds);// *i am getting NULL*
    }but same code working with Glassfish and net benas..
    can any body hint me where i did mistake
    thanks in advance

    Go to Window-Preferences-Java-Debug-Step Filtering. When the dialog opens, press F1 for help. Good luck!

  • How to use common resource bundle across all the development components ?

    Hi,
    I am working on SAP NetWeaver Developer Studio - JAVA
    How to use common resource bundle across all the development components ?
    Description :
    I have a requirement of creating a resource bundle (resource.properties) and use that common resource bundle in all the development components.
    Can we create a  development component (war and ear both) and create only resource.properties in this development component( DC ) and create the dependency of the same DC  in all the other DCs ?
    Thanks,
    Neha

    Hello Neha 
    This question is more NWDS related.
    You may have a better chance of someone answering the thread under
    SAP Netweaver -> SAP NetWeaver Development Infrastructure (NWDI, formerly known as JDI) forum
    Thanks
    Kenny

  • How to use resource bundles?

    I have a requirement to translate the test that appears on the custom buttons of my portal application. I know resource bundles are part of .properties file that are delivered in Classes floder. But i am not sure how should i make use of this in translating the button text. It would be grate if someone knows it. I will be  very helpfull.
    Regards,
    Ameya

    Hi Ameya,
    [This link|http://help.sap.com/saphelp_nw04/helpdata/en/74/641640b7b6dd5fe10000000a155106/frameset.htm] will provide you information on how to implement Portal Content Translation.
    [This link|http://help.sap.com/saphelp_nw04/helpdata/en/62/8b1d40bb37e569e10000000a155106/frameset.htm] will explain how to create and access Resource Bundles (read the entire chapter).
    Hope it helps,
    Roy
    Edited by: Roy Cohen on Nov 26, 2008 3:21 PM

  • How to use a resource bundle in viewcontroller project

    How can I create a resource bundle for a viewcontroller project ? Is there any way to add entries to it other than adding manually editing the property file ? so that all the key generated will be unique? How to access a message in the resource bundle in my backing bean so that I can display it in my screen ?
    Thanks
    Suneesh

    Suneesh Raman wrote:
    How to access a message in the resource bundle in my backing bean so that I can display it in my screen ?Take a look at this: http://adfcodebits.blogspot.com/2010/04/bit-5-accessing-resource-bundle-from.html

  • How to deal with resource bundle in multiple applications system

    Hi all,
    I'm building new system depend on the method of
    one common model with multiple applications for the view objects
    my JDeveloper version 11.1.2.3
    my Question
    How can i merge the resource bundle for these applications
    as in the common model exists file for resouce bundle
    and each other applications contains resource bundle files how can i merge all these file in one Resource bundle file ?
    Edited by: 985756 on Apr 2, 2013 12:39 AM

    Hi,
    Please check anerjusb blog for your answer
    Hoping this will help you.
    http://andrejusb.blogspot.in/2009/12/reusing-resource-bundles-from-different.html
    Thanks & Regards,
    Vikas

Maybe you are looking for