[opencms-dev] Solved: Problem with locale opencms changed JVM (Possible bug in OpenCms set locale JVM)
Deiverson Silveira
deiverson at solutioncms.com
Wed Oct 21 23:37:59 CEST 2009
Hi List,
About problem with JVM, I believe it is a bug in opencms, when he goes to
set a locale that has more than 2 parts (fr_CA, pt_BR), i have module pt_BR
ok, but code dont reading pt_BR and set locale JVM, i change class
CmsLocaleManager.java in package org.opencms.i18n:
/**
* Sets the default locale of the Java VM to <code>{@link
Locale#ENGLISH}</code> if the
* current default has any other language then English set.<p>
*
* This is required because otherwise the default (English) resource
bundles
* would not be displayed for the English locale if a translated default
locale exists.<p>
*
* Here's an example of how this issues shows up:
* On a German server, the default locale usually is <code>{@link
Locale#GERMAN}</code>.
* All English translations for OpenCms are located in the "default"
message files, for example
* <code>org.opencms.i18n.message.properties</code>. If the German
localization is installed, it will be
* located in <code>org.opencms.i18n.message_de.properties</code>. If
user has English selected
* as his locale, the default Java lookup mechanism first tries to find
* <code>org.opencms.i18n.message_en.properties</code>. However, this
file does not exist, since the
* English localization is kept in the default file. Next, the Java
lookup mechanism tries to find the servers
* default locale, which in this example is German. Since there is a
German message file, the Java lookup mechanism
* is finished and uses this German localization, not the default file.
Therefore the
* user get the German localization, not the English one.
* Setting the default locale explicitly to English avoids this
issue.<p>
*/
private static void setDefaultLocale() {
// set the default locale to english
// this is required because otherwise the default (english) resource
bundles
// would not be displayed for the english locale if a translated
locale exists
Locale oldLocale = Locale.getDefault();
if (!(Locale.ENGLISH.getLanguage().equals(oldLocale.getLanguage())))
{
// default language is not English
try {
Locale.setDefault(Locale.ENGLISH);
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(
Messages.INIT_I18N_DEFAULT_LOCALE_2,
Locale.ENGLISH,
oldLocale));
}
} catch (Exception e) {
// any Exception: the locale has not been changed, so there
may be issues with the English
// localization but OpenCms will run in general
CmsLog.INIT.error(Messages.get().getBundle().key(
Messages.LOG_UNABLE_TO_SET_DEFAULT_LOCALE_2,
Locale.ENGLISH,
oldLocale), e);
}
} else {
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_I18N_KEEPING_DEFAULT_LOCALE_1,
oldLocale));
}
}
// initialize the static member with the new default
m_defaultLocale = Locale.getDefault();
}
I change method for this and set JVM ok:
private static void setDefaultLocale() {
// set the default locale to english
// this is required because otherwise the default (english) resource
bundles
// would not be displayed for the english locale if a translated
locale exists
Locale oldLocale = Locale.getDefault();
Locale loc = new Locale("pt","BR");
try {
Locale.setDefault(loc);
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(
Messages.INIT_I18N_DEFAULT_LOCALE_2,
loc,
oldLocale));
}
} catch (Exception e) {
// any Exception: the locale has not been changed, so there
may be issues with the English
// localization but OpenCms will run in general
CmsLog.INIT.error(Messages.get().getBundle().key(
Messages.LOG_UNABLE_TO_SET_DEFAULT_LOCALE_2,
loc,
oldLocale), e);
}
// initialize the static member with the new default
m_defaultLocale = Locale.getDefault();
}
SUCESS! This Work others system/projects, opencms dont impact in jvm when
pt_BR... but the jvm will be forever by setting pt_BR! I Belive other people
must have the same problem when more project in server aplication!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20091021/f1dc35bc/attachment.htm>
More information about the opencms-dev
mailing list