dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #01299
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 374: Simplified the static i18n service
------------------------------------------------------------
revno: 374
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Mon 2009-06-15 12:06:24 +0200
message:
Simplified the static i18n service
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/i18n/I18n.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/i18n/locale/LocaleManager.java
dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/WeeklyPeriodTypeTest.java
dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java
dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/locale/SessionLocaleManager.java
dhis-2/dhis-i18n/dhis-i18n-static/src/main/java/org/hisp/dhis/i18n/DefaultI18nManager.java
dhis-2/dhis-i18n/dhis-i18n-static/src/main/java/org/hisp/dhis/i18n/locale/UserSettingLocaleManager.java
dhis-2/dhis-i18n/dhis-i18n-static/src/main/java/org/hisp/dhis/i18n/resourcebundle/DefaultResourceBundleManager.java
dhis-2/dhis-i18n/dhis-i18n-static/src/main/java/org/hisp/dhis/i18n/resourcebundle/ResourceBundleManager.java
dhis-2/dhis-i18n/dhis-i18n-upgrader/src/main/java/org/hisp/dhis/i18n/I18nUpgrader.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/workbook/impl/JExcelWorkbookService.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/i18n/action/I18nAction.java
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/i18n/I18n.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/i18n/I18n.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/i18n/I18n.java 2009-06-15 10:06:24 +0000
@@ -91,44 +91,4 @@
return translation;
}
-
- /**
- * Get a translated String for a given key, with variables, for the currently
- * selected locale
- *
- * @param key the key for a given translation
- * @param variables One or more variables due to be inserted into the
- * translation. May be null.
- * @return a translated String for a given key, or the key if no translation
- * is found
- */
- public String getString( String key, Object ... variables )
- {
- String translation = getString( key );
-
- if ( translation != null && variables != null )
- {
- if ( variables.length > 0 )
- {
- /*
- * Reverse replacement to make sure we replace %10 before %1, so
- * that there's no need for spaces/end-delimiter around the variable
- * replacement positions
- */
- for ( int i = variables.length - 1; i >= 0; i-- )
- {
- if ( variables[i] != null )
- {
- translation = translation.replace( "%" + ( i + 1 ), variables[i].toString() );
- }
- else
- {
- translation = translation.replace( "%" + ( i + 1 ), "<null>" );
- }
- }
- }
- }
-
- return translation;
- }
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/i18n/locale/LocaleManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/i18n/locale/LocaleManager.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/i18n/locale/LocaleManager.java 2009-06-15 10:06:24 +0000
@@ -40,11 +40,11 @@
Locale DHIS_STANDARD_LOCALE = Locale.UK;
- Locale getCurrentLocale() throws LocaleManagerException;
-
- void setCurrentLocale( Locale locale ) throws LocaleManagerException;
-
- List<Locale> getLocalesOrderedByPriority() throws LocaleManagerException;
+ Locale getCurrentLocale();
+
+ void setCurrentLocale( Locale locale );
+
+ List<Locale> getLocalesOrderedByPriority();
Locale getFallbackLocale();
}
=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/WeeklyPeriodTypeTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/WeeklyPeriodTypeTest.java 2009-06-12 16:00:35 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/WeeklyPeriodTypeTest.java 2009-06-15 10:06:24 +0000
@@ -27,12 +27,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import java.util.Calendar;
import java.util.List;
-import org.junit.Ignore;
import org.junit.Test;
/**
=== modified file 'dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java'
--- dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java 2009-06-15 10:06:24 +0000
@@ -39,7 +39,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.i18n.locale.LocaleManager;
-import org.hisp.dhis.i18n.locale.LocaleManagerException;
/**
* @author Oyvind Brucker
@@ -137,15 +136,8 @@
Locale locale = null;
- try
- {
- locale = localeManager.getCurrentLocale();
- }
- catch ( LocaleManagerException e )
- {
-
- }
-
+ locale = localeManager.getCurrentLocale();
+
if ( locale == null )
{
log.error( "Unable to get current locale" );
@@ -158,17 +150,7 @@
public void internationaliseCollection( Collection<?> intObjects )
{
- Locale locale = null;
-
- try
- {
- locale = localeManager.getCurrentLocale();
- }
- catch ( LocaleManagerException e )
- {
- log.error( "Unable to get current locale: " + e );
- return;
- }
+ Locale locale = localeManager.getCurrentLocale();
if ( locale == null || intObjects == null )
{
@@ -327,18 +309,7 @@
return;
}
- Locale locale = null;
-
- try
- {
-
- locale = localeManager.getCurrentLocale();
- }
- catch ( LocaleManagerException e )
- {
- log.error( "Unable to get current locale: " + e );
- return;
- }
+ Locale locale = localeManager.getCurrentLocale();
/**
* Save translations
@@ -393,16 +364,7 @@
return;
}
- Locale locale = null;
-
- try
- {
- locale = localeManager.getCurrentLocale();
- }
- catch ( LocaleManagerException e )
- {
- // Handled in the next block
- }
+ Locale locale = localeManager.getCurrentLocale();
if ( locale == null )
{
@@ -475,16 +437,7 @@
public Collection<Locale> getAvailableLocales()
{
- List<Locale> locales;
-
- try
- {
- locales = localeManager.getLocalesOrderedByPriority();
- }
- catch ( LocaleManagerException e )
- {
- locales = new ArrayList<Locale>();
- }
+ List<Locale> locales = localeManager.getLocalesOrderedByPriority();
Collection<Locale> translationLocales = translationService.getAvailableLocales();
=== modified file 'dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/locale/SessionLocaleManager.java'
--- dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/locale/SessionLocaleManager.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-i18n/dhis-i18n-db/src/main/java/org/hisp/dhis/i18n/locale/SessionLocaleManager.java 2009-06-15 10:06:24 +0000
@@ -49,7 +49,6 @@
}
public Locale getCurrentLocale()
- throws LocaleManagerException
{
if ( locale == null )
{
@@ -60,13 +59,11 @@
}
public void setCurrentLocale( Locale locale )
- throws LocaleManagerException
{
this.locale = locale;
}
public List<Locale> getLocalesOrderedByPriority()
- throws LocaleManagerException
{
List<Locale> locales = new ArrayList<Locale>();
=== modified file 'dhis-2/dhis-i18n/dhis-i18n-static/src/main/java/org/hisp/dhis/i18n/DefaultI18nManager.java'
--- dhis-2/dhis-i18n/dhis-i18n-static/src/main/java/org/hisp/dhis/i18n/DefaultI18nManager.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-i18n/dhis-i18n-static/src/main/java/org/hisp/dhis/i18n/DefaultI18nManager.java 2009-06-15 10:06:24 +0000
@@ -31,7 +31,6 @@
import java.util.ResourceBundle;
import org.hisp.dhis.i18n.locale.LocaleManager;
-import org.hisp.dhis.i18n.locale.LocaleManagerException;
import org.hisp.dhis.i18n.resourcebundle.ResourceBundleManager;
import org.hisp.dhis.i18n.resourcebundle.ResourceBundleManagerException;
@@ -99,28 +98,12 @@
}
private ResourceBundle getSpecificResourceBundle( Class<?> clazz )
- throws I18nManagerException
{
- try
- {
- return resourceBundleManager.getSpecificResourceBundle( clazz, getCurrentLocale() );
- }
- catch ( ResourceBundleManagerException e )
- {
- throw new I18nManagerException( "Failed to get specific resource bundle", e );
- }
+ return resourceBundleManager.getSpecificResourceBundle( clazz, getCurrentLocale() );
}
private Locale getCurrentLocale()
- throws I18nManagerException
{
- try
- {
- return localeManager.getCurrentLocale();
- }
- catch ( LocaleManagerException e )
- {
- throw new I18nManagerException( "Failed to get current locale", e );
- }
+ return localeManager.getCurrentLocale();
}
}
=== modified file 'dhis-2/dhis-i18n/dhis-i18n-static/src/main/java/org/hisp/dhis/i18n/locale/UserSettingLocaleManager.java'
--- dhis-2/dhis-i18n/dhis-i18n-static/src/main/java/org/hisp/dhis/i18n/locale/UserSettingLocaleManager.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-i18n/dhis-i18n-static/src/main/java/org/hisp/dhis/i18n/locale/UserSettingLocaleManager.java 2009-06-15 10:06:24 +0000
@@ -71,7 +71,6 @@
// -------------------------------------------------------------------------
public Locale getCurrentLocale()
- throws LocaleManagerException
{
Locale locale = getUserSelectedLocale();
@@ -89,7 +88,6 @@
}
public void setCurrentLocale( Locale locale )
- throws LocaleManagerException
{
try
{
@@ -102,7 +100,6 @@
}
public List<Locale> getLocalesOrderedByPriority()
- throws LocaleManagerException
{
List<Locale> locales = new ArrayList<Locale>();
=== modified file 'dhis-2/dhis-i18n/dhis-i18n-static/src/main/java/org/hisp/dhis/i18n/resourcebundle/DefaultResourceBundleManager.java'
--- dhis-2/dhis-i18n/dhis-i18n-static/src/main/java/org/hisp/dhis/i18n/resourcebundle/DefaultResourceBundleManager.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-i18n/dhis-i18n-static/src/main/java/org/hisp/dhis/i18n/resourcebundle/DefaultResourceBundleManager.java 2009-06-15 10:06:24 +0000
@@ -81,7 +81,6 @@
// -------------------------------------------------------------------------
public ResourceBundle getSpecificResourceBundle( Class<?> clazz, Locale locale )
- throws ResourceBundleManagerException
{
String path = PathUtils.getClassPath( clazz.getName() );
=== modified file 'dhis-2/dhis-i18n/dhis-i18n-static/src/main/java/org/hisp/dhis/i18n/resourcebundle/ResourceBundleManager.java'
--- dhis-2/dhis-i18n/dhis-i18n-static/src/main/java/org/hisp/dhis/i18n/resourcebundle/ResourceBundleManager.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-i18n/dhis-i18n-static/src/main/java/org/hisp/dhis/i18n/resourcebundle/ResourceBundleManager.java 2009-06-15 10:06:24 +0000
@@ -40,7 +40,7 @@
{
String ID = ResourceBundleManager.class.getName();
- ResourceBundle getSpecificResourceBundle( Class<?> clazz, Locale locale ) throws ResourceBundleManagerException;
+ ResourceBundle getSpecificResourceBundle( Class<?> clazz, Locale locale );
ResourceBundle getGlobalResourceBundle( Locale locale ) throws ResourceBundleManagerException;
=== modified file 'dhis-2/dhis-i18n/dhis-i18n-upgrader/src/main/java/org/hisp/dhis/i18n/I18nUpgrader.java'
--- dhis-2/dhis-i18n/dhis-i18n-upgrader/src/main/java/org/hisp/dhis/i18n/I18nUpgrader.java 2009-06-10 22:25:07 +0000
+++ dhis-2/dhis-i18n/dhis-i18n-upgrader/src/main/java/org/hisp/dhis/i18n/I18nUpgrader.java 2009-06-15 10:06:24 +0000
@@ -46,7 +46,6 @@
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.DataSetStore;
import org.hisp.dhis.i18n.locale.LocaleManager;
-import org.hisp.dhis.i18n.locale.LocaleManagerException;
import org.hisp.dhis.i18n.util.LocaleUtils;
import org.hisp.dhis.indicator.Indicator;
import org.hisp.dhis.indicator.IndicatorGroup;
@@ -189,29 +188,20 @@
if ( translations == null || translations.isEmpty() )
{
- Locale orgLocale = null;
-
- try
- {
- orgLocale = localeManager.getCurrentLocale();
-
- localeManager.setCurrentLocale( localeManager.getFallbackLocale() );
-
- String alternativeNameDescription = "";
-
- if ( alternativeNameLocale != null )
- {
- alternativeNameDescription = " and " + alternativeNameLocale.getDisplayName()
- + " for alternative names";
- }
-
- log.info( "I18n Upgrader running using locale " + localeManager.getFallbackLocale().getDisplayName()
- + alternativeNameDescription );
- }
- catch ( LocaleManagerException e )
- {
- orgLocale = localeManager.getFallbackLocale();
- }
+ Locale orgLocale = localeManager.getCurrentLocale();
+
+ localeManager.setCurrentLocale( localeManager.getFallbackLocale() );
+
+ String alternativeNameDescription = "";
+
+ if ( alternativeNameLocale != null )
+ {
+ alternativeNameDescription = " and " + alternativeNameLocale.getDisplayName()
+ + " for alternative names";
+ }
+
+ log.info( "I18n Upgrader running using locale " + localeManager.getFallbackLocale().getDisplayName()
+ + alternativeNameDescription );
// ---------------------------------------------------------------------
// DataElement
@@ -387,13 +377,7 @@
}
}
- try
- {
- localeManager.setCurrentLocale( orgLocale );
- }
- catch ( LocaleManagerException e )
- {
- }
+ localeManager.setCurrentLocale( orgLocale );
// ---------------------------------------------------------------------
// DataElementCategory
@@ -411,13 +395,7 @@
}
}
- try
- {
- localeManager.setCurrentLocale( orgLocale );
- }
- catch ( LocaleManagerException e )
- {
- }
+ localeManager.setCurrentLocale( orgLocale );
// ---------------------------------------------------------------------
// DataElementCategoryOption
@@ -435,13 +413,7 @@
}
}
- try
- {
- localeManager.setCurrentLocale( orgLocale );
- }
- catch ( LocaleManagerException e )
- {
- }
+ localeManager.setCurrentLocale( orgLocale );
// ---------------------------------------------------------------------
// DataElementCategoryCombo
@@ -459,13 +431,7 @@
}
}
- try
- {
- localeManager.setCurrentLocale( orgLocale );
- }
- catch ( LocaleManagerException e )
- {
- }
+ localeManager.setCurrentLocale( orgLocale );
}
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/workbook/impl/JExcelWorkbookService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/workbook/impl/JExcelWorkbookService.java 2009-06-10 22:25:07 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/workbook/impl/JExcelWorkbookService.java 2009-06-15 10:06:24 +0000
@@ -422,7 +422,7 @@
sheet.addCell( new Label( MARGIN_LEFT + 1, row, format.formatPeriod( period ), text ) );
sheet.addCell( new Label( MARGIN_LEFT + 2, row, result.getValidationRule().getLeftSide().getDescription(), text ) );
sheet.addCell( new Number( MARGIN_LEFT + 3, row, result.getLeftsideValue(), text ) );
- sheet.addCell( new Label( MARGIN_LEFT + 4, row, i18n.getString( result.getValidationRule().getOperator(), text ) ) );
+ sheet.addCell( new Label( MARGIN_LEFT + 4, row, result.getValidationRule().getOperator(), text ) );
sheet.addCell( new Number( MARGIN_LEFT + 5, row, result.getRightsideValue(), text ) );
sheet.addCell( new Label( MARGIN_LEFT + 6, row, result.getValidationRule().getRightSide().getDescription(), text ) );
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/i18n/action/I18nAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/i18n/action/I18nAction.java 2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/i18n/action/I18nAction.java 2009-06-15 10:06:24 +0000
@@ -35,7 +35,6 @@
import org.hisp.dhis.i18n.I18nService;
import org.hisp.dhis.i18n.locale.LocaleManager;
-import org.hisp.dhis.i18n.locale.LocaleManagerException;
import com.opensymphony.xwork.Action;
@@ -142,14 +141,7 @@
public Locale getCurrentLocale()
{
- try
- {
- return localeManager.getCurrentLocale();
- }
- catch ( LocaleManagerException e )
- {
- return localeManager.getFallbackLocale();
- }
+ return localeManager.getCurrentLocale();
}
public Locale getCurrentRefLocale()
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription.