Multi-lingual Java program
Hi,
The following program from the Sun books, is supposed to work with different languages. Except it doesn't!
It has a problem finding the Properties files (?)
It gives the following Exception:
Exception in thread "main" java.util.MissingResourceException: Can't find bundle
for base name MessagesBundle, locale en_GB
here is the Sun program:
import java.util.*;
public class I18NSample {
static public void main(String[] args) {
String language;
String country;
if (args.length != 2) {
language = new String("en");
country = new String("GB");
} else {
language = new String(args[0]);
country = new String(args[1]);
Locale currentLocale;
ResourceBundle messages;
currentLocale = new Locale(language, country);
messages =ResourceBundle.getBundle("MessagesBundle",currentLocale);
System.out.println(messages.getString("greetings"));
System.out.println(messages.getString("inquiry"));
System.out.println(messages.getString("farewell"));
and I have created several properties file (English, French, German, Arabic) as text files. Maybe I have problems with the properties files.
I have followed the steps from the Java Tutorial book from Sun.
Any help would be most welcome.
Akz
You can create properties files in any text editor, although you're obviously best off with one that can handle the various different characters needed for the different languages.
As a content managmenet issue, I'd suggest not mixing resource bundles with your compiled class files. For one thing, I believe you can and may need to reuse the same properties file for multiple classes. Also it's easier to manage if things are placed in directories based on type.
There's no reason you can't create two directories (or directory hierarchies, really) say "classes/" and "resourceBundles/", and then add both directories to your classpath.
Similar Messages
-
Multi-lingual Java program/problem
Hi,
The following program from the Sun books, is supposed to work with different languages. Except it doesn't!
It has a problem finding the Properties files (?)
It gives the following Exception:
Exception in thread "main" java.util.MissingResourceException: Can't find bundle
for base name MessagesBundle, locale en_GB
here is the Sun program:
import java.util.*;
public class I18NSample {
static public void main(String[] args) {
String language;
String country;
if (args.length != 2) {
language = new String("en");
country = new String("GB");
} else {
language = new String(args[0]);
country = new String(args[1]);
Locale currentLocale;
ResourceBundle messages;
currentLocale = new Locale(language, country);
messages =ResourceBundle.getBundle("MessagesBundle",currentLocale);
System.out.println(messages.getString("greetings"));
System.out.println(messages.getString("inquiry"));
System.out.println(messages.getString("farewell"));
and I have created several properties file (English, French, German, Arabic) as text files. Maybe I have problems with the properties files.
I have followed the steps from the Java Tutorial book from Sun.
Any help would be most welcome.
AkzFirst save a java file "MessageBundle.java" in your current directory, for the moment. Then save java files "MessagesBundle_en_GB.java", "MessagesBundle_fr_FR", "MessagesBundle_de_DE" or "MessagesBundle_ar_EG" for example. Compile them to class files.
Then try using your code with various locales. -
Multi Lingual String not getting displayed properly with Java 1.5.4
Hi,
I have a strange problem and i think the problem is due to java 1.5.4.
Problem is:
My application was previously deployed on weblogic6.1 server and jdk used was 1.3.1
After i migrated my application to weblogic 9.2 and started using jdk 1.5.4, i am not able to correctly view the data which is stored in different languages on browser.
Some more details:
OS - Linux.
Database - Informix 9.2
Intresting part is :
If i enter a new multi lingual string from my application (deployed on WLS 9.2 with JDK 1.5.4) and store it in database, and then try to retreive it, it is displayed correctly.
Issue arises only when the multi lingual string created and stored in database from my old application (deployed on WLS 6.1 with JDK 1.3.1) is retrieved and displayed in the new application (WLS 9.2 with JDK 1.5.4).
Hope my issue is clear and if any one has any clue as to how to solve this issue. Kindly helpOne thread is enough.
http://forum.java.sun.com/thread.jspa?messageID=9651015 -
Helps!:How to start multi process in a single java program?
I wanna to test the querying performance of a Database
connection poll,and here,not only multi threads,but also multi process I need to start in the same java program cause i have only one PC available.....
Does that possible?In pure java this is not possible.
A java program with all its thread run in a single
jvm,
which is just one process.However, you can have multiple instances of the jvm, I've done it w/ I needed to test some row locking in my database app. If you are in windows and want 3 copies of you program just make a bat file that looks likejavaw.exe -classpath "classesGoHere" MainClass
javaw.exe -classpath "classesGoHere" MainClass
javaw.exe -classpath "classesGoHere" MainClassThat will create 3 instances of the jvm and thus three instances of your application. I'm sure the same can be done on multiple platforms.
Peter -
Multi-lingual Translator component in java?
hello all,
I want to make a Multi-lingual Translator component in java
which can be used to convert any existing web site(developed
using any technology asp/jsp etc) to any foreign language
viz german, spanish,italian and other major foreign
languages.
Please let me know how do i proceed in java with respect to
the following?:
1. It has to be developed as a component in java such that
it can be included in any existing web site as a control
which simply gives the users the option of converting
either the current web page from english to any other
foreign language or simply the entire web site from
english to any other foreign language
How to develop it as a component so that it can be
independently merged into any existing web site(whether
asp or jsp) as a control? which technology should i be
using here EJB's or Applets or any other?
I personally think it can be a applet because with EJB's
container/application server is required.
what do you all suggest?
2. I don't want to use any free translators that are
available freely on net these days, because a lot of them
re-directs to their own translation page and includes
their own banners and or advertisements etc., which may
not be feasible with us as we have to include this
utility on our company's web sites
3. How much time it should take approximately to develop?
4. If there's any free tool available however without the
limitations as mentioned above in point 2, then i am not
averse to using it please let me know if such a tool is
available.
5. Please also let me know if there exists already a multi-
lingual component in java with source code freely
available anywhere on net, then please give me the link.
This will help me save a lot of time in developing it.
Please let me know the answers to above of my queries and
u"ll be doing a great deal of help here.
Thanks in advance
sd76JS supports UTF-8... assuming the browser has the proper fonts.
// _lang.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Language Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body bgcolor="#ffffff" background="" text="#000000" link="#ff0000" vlink="#800000" alink="#ff00ff">
<%
request.setCharacterEncoding("UTF-8");
String str = "\u7528\u6237\u540d";
String name = request.getParameter("name");
// OR instead of setCharacterEncoding...
//if(name != null) {
// name = new String(name.getBytes("ISO8859_1"), "UTF8");
System.out.println(application.getRealPath("/"));
System.out.println(application.getRealPath("/src"));
%>
req enc: <%= request.getCharacterEncoding() %><br />
rsp enc: <%= response.getCharacterEncoding() %><br />
str: <%= str %><br />
name: <%= name %><br />
<script language="Javascript">
alert('<%= name %>'); // should show correctly
</script>
<form method="POST" action="_lang.jsp">
Name: <input type="text" name="name" value="" >
<input type="submit" name="submit" value="Submit POST" />
</form>
<br />
<form method="GET" action="_lang.jsp">
Name: <input type="text" name="name" value="" >
<input type="submit" name="submit" value="Submit GET" />
</form>
</body>
</html> -
Maintaining default locale in multi-lingual application
Hello,
I have a multi-lingual application where the language can be changed at runtime.
To make the following code work properly, the default locale has to be set each
time the language changes. Why?
Since I need to check sometimes the platforms original locale (I do this with
"Locale.getDefault()"), I am looking for a way not to change the default locale,
but still to change the resourceBundle.
In the API I read under "ResourceBundle, Cache Management" that the bundles are cached. Is this the reason why redefining the resourceBundle has no effect? And if yes, how can it be avoided?
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class Y extends JFrame {
boolean toggle;
Locale currentLocale;
JButton b;
ResourceBundle languageBundle;
String country, userLanguage;
public Y() {
setSize(300,300);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Container cp= getContentPane();
b= new JButton();
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
toggle= !toggle;
if (toggle)
country= "DE";
else
country= "GB";
setUserLanguage(country);
cp.add(b, BorderLayout.SOUTH);
setUserLanguage("GB");
setVisible(true);
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Y();
void setUserLanguage(String country) {
if (country.equals("DE"))
userLanguage= "de";
else
userLanguage= "en";
currentLocale = new Locale(userLanguage, country);
// System.out.println(currentLocale); // The locale changes ...
// Locale.setDefault(currentLocale); // Remove comment slashes and it works.
// languageBundle.clearCache(); // No effect.
languageBundle = ResourceBundle.getBundle("MyBundle",currentLocale);
System.out.println(languageBundle); // ... but the resourceBundle does not change.
b.setText(languageBundle.getString("ButtonText"));
The resource bundle files:
MyBundle.properties
ButtonText= Just a button
MyBundle_de_DE.properties
ButtonText= Nur ein KnopfEdited by: Joerg22 on 18.08.2008 13:26What's your default locale? If your default locale is de_DE, that's the expected behavior. The reason for it is the fallback mechanism searches default locale's bundle before falls back to the base bundle, i.e., in case of searching en_GB bundle, the search order is:
en_GB
en
de_DE
de
(base)
So, it will choose MyBundles_de_DE.
If you do not want this default locale fallback, you can specify ResourceBundle.Control instance, which is returned from ResourceBundle.Control.getNoFallbackControl() method, in your getBundle() call. Or if you do not use JDK6, you could copy the base bundle to MyBundles_en, which is ugly but should work.
Naoto
Edited by: naoto on Aug 18, 2008 1:05 PM -
How to find cd rom drive in windows and unix platform using java program
Hi,
I am having the requirement of finding the cd rom drive
using java program. I do not know the label and which
one is the cd rom drive. also I want to know how many
cd rom drives are there on my system. I want the solution
for windows and unix platforms.
If have any suggestions please mail to [email protected]
DeepakUghhh.. I had the same problem with multi platform file-system detection
First off - Unix.
Do you know for sure you have all your drives mounted?? This could be a big problem because java will not see unmounted drives... So you can scour thru your /etc/fstab to find out which drives are available... or you can mount all and show roots... (Yuck!)... You've got timeouts and all sorts of things to worry about...
I would then shy away from the java.io.File.listRoots() on unix and rely on parsing your fs file. If a user would like to see the medium in the drive. Do a Runtime.exec and mount the drive, then you can grab the filesystem by wrapping it in the java.io.File object. ( NOTE - this will hold well for your NFS mounts as well which might be buried under other FS. So you now have detection for that as well. ) Labels are also noted in this file. Let me know if you don't know the difference between mtab and fstab....
Second - Winders.... Corney but I love saying that.
The listRoots is a good solution. As others have said CD-ROMS will not be writable. Use a combination of getName and getPath to decipher the label and mount point.
Hope this helps! -
Multi-lingual javascript support
Hi all,
I am facing a problem trying to make my site multi-lingual. I have made necessary changes in my database to handle multi-lingual data, but the problem is how do i check the data entered by the user in any language other than english at the client side itself.
Has anyone worked on this or does anyone has material regarding how to support multi-lingual javascript validations.
thanks in advance
AbhiWrong forum and cross posted as well.....
http://forum.java.sun.com/thread.jsp?thread=549121&forum=45&message=2678057 -
Multi-Lingual Forte Applications
We have at least one application site that needs to have their applications in
multiple languages. If any of you out there have experience in doing this and
can offer tips/techniques it is appreciated.
Also, have any of you evaluated Lindhard Forte Solutions product called
Ambassador Translation Wizard or know
of any other products?
Thanks in advance,
Peggy Adrian
Global Forte Support
Eli Lilly and Company
[email protected]Hello Peggy Lynn & Joseph,
My name is Kerry Bellerose. I work for Lindhard Forte Solutions
and I saw your note in the Forte User's list concerning multi-lingual
applications.
I just wanted to send out a quick note to let you know that we would
be happy to answer any questions you have about the Ambassador
Translation Wizard.
Did you know that you can download a free demo version that you can
use to quickly evaluate the product yourself? All you need is a PC
running Windows 95 or Windows NT and Forte release 2 or release 3.
Just go to our web page at:
http://www.lindhard.com/forte/ambassador.html
Then select the Download a Free Demo Version image. The demo version
is very simple to install (it comes packaged in a self-extracting
installation program that are common in windows).
The demo version itself is a Forte application, not an animated
presentation, which means you can actually use the program directly
to get a complete understand of how it works.
The only restriction is that the demo version will only translate
the demo project we provide. Otherwise, it has all the functionality
of the full release.
As far as we know, there are no other products available on the
market that automate the process of adding multi-lingual support
to an application. The only alternative is to hand-code your
own solution. As Joseph points out, this is a lot of work,
including at least hundreds of GetMsg statements.
But multi-lingual support requires more than just writing GetMsg
statements, and Ambassador does much more than just automatically
generate this code for you. Ambassador also maintains this code
as you modify your application. Ambassador generates the message
catalog for you. Ambassador minimizes the amount of translation
work you need to do by reducing the number duplicate strings in
your message catalogs. Ambassador also provides a Translation
Editor to make the translation work itself easier. And Ambassador
supports all the languages that Forte supports, both European and
Asian.
All in all, compared with manually supporting multi-lingual
applications in Forte, Ambassador can potentially save your
project months of developer time. That is why there are already
several Forte customers who have choosen Ambassador, and others
that have approved it for use in appropriate projects.
Please let us know if we can help out in any way.
Cheers,
Kerry
PS. If for any reason you are unable to access our web page,
please let us know, we'll be happy to send you a copy
of the demo version on CD ROM.
| | / \ Kerry Bellerose e-mail: [email protected]
| || C | FORTE' SOLUTIONS http://www.lindhard.com/
| | \___/ Lindhard Computer Systems direct: +45 45 94 01 03
| |_____ Datavej 52 desk: +45 45 82 21 21
| | 3460 Birkeroed fax: +45 45 82 21 22
|_________| Denmark -
Multi-lingual Software & Database Design
I am interested in how the industry is approaching multi-lingual software and database design. Specifically, I would like to know if there are any good resources (whitepapers, web sites, books) that get into the details of what the object model and data model of a multi-lingual design would look like and how the two fit together. I am working on a project that requires Product information to be stored in both English and French. Thank you.
http://java.sun.com/j2se/1.3/docs/guide/intl/
-
Possible to Get Database backup with java program
Hello
Is it possible to Get or Create Database Backup on runtime with java program using some sql statements
How could i do that
'Cross posted and multi-posted.
Hey jackass why don't you look where I already answered this question.
http://forum.java.sun.com/thread.jspa?threadID=654902&messageID=3849575 -
How to insert multi-lingual information into an NVARCHAR column
Hi,
I've searched through the forum but couldn't find an answer, and have spent days on this already.
I have a Java Web Application, and the user may enter information in any language into one of the forms. I need to collect the user-input, and insert it into an Oracle 10g database.
My database settings:
WE8ISO8859P1 for Char/VarChar/CLOB fields and
AL16UTF16 for Nchar/Nvarchar/NCLOB fields
I have defined the columns that require multi-lingual support to be NVARCHAR.
My question is, how do I insert into this column? From what I read, it seems that no conversion needs to be done, but doing this:
update <table> set <column> = '什么'
does not work. The '什么' is some Chinese characters I copied and pasted from a Chinese site.
Apparently, if I convert the Chinese characters to a hex string and do this:
update <table> set <column> = unistr('\xxxx')
then it will work.
However, is there a way to avoid doing this conversion and let Oracle handles the conversion?
Thanks in advance,
ElaineHi Denes,
I saw the example in your workspace and it is the same what exactly i want and instead of storing in one column i want to store the two selected values into two different columns. Also i need to restrict the selection of checkboxes upto 2 only. So If the user tries to select the third check box it doesnt have to accept.
Even I am ready to change my table as according to your example i.e. creating only one column. Store the values of selection into that column.
I was unable to see how u wrote the logic (Code) for your example in your workspace. It helps alot if you provide me the code for that example(Multi Checkbox One Column).
I was facinated after watching your examples in your workspace and am very much interested to know more about Apex.
Please help me insolving this as it is long pending issue for my requirement.
Thanks a lot again,
Sekhar.
Edited by: Sekhar Nooney on Mar 26, 2009 4:35 AM -
Error while running a Java Program
Can anyone help me,
I am getting the following error while running a Java program, Below is the exception thrown, please help.
java.nio.BufferOverflowException
at java.nio.Buffer.nextPutIndex(Buffer.java:425)
at java.nio.DirectByteBuffer.putChar(DirectByteBuffer.java:463)
at org.jetel.data.StringDataField.serialize(StringDataField.java:295)
at org.jetel.data.DataRecord.serialize(DataRecord.java:283)
at org.jetel.graph.DirectEdge.writeRecord(DirectEdge.java:216)
at org.jetel.graph.Edge.writeRecord(Edge.java:288)
at com.tcs.re.component.RESummer1.run(RESummer1.java:505)
java.nio.BufferOverflowException
at java.nio.Buffer.nextPutIndex(Buffer.java:425)
at java.nio.DirectByteBuffer.putChar(DirectByteBuffer.java:463)
at org.jetel.data.StringDataField.serialize(StringDataField.java:295)
at org.jetel.data.DataRecord.serialize(DataRecord.java:283)
at org.jetel.graph.DirectEdge.writeRecord(DirectEdge.java:216)
at org.jetel.graph.Edge.writeRecord(Edge.java:288)
at com.tcs.re.component.RECollectCont.run(RECollectCont.java:304)Ok, let's see. Write the following class:
public class Grunt {
public static void main(String[] args) {
System.out.println("Hello Mars");
}Save it as "C:\Grunt.java", compile by typing:
javac c:\Grunt.javaRun by typing:
java -classpath "C:\" GruntDoes it say "Hello Mars"? If yes, go back to your program and compare for differences (maybe you used the "package" statement?).
Regards -
Running a java program a set number of times
This is a general question. Is it possible to make a java program run only 5 times for the sake of arguement.
Basically I want to write a program that will give the user some flexibility when it will actually run another Java program, but I only want them to be able to say "not now' for a set number of times. When the last time comes the other program will launch. I was initially thinking of the Do Whilw loop, but this needs to work when the program is restarted.
Program starts, it has 5 times it will run before it does something else(doesn't really matter now I think). User takes option "Not Now" and the program ends, but warns the user this will run 4 more times before you will need to do something.
This process will repeat until the user takes the option "Ok install now" or the time limit expires and the install occurs anyway. Can someone point me in the right direction.ok I see so it's like one those programs that you download for free on the internet and they give you a set amount times to use it before you have to pay for it. but in this case when the number of times you use it equals 5 (or when the user clicks ok) a different java app will open automatically.
My first thought would be to Write a Serialized object to disk using objectOutputStream that stores the number of times the application has been opened. and each time the program runs it checks for the serialized object and then you can do something like what I posted before. of course if were worried about security the user could always look for the object and erase it, if so then I guess we would have to come up with another plan of attack
Hope this helps -
This shows how dumb i am.
I have a java program all wrote. How can i run it without using the compiler? Can i have a .exe file or something that I just have to click on to run??
Thanks again
AgdudeMicrosoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\awaguespack>cd jbproject\untitled1\classes\untitled1
C:\Documents and Settings\awaguespack\jbproject\untitled1\classes\untitled1>java
form
Exception in thread "main" java.lang.NoClassDefFoundError: form (wrong name: unt
itled1/form)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
C:\Documents and Settings\awaguespack\jbproject\untitled1\classes\untitled1>dir
Volume in drive C has no label.
Volume Serial Number is C065-81CA
Directory of C:\Documents and Settings\awaguespack\jbproject\untitled1\classes\
untitled1
07/24/2003 02:21 PM <DIR> .
07/24/2003 02:21 PM <DIR> ..
07/24/2003 02:21 PM 7,655 form.class
1 File(s) 7,655 bytes
2 Dir(s) 36,031,016,960 bytes free
C:\Documents and Settings\awaguespack\jbproject\untitled1\classes\untitled1>echo
%classpath%
%classpath%
C:\Documents and Settings\awaguespack\jbproject\untitled1\classes\untitled1>
Maybe you are looking for
-
i am trying to now install a free trial of indesign because despite paying $50+ a month for this supposed service I cannot open an indesign file I've been sent and need to do work on it urgently. I have now signed in again for a free one month trial
-
How to consider internal transfer movement for material aging Z report
Hello Expert , we are developing Z repot for material ageing . In this we are using BSIM table but in our case internal transfer movement such as ( 411 ,412 ,413 ,etc.) create debit credit entry in BSIM for this reason value of material gettin
-
IMic / Final Vinyl killed my sound!
Brand new iMac with OS X Tiger. I installed iMic yesterday, and hooked up a cassette deck. When first running Final Vinyl (1.1.2) I heard the sound OK in 'preview.' Then, no sound. Re-start, and the sound works, but is up one octave (like the Chipmun
-
Naming of my SOA Composite Application ? (EBF, ABCS...)
Hi all I have created a SOA composite application that uses a dbAdapter to poll data from a database and that processes these data in a BPEL process. The BPEL process transforms the data, then calls other dbAdapters to perform business tasks. I'd lik
-
Delay iTunes music sound.
Hi there! I have a standard 3.5mm 2.1 speakers plugged into my iMac's audio output port in one room. In another room I have both an AppleTV as well as an AirPort Express connected to a Sony sound-bar (HT-CT150). The AppleTV goes via HDMI while the