Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Sep 2003

    Localisation and file encoding problems

    I've read all the posts on here and many other places regarding UTF-8 encoded files, using readUTF() etc...

    Here is the problem... I have a "modified" UTF-8 encoded file (not done with notepad), but converted from a UTF-8 linux encoded file to a java modified UTF-8. I am storing the following into the file:

    int - id for the string
    int - length of the string
    the string chars themselves

    I'm aiming to use this to support any language just by changing the 1 resource file.

    Anyway, the idea work perfectly on the Nokia series 60 (tested on 3660), and it works perfectly int the series 40 and series 60 emulators (not that, that really means anything). However, testing on the nokia 6100 has thrown up several issues:

    1. On the 6100 the first int read is 65533 (decimal) which isn't right it should have been 1000.

    2. For some reason on series 60 devices there are 0's being read (ie nulls) from the InputStream, christ knows where they've come from so I'll blame Nokia for the minute, anyway I'm just ignoring them which gets it to work on the series 60.

    3. I'm not getting ANY UnsupportedEncodingException's being thrown, so it would APPEAR that it supports UTF-8.

    4. Inconsistencies (as usual), on the series 60 you can label the encoding as UTF8 or UTF-8, but on the 6100 UTF8 doesn't work (haven't tried lowercase identifiers).

    Here's the code I'm using to read the file:

    		StringBuffer buffer = new  StringBuffer();
    		mStrings = new Hashtable();
    		int id = 0;
    		int length = 0;
    		int charsread = 0;
    		try {
    			InputStream is = getClass().getResourceAsStream(lang_filename);
    			InputStreamReader isr = new InputStreamReader(is, "UTF-8");
    			int ch;
    			int stage = 0; // 0 - read id, 1 - read length, 2, read chars
    			while ((ch = isr.read()) > -1) {
    				// TODO: work out why Nokia adds 0x00 to reads...
    				if (ch == 0)
    				if (stage == 2) {
    					if (charsread == length) {
    						stage = 0;
    						mStrings.put(new Integer(id), new String(buffer.toString()));
    						buffer = null;
    				} else
    				if (stage == 1) {
    					length = ch;
    					stage = 2;
    				} else
    				if (stage == 0) {
    					buffer = new StringBuffer();
    					id = ch;
    					stage = 1;
    					charsread = 0;
    			// show all entries in hashmap
    //			System.out.println("mStrings = " + mStrings.toString());
    		} catch (Exception e) {
    			System.out.println("Unable to load locale Strings");
    Anyone got any ideas why I'm getting such odd results.

    For test the hex for the first entries in the file are:

    CF A8 02 4F 6B

    So the String should be "Ok" with an ID of 1000 (decimal) and a length of 2



  2. #2
    Registered User
    Join Date
    Mar 2003
    Bremen, Germany
    Hi kbateman,

    well, this doesn't solve your original problem but why don't you go with the DataInputStream for reading the data, and DataOutputStream for writing the data?

    Then you could use this code for example:

    DataInputStream is = DataInputStream in = new DataInputStream( getClass().getResourceAsStream(lang_filename) );
    int numberOfTranslations = is.readInt();
    for (int i = 0; i < numberOfTranslations; i ++ ) {
       int id = is.read();
       String translation = is.readUTF();
      // now store the translation...
    When maintaining such files is an issue, there is a "binary data editor" in J2ME Polish:

    That said there is of course also localization support in J2ME Polish:

    In the forthcoming 1.2.4 release that will be published within the next couple of days (or maybe a bit after the start of the CeBIT ;-) there is also support for dynamic translations, so that you can change the translations during the runtime. Of course such dynamic translations are also implemented in an extremely efficient way (no IDs, Hashtable or so are used, just plain old arrays). Also you can use translations with several parameters, e.g.:
    messages.YouHaveWon=Congrats {0}, you have won and got {1} points!
    Translations are maintained in simple text files by the way.

    Let me know if you want to check out a preview.

    All the best,

  3. #3
    Registered User
    Join Date
    Aug 2005

    multilingual apps


    You can use StringDB for your multi-language software.
    No source files for strings.
    It is a OS independent file that you can load at runtime to get the strings.

    You can also change languages/strings at runtime.

    And you dont have to recompile app for language or string changes.

    The tool directly converts string tables in MS Excel files to StringDB.

    You can get read more about it from www.swbox.com.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts