Author: nextgens
Date: 2007-04-22 13:56:19 +0000 (Sun, 22 Apr 2007)
New Revision: 12862
Modified:
trunk/freenet/src/freenet/l10n/L10n.java
Log:
Synchronize the L10n class ... not tested
Modified: trunk/freenet/src/freenet/l10n/L10n.java
===================================================================
--- trunk/freenet/src/freenet/l10n/L10n.java 2007-04-22 13:34:49 UTC (rev
12861)
+++ trunk/freenet/src/freenet/l10n/L10n.java 2007-04-22 13:56:19 UTC (rev
12862)
@@ -68,15 +68,19 @@
* @param selectedLanguage (2 letter code)
* @throws MissingResourceException
*/
- public synchronized static void setLanguage(String selectedLanguage)
throws MissingResourceException {
+ public static void setLanguage(String selectedLanguage) throws
MissingResourceException {
for(int i=0; i<AVAILABLE_LANGUAGES.length; i++){
if(selectedLanguage.equalsIgnoreCase(AVAILABLE_LANGUAGES[i])){
- selectedLanguage = AVAILABLE_LANGUAGES[i];
- Logger.normal(CLASS_NAME, "Changing the current
language to : " + selectedLanguage);
- currentClass = new L10n(selectedLanguage);
- if(currentTranslation == null) {
- currentClass = new
L10n(AVAILABLE_LANGUAGES[0]);
- throw new
MissingResourceException("Unable to load the translation file for
"+selectedLanguage, "l10n", selectedLanguage);
+ synchronized (currentClass) {
+ selectedLanguage =
AVAILABLE_LANGUAGES[i];
+ Logger.normal(CLASS_NAME, "Changing the
current language to : " + selectedLanguage);
+
+ currentClass = new
L10n(selectedLanguage);
+
+ if(currentTranslation == null) {
+ currentClass = new
L10n(AVAILABLE_LANGUAGES[0]);
+ throw new
MissingResourceException("Unable to load the translation file for
"+selectedLanguage, "l10n", selectedLanguage);
+ }
}
return;
}
@@ -107,15 +111,18 @@
_saveTranslationFile();
}
- private synchronized static void _saveTranslationFile() {
+ private static void _saveTranslationFile() {
FileOutputStream fos = null;
BufferedOutputStream bos = null;
try {
fos = new FileOutputStream(new File(L10n.PREFIX +
L10n.getSelectedLanguage() + L10n.OVERRIDE_SUFFIX));
- bos = new BufferedOutputStream(fos);
+ bos = new BufferedOutputStream(fos);
-
bos.write(L10n.translationOverride.toOrderedString().getBytes("UTF-8"));
+ synchronized (translationOverride) {
+
bos.write(L10n.translationOverride.toOrderedString().getBytes("UTF-8"));
+ }
+
Logger.normal("L10n", "Override file saved
successfully!");
} catch (IOException e) {
Logger.error("L10n", "Error while saving the
translation override: "+ e.getMessage(), e);
@@ -133,7 +140,9 @@
* @return SimpleFieldSet or null
*/
public static SimpleFieldSet getCurrentLanguageTranslation() {
- return (currentTranslation == null ? null : new
SimpleFieldSet(currentTranslation));
+ synchronized (currentTranslation) {
+ return (currentTranslation == null ? null : new
SimpleFieldSet(currentTranslation));
+ }
}
/**
@@ -142,7 +151,9 @@
* @return SimpleFieldSet or null
*/
public static SimpleFieldSet getOverrideForCurrentLanguageTranslation()
{
- return (translationOverride == null ? null : new
SimpleFieldSet(translationOverride));
+ synchronized (translationOverride) {
+ return (translationOverride == null ? null : new
SimpleFieldSet(translationOverride));
+ }
}
/**
@@ -163,10 +174,15 @@
* @see getString(String)
*/
public static String getString(String key, boolean
returnNullIfNotFound) {
- String result = (translationOverride == null ? null :
translationOverride.get(key));
+ String result = null;
+ synchronized (translationOverride) {
+ result = translationOverride.get(key);
+ }
if(result != null) return result;
-
- result = currentTranslation.get(key);
+
+ synchronized (currentTranslation) {
+ result = currentTranslation.get(key);
+ }
if(result != null)
return result;
else
@@ -200,11 +216,13 @@
public static String getDefaultString(String key) {
String result = null;
// We instanciate it only if necessary
- if(fallbackTranslation == null)
- fallbackTranslation =
loadTranslation(AVAILABLE_LANGUAGES[0]);
+ synchronized (fallbackTranslation) {
+ if(fallbackTranslation == null)
+ fallbackTranslation =
loadTranslation(AVAILABLE_LANGUAGES[0]);
+
+ result = fallbackTranslation.get(key);
+ }
- result = fallbackTranslation.get(key);
-
if(result != null) {
Logger.normal(CLASS_NAME, "The translation for " + key
+ " hasn't been found! please tell the maintainer.");
return result;
@@ -257,7 +275,9 @@
* @return String
*/
public static String getSelectedLanguage() {
- return currentClass.selectedLanguage;
+ synchronized (currentClass) {
+ return currentClass.selectedLanguage;
+ }
}
/**