Character encoding in resource bundle files

I am developing a multilingual site, using resource bundle files. The problem I'm having is that, while the jsp file is save in UTF-8, and the contentType="text/html; charset=UTF-8", the foreign characters in the bundle files don't display properly unless I save them as "windows-1252". If I copy the text and paste it into the jsp file, it displays correctly.
How can I make the text from the bundle files display the same as the text in the jsp document itself when both files are saved as UTF-8? I'm surprised it doesn't do this by default.

Because resource bundles (the PropertyResoureceBundle class in particular) doesn't know anything about JSP or HTML page encodings. All that class knows is that it needs to load a properties file from the local (server-side) file system. (BTW, if you are using Struts MessageResources, it works the same way). Anyway, it doesn't read the file every time you call for a resource property String, it reads it 1 time, and 1 time only when you call new ResourceBundle().
The API docs (in java.util.Properties) specified that properties files are read using the ISO8895-1 encoding, actually, not the Windows-1252 or whatever the OS defines. So if you store text that's using a different encoding then ISO8895-1, it's going to read the chars incorrectly.
native2ascii converts things to ASCII using Unicode escapes, as I said. (Although, maybe it saves as ISO8895-1, I forget..., or maybe you should specify the output encoding.... you'd have to read the docs on that tool, cuz there's no command-line help.) This is sort-of an exception to the ISO8895-1 thing, in a sense, as all ASCII chars are the same as the first 127 chars of ISO8895-1, so it doesn't matter really.
So in short, it doesn't assume it's in the default Windows encoding, it assumes it's in ISO8895-1. But since the API docs specifically say so, you should abide by those rules.
As for "getting around the problem", yes, it does, actually. See, whatever it reads in that Unicode escaped ASCII text is converted properly to Strings in Java, which are 16-bit Unicode characters, which cover nearly every character set around (English, Chinese, Japanese, Arabic, Cyrillic, etc). When it's in that form, the chars are the Unicode chars and that's it. That's all they need to be. Encodings are only important when writing (and reading back) to files or other byte streams. You have to read in with the same encoding it was written under, otherwise the conversion is not going to be correct (with a few exceptions, but not many).
So that creates a Unicode String in Java, and when you write that to a JSP page or servlet, the output writer used knows from the content type you specified in the page declaration (UTF-8 is typically recommended because it's an efficent way to deal with Unicode chars, particularly in HTML, where most of the HTML tag content is still ASCII text), so it encodes the strings in that encoding.
Get it?

Similar Messages

  • Java: Loading Resource Bundle File with UTF-8

    I have found out all my previous problems now, thank you all for your assitance with this...
    During the time we have worked so solve our problem with UTF-8 charset we have found new problem with this?
    I don't know if this is the right forum to put this up, if not please let us know where to go with this?
    I have prepared both Eclipse (JSP Files) and GlassFish to run all my files in charset UTF-8. Then i got my
    resource bundle files(property files) to use UTF-8 encoding. Everything looks fine in my text editor. Then
    when i upload these pages every character retrieved from my resource bundles look garbled. This is because
    Java loads property files using ISO 8859-1 character encoding.
    This is a problem from Sun i have read on the internet!
    Note: that in JDK 1.6, you can use PropertyResourceBundle constructor to take a Reader which uses UTF-8 encoding.
    please have a look at these links for more info:
    [http://www.kai-mai.com/node/128]
    [http://java.sun.com/javase/6/docs/api/java/util/PropertyResourceBundle.html]
    Note: PropertyResourceBundle can be constructed either from an InputStream or a Reader, which represents a property file.
    Constructing a PropertyResourceBundle instance from an InputStream requires that the input stream be encoded in ISO-8859-1.
    In that case, characters that cannot be represented in ISO-8859-1 encoding must be represented by Unicode Escapes,
    whereas the other constructor which takes a Reader does not have that limitation.
    What i have read and understand is that the real solution to the problem is: Get the fmt lib to use a Reader instead of an
    InputStream. Alternativly if it works get a ResourceBundle instead of creating one that is wrong all the time? I have to create
    my own ResourceBundle instead of using my own fmt lib wich i cannot trust in a way any more. Is this right or am i comletly wrong?
    My WebTexts files, en, sv and ry are my resource property bundles. To be able to read them i will use resource property bundle reader.
    Fmt lib gives me this but it seems that it inciates this in an InputStream (wich is looked to iso-8859-1) instead of a reader who can
    read UTF-8 without no problem. So can i get my fmt lib to change this or not, anybody have an idea about this???

    Torleif wrote:
    Ok, i know there are a few ways of doing this already. The problem is that i have no idea how to use these different problem solving issues. First we have the;
    1. native2ascii command line utility.
    2. use the XML properties format.
    3. other ways of converting from iso-8859-1 to utf-8.
    The last one i have tried already but i never get this to work. So after knowing of 2 standardized solutions you choose to implement your own non-standard soltion? That's usually not a good idea until you've verified that the standardized solution don't help.
    This is also not the best solution to the problem i have to say. This way i will have both properties files and source files to work with and that is to much i think. Either i will use the native2ascii command or use XML properties format like you say here. I need some more insight in how these two work only because i have no idea my self.Uhm .. read [the documentation|http://java.sun.com/javase/6/docs/api/java/util/Properties.html]? loadFromXML/storeToXML work pretty much exactly the same as load/store, except they handle XML. Try it, look at what it produces, learn.
    Could you please help and explain how to use either this native2ascii command line work or how this XML format properties would work for me. Please i need guidance here with this!!![native2ascii is documented as well|http://java.sun.com/javase/6/docs/technotes/tools/windows/native2ascii.html].
    If you have a specific question after reading those, feel free to ask here.
    You really have to work on your Google-fu, it seems to be too weak.

  • Where does the resources bundle files need to be

    Hi All,
    Does any of you knows where all the custom resources bundle files that will be used on BCC need to be?
    I have something like this:
    BCC module /src/com/mycompany/resources/WebAppResources.properties
    But when I try to use it
    This happens
    javax.servlet.jsp.JspException: An error occurred while evaluating custom action attribute "title" with value "${activity.description}": An error occurred while getting property "description" from an instance of class atg.bizui.activity.GenericActivity (java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key manageLoyaltyProgram.description)
    I am trying to use it on a activity that will be used in the ActivityManager:
    This is what I have
    <resource-bundle>com.mycompany.resources.WebAppResources</resource-bundle>
    Do you know if I am missing somehting or putting the files on a wrong location?
    Regards,
    Obed

    Hi Shaik,
    The title of for the source is added http://i.imgur.com/a6WVxsW.png but when I click on it it throws this exception:
    javax.servlet.jsp.JspException: An error occurred while evaluating custom action attribute "value" with value "${activity.displayName}": An error occurred while getting property "displayName" from an instance of class atg.bizui.activity.GenericActivity (java.util.MissingResourceException: Can't find resource for bundle j
    ava.util.PropertyResourceBundle, key emanageLoyaltyProgram.displayName)
    meaning that the properties file is on the classpath, but my genericActivities.xml file is not able to read the properties file.
    Any suggestion?
    Regards,
    Obed

  • How To Change Resource Bundle file's data from Java Class

    Hi
    i have used below code for accessing Resource Bndle from Java Class but here i also want to make change in a particular key and its value.
    please let me know the code i should use to make changes in Resource Bundle file's key and value and saving the same in the file.
    package test;  import java.util.Enumeration;
    import java.util.ResourceBundle;
    public class ResourceBundleTest {
    public static void main(String[] args) {
    ResourceBundle rb = ResourceBundle.getBundle("test.bundletest.mybundle");
    Enumeration <String> keys = rb.getKeys();
    while (keys.hasMoreElements()) {
    String key = keys.nextElement();
    String value = rb.getString(key);
    System.out.println(key + ": " + value);
    Thanks

    With further debugging, I noticed the following line only works in integrated WLS but not in standalone WLS
    resourceBundle = ResourceBundle.getBundle("com.myapp.MyMappings");
    I confirmed the corresponding properties file was included properly in the EAR file but the standalone WLS failed to find the properties file at runtime.
    Why did the standalone WLS class loader (must be the same as the integrated WLS) failed to find the properties file deployed under the WEB-INF/classes path in the EAR file?
    The above line was in a POJO class which has the same classpath as the properties file ie. com.myapp.MappingManager.class.
    It was strange that the class loader could load the POJO class but unable to find the com.myapp.MyMappings.properties in the same classpath!!!
    Is this a bug in standalone WLS?
    Edited by: Pricilla on May 26, 2010 8:52 AM
    Edited by: Pricilla on May 26, 2010 9:01 AM

  • 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 utf-8 in jsp with resource bundle files(Farsi Language) Help !

    Hi,
    I am using jdeveloper and struts and i have a resourcce bundle file that i am writing in Farsi in it.
    my jsp looks like this :
    <%@ page contentType="text/html;charset=UTF-8"%>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <html:form action="IndexAction.do" method="POST" enctype="UTF-8">
    <% request.setCharacterEncoding("UTF-8");%>
    <bean:message key="button.add" /><!-- i get the key from the bundle here-->
    i have saved the bundle file in utf-8 and i have tried native2ascii on it as well.
    i also have response.setContentType("text/html; charset=UTF-8"); in my action file.my browser setting is also utf-8.
    but still i get garbage chars in jsp.
    any idea ?
    thax
    reza

    hello
    i have problem whit write farsi in jsp.
    the charecter is destroy.
    please help me.
    thanks

  • Preloader - Character Encoding on external script files

    Hi,
    I have found a slight bug in the generated preloader file _edgePreload.js.
    Basically when the preloader creates the script elements, it doesnt set the charset attribute which causes issues with foriegn characters in certain browsers including FireFox.
    This can be found on line 11 & line 2 of the minifed published version of the  _edgePreload.js file.
    var k=b.createElement("script"),l,o,e=e||B.errorTimeout;k.src=a;
    The following should also be included after the code above to fix the problem.
    k.type="text/javascript";k.charset="utf-8"
    Is this something that can be include in the next update? or is there any other alternate suggests insted of manually having to add this to the _edgePreload.js each time its published.
    Thanks,
    Nik

    Hi Rhemanth.
    Thanks for your quick respons. Correct me if im wrong - yes yepnope is used to load the scripts however _edgePreload.js file defines what is loaded and what attributes are being set.
    For example - to create a stylesheet element the 'rel' & 'type' attribute are being defined correctly.
    var e=b.createElement("link"),j,c=i?h:c||f;e.href=a,e.rel="stylesheet",e.type="text/css";
    However for script elements the nessecary attributes have not been defined in _edgePreload.js and has been left out of the function.
    Thanks,
    Nik

  • How to set character encoding to Greek in a javascript file in Dreamweaver CS4?

    I have a javascript file built with a text editor some time
    ago, which has Greek characters in one of the variables:
    1.) --> var
    scrollercontent='</font><br><font face="Verdana"
    color="#333333" size="-1">11-04-2008:
    <b>ΜΑΝΩΛΗΣ
    ΜΗΤΣΙΑΣ
    </b><br><img SRC="mitsias2.gif" height=148 width=104
    border="0" /><p></font>' <--
    In DW CS4 it displays as
    2.) --> var
    scrollercontent='</font><br><font face="Verdana"
    color="#333333" size="-1">11-04-2008: <b>???O??S ???S??S
    </b><br><img SRC="mitsias2.gif" height=148 width=104
    border="0" /><p></font>' <--
    When trying to save the corrected content in 1.) I get an
    error message that DW cannot save the Greek characters. I am asked
    to change the character encoding.
    I don't know how to change the character encoding in a js
    file. Is there a "head" file like in HTML? Or how does one
    determine the character encoding in a js file?
    When I change the encoding in the prefereces, which is
    "Western" to "Greek" or "UTF", I have the same result.
    Thanks for help.
    jml

    The .js file and the html need to have the same encoding. If
    your html uses iso-8859-7, then the .js must also use that. But if
    the original text editor created the .js file using utf-8, then
    that is what the html needs to use.

  • Character encoding in internationalization

    hiya everyone,
    gotta small prob... i save a chinese resource bundle file using word as unicode file.. when i invoke the resource bundle and try to get the value for the key... do i need to create a streamreader and specify the encoding? the normal way of just getting the value as string doesn't work in this case...
    any clues????
    Thanx
    xxx

    Also, don't forget the native2ascii.exe utility, you can use that in conjunction with a normal text editot to convert native encoded (eg SHIFT-JIS) text to the latin strings represents by unicode escapes. A good explanation is in another post:
    http://forum.java.sun.com/thread.jsp?forum=16&thread=525427&tstart=0&trange=15
    About the only thing this doesn't mention is that native2ascii writes to the standard output. Anytime I tried to use it to over-write the same file I just ended up with a 0 byte file. ie:
    native2ascii file.properties > file.properties
    doesn't seem to work (under windows anyway). You need to use an intermediate file it seems.
    Regards
    Iain

  • 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

  • Why differing Character Encoding and how to fix it?

    I have PRS-950 and PRS-350 readers, both since 2011.  
    In the last year, I've been getting books with Character Encoding that is not easy to read.  In playing around with my browsers and View -> Encoding menus, I have figured out that it has something to do with the character encoding within the epub files.
    I buy books from several ebook stores and I borrow from the library.
    The problem may be the entire book, but it is usually restricted to a few chapters, with rare occasion where the encoding changes within a chapter.  Usually it is for a whole chapter, not part, and it can be seen in chapters not consecutive to each other.
    It occurs whether the book is downloaded directly to my 950 reader or if I load it to either reader from my computer(s), which are all Mac OS X of several versions fom 10.4 to Mountain Lion.  SInce it happens when the book is downloaded directly, I figure the operating system of my computer is not relevant.
    There are several publishers involved, though Baen (no DRM ebooks) has not so far been one of them.
    If I look at the books with viewers on the computer, the encoding is the same.  I've read them in Calibre, in the Sony Reader App, and in Adobe Digital Editions 2.0.  It's always the same.
    I believe the encoding is inherent to the files.  I would like to fix this if I can to make the books I've purchased, many of them in paper and electronically, more enjoyable to read on my readers.
    Example: I’ve is printed instead of I've.
    ’ for apostrophe
    “ the opening of a quotation,
    â€?  for closing the quotation,
    and I think — is for a hyphen.
    When a sentence had “’m  for " 'm at the beginning of a speech (when the character was slurring his words) it took me a while to figure out how it was supposed to read.
    “’Sides, â€™tis only for a moon.  That ain’t long.â€?
    was in one recent book.
    Translation: " 'Sides, 'tis only for a moon. That ain't long."
    See what I mean? 
    Any ideas?

    Hi
    I wonder if it’s possible to download a free ebook with such issue, in order to make some “tests”.
    Perhaps it’s possible, on free ebooks (without DRM), to add fonts by using softwares like Sigil.

  • Problem with property resource bundles

    I use struts message resource to localize my jsp pages.
    struts message resources itself uses property resource bundles to
    accompolish its task.the problem arises when I try to
    print a message from resource bundle using:
    <bean:message bundle="messages_ir" key="label.username" />
    statement and my resource bundle file has a line like:
    label.username=\u0644\u0646 ,
    but it doesnot show the specified unicode characters. as i have understood it
    only uses the low order bytes in specifed unicdes (e.g \u0644=\u0044).
    plz help me!

    first did you try putting this at the top of the jsp page?
    <%
    page
    language="java"
    pageEncoding="utf-8"
    contentType="text/html;charset=utf-8"
    %>
    then, when using struts, you should also specify the locale:
    <html:html locale="true">
    </html:html>
    hope this helps

  • Resource bundle in content repository

    Hi,
    We have a weblogic portal application. Client wants the flexibility to be able to change the text (labels, paragraphs) without any help from IT i.e no releases or redeployment should be required.
    For static pages htmls have been moved to content repository and that helps.
    However for multilingual jsp labels, headers etc. should we add the resource bundle files(.properties files) to content repository?
    Please suggest. We are using netui tags in UI.

    What are you using to show the message i18n or JSTL? i18n tag libraries have a timed technique of reload. ResourceBundles cant be reloaded (directly). search for a snippet on the web which shows how to reload ResourceBundles.
    should we add the resource bundle files(.properties files) to content repository?So long as you have a way to push the files to all managed servers , store it wherever you want.
    While this is an idealistic scenario of business can update all content consider what happens when a business user changes the key by mistake, makes a formatting error etc that can potentially break your page.

  • Default lookup of resource bundle is wrong ?

    Hi,
    i have defined resource bundle files for localizing purpose, which i define:
      localization.properties
      localization_da.properties (danish language)
      localization_sv.properties (swedish language)
    By default for all other languages than danish & swedish, it should use the localized texts from localization.properties
    However i have a weird scenario: i created a user with English language.
    On the development server, the user uses the localization.properties
    On the test server, the user (with english and all other languages than da/sv) uses the localization_da.properties INSTEAD!?!?
    I found the
    <a href="http://help.sap.com/saphelp_nw04/helpdata/en/42/938297a5061d69e10000000a1553f6/frameset.htm">Lookup of Recource Bundle</a>, which is quite useful but didn't help resolve this problem.
    As it states the locale is determined by the following priorities:
    1. Component locale (there's no setting in this case)
    2. Portal mandatory localte (no setting neither)
    3. User locale (i have set the bebud info and it shows correctly that user has EN language)
    4. Request locate (the request.getLocale also shows the EN language which is correct)
    5. Portal default locale (i checked prtDefault.properties file in both servers, it both set to EN/US as default setting)
    6. System default locale
       - Anyone know how to check JVM default language?
       I checked the windows language setting, both have EN as default so no different in this case neither.
    So how can one server uses the correct resource and another use the wrong resource still, any ideas??
    Are there any other settings i haven't checked yet? Any helps will be very appreciated.
    I think about my work around is to have only 3 resource files:
      localization_en.properties (english and other languages)
      localization_da.properties (danish language)
      localization_sv.properties (swedish language)
    but i don't sure if it's possible to have no default  localization.properties file?

    Hi,
    +"But what is the point of having Bundle class for let say EO"+
    The point is to allow applications to be translated into multiple languages so that - based on the user language setting - the application runs with native labels. This works well with the default properties or Java resource bundle in ADF BC. So what doesn't work is the solution you copied from the AMIS blog and you may want to reach out to them if this works for them and if not why. Oracle support is correct in that they cannot support 3rd party samples and demos
    Frank

  • Wrong default resource bundle is retrieved, anyone?

    Hi,
    i have defined resource bundle files for localizing purpose, which i define:
    localization.properties
    localization_da.properties (danish language)
    localization_sv.properties (swedish language)
    By default for all other languages than danish & swedish, it should use the localized texts from localization.properties
    However i have a weird scenario: i created a user with English language.
    On the development server, the user uses the localization.properties
    On the test server, the user (with english and all other languages than da/sv) uses the localization_da.properties INSTEAD!?!?
    I found the
    <a href="http://help.sap.com/saphelp_nw04/helpdata/en/42/938297a5061d69e10000000a1553f6/frameset.htm">Lookup of Recource Bundle</a>, which is quite useful but didn't help resolve this problem.
    As it states the locale is determined by the following priorities:
    1. Component locale (there's no setting in this case)
    2. Portal mandatory localte (no setting neither)
    3. User locale (i have set the bebud info and it shows correctly that user has EN language)
    4. Request locate (the request.getLocale also shows the EN language which is correct)
    5. Portal default locale (i checked prtDefault.properties file in both servers, it both set to EN/US as default setting)
    6. System default locale
    - Anyone know how to check JVM default language?
    I checked the windows language setting, both have EN as default so no different in this case neither.
    So how can one server uses the correct resource and another use the wrong resource still, any ideas??
    Are there any other settings i haven't checked yet? Any helps will be very appreciated.
    I think about my work around is to have only 3 resource files:
    localization_en.properties (english and other languages)
    localization_da.properties (danish language)
    localization_sv.properties (swedish language)
    but i don't sure if it's possible to have no default localization.properties file?

    Hi Matt,
    > but i don't sure if it's possible to have
    > no default localization.properties file?
    No, that leads to an exception if the language determined for a user is not reflected by some bundle file. You can still duplicate the localization_en.properties file to localization.properties.
    Anyhow, if - for whatever reason - the bundle localization_da.properties got selected for a certain user, it probably also will be selected if you provide additional property files...
    Hope it helps
    Detlev

Maybe you are looking for

  • Adobe Reader 9.4.0

    Wenn ich nach Updates suchen lasse kommt immer eine 1440 Fehlermeldung. Was is da los? Ich besitze Vindows Vista 32 Bit Home Premium. Ich gehe über ein Kabelmodem direkt ohne Proxy in das internet. Danke schon im vorraus. Gruß Treter2

  • Hierachical Tree node(help me please)

    Hi experts, JDEV 11.1.2.0.0 i hav 3 tables say category_1 ,category_2(FK - cat1_code), & category_3( FK - cat1_code&cat2_code)...... I created a BC from these tables and also created a view link from category_1 to category_2 & another view link from

  • Question for "FOR ALL ENTRIES"

    Some materials mentioned that If the table on which the For All Entries IN clause is based is very large, the performance will go down instead of improving. But what's the moderate size of the table used in "FOR ALL ENTRIES"?

  • GUI problem with UNIX

     

  • Web service to return all employees

    Hi I am new to PeopleSoft but have managed to get the OVM template up and running now in virtual box and have the web services working again CI_CI_PERSONAL_DATA.  This returns data for a single employee.  How would I go about creating a web service t