dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #15721
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5771: I18n db, WIP
Merge authors:
Lars Helge Øverland (larshelge)
------------------------------------------------------------
revno: 5771 [merge]
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-01-22 05:38:30 +0100
message:
I18n db, WIP
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/translation/TranslationService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/translation/TranslationStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/translation/DefaultTranslationService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/translation/hibernate/HibernateTranslationStore.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/translation/TranslationServiceTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/translation/TranslationStoreTest.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/AbstractPreResultListener.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/ContextInterceptor.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/ExceptionInterceptor.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/I18nInterceptor.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/SystemSettingInterceptor.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/user/SetGeneralSettingsAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/userGeneralSettings.vm
--
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
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/translation/TranslationService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/translation/TranslationService.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/translation/TranslationService.java 2012-01-22 04:37:14 +0000
@@ -64,19 +64,6 @@
Translation getTranslation( String className, int id, Locale locale, String property );
/**
- * Retrieved Collection of Translations
- *
- * @param className className is the string of object's class name
- * @param locale locale of translation object
- * @param property property of the translation object
- * @param nonId nonId is not the identify of translation object
- *
- * @return a collection of translation objects
- *
- */
- Translation getTranslation( String className, Locale locale, String property, String value, int nonId );
-
- /**
* Retrieves a Collection of Translations.
*
* @param className the class name.
@@ -116,12 +103,4 @@
* @param id the id.
*/
void deleteTranslations( String className, int id );
-
- /**
- * Retrieves all available Locales.
- *
- * @return a Collection of all available Locales.
- */
- Collection<Locale> getAvailableLocales();
-
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/translation/TranslationStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/translation/TranslationStore.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/translation/TranslationStore.java 2012-01-22 04:37:14 +0000
@@ -63,19 +63,6 @@
Translation getTranslation( String className, int id, Locale locale, String property );
/**
- * Retrieved Collection of Translations
- *
- * @param className className is the string of object's class name
- * @param locale locale of translation object
- * @param property property of the translation object
- * @param nonId nonId is not the identify of translation object
- *
- * @return a collection of translation objects
- *
- */
- Translation getTranslation( String className, Locale locale, String property, String value, int nonId );
-
- /**
* Retrieves a Collection of Translations.
*
* @param className the class name.
@@ -115,12 +102,4 @@
* @param id the id.
*/
void deleteTranslations( String className, int id );
-
- /**
- * Retrieves all available Locales.
- *
- * @return a Collection of all available Locales.
- */
- Collection<Locale> getAvailableLocales();
-
}
\ No newline at end of file
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java 2012-01-20 10:00:50 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java 2012-01-22 04:37:14 +0000
@@ -27,7 +27,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.i18n.locale.LocaleManager.DHIS_STANDARD_LOCALE;
import static org.hisp.dhis.system.util.ReflectionUtils.getClassName;
import static org.hisp.dhis.system.util.ReflectionUtils.getId;
import static org.hisp.dhis.system.util.ReflectionUtils.getProperty;
@@ -106,10 +105,10 @@
private void internationaliseObject( Object object, Locale locale )
{
- if ( object == null || DHIS_STANDARD_LOCALE.equals( locale ) )
+ if ( locale == null || object == null )
{
return;
- }
+ }
List<String> properties = getObjectPropertyNames( object );
@@ -131,10 +130,10 @@
private void internationaliseCollection( Collection<?> objects, Locale locale )
{
- if ( objects == null || objects.size() == 0 || DHIS_STANDARD_LOCALE.equals( locale ) )
+ if ( locale == null || objects == null || objects.size() == 0 )
{
return;
- }
+ }
Object peek = objects.iterator().next();
@@ -200,36 +199,44 @@
public void updateTranslation( String className, int id, Locale locale, Map<String, String> translations )
{
- for ( Map.Entry<String, String> translationEntry : translations.entrySet() )
+ if ( locale != null && className != null )
{
- String key = translationEntry.getKey();
- String value = translationEntry.getValue();
-
- Translation translation = translationService.getTranslation( className, id, locale, key );
-
- if ( value != null && !value.trim().isEmpty() )
- {
- if ( translation != null )
- {
- translation.setValue( value );
- translationService.updateTranslation( translation );
- }
- else
- {
- translation = new Translation( className, id, locale.toString(), key, value );
- translationService.addTranslation( translation );
- }
- }
- else if ( translation != null )
- {
- translationService.deleteTranslation( translation );
+ for ( Map.Entry<String, String> translationEntry : translations.entrySet() )
+ {
+ String key = translationEntry.getKey();
+ String value = translationEntry.getValue();
+
+ Translation translation = translationService.getTranslation( className, id, locale, key );
+
+ if ( value != null && !value.trim().isEmpty() )
+ {
+ if ( translation != null )
+ {
+ translation.setValue( value );
+ translationService.updateTranslation( translation );
+ }
+ else
+ {
+ translation = new Translation( className, id, locale.toString(), key, value );
+ translationService.addTranslation( translation );
+ }
+ }
+ else if ( translation != null )
+ {
+ translationService.deleteTranslation( translation );
+ }
}
}
}
public Map<String, String> getTranslations( String className, int id, Locale locale )
{
- return convertTranslations( translationService.getTranslations( className, id, locale ) );
+ if ( locale != null && className != null )
+ {
+ return convertTranslations( translationService.getTranslations( className, id, locale ) );
+ }
+
+ return new HashMap<String, String>();
}
public List<Locale> getAvailableLocales()
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/translation/DefaultTranslationService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/translation/DefaultTranslationService.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/translation/DefaultTranslationService.java 2012-01-22 04:37:14 +0000
@@ -97,14 +97,4 @@
{
translationStore.deleteTranslations( className, id );
}
-
- public Collection<Locale> getAvailableLocales()
- {
- return translationStore.getAvailableLocales();
- }
-
- public Translation getTranslation( String className, Locale locale, String property, String value, int nonId )
- {
- return translationStore.getTranslation( className, locale, property, value, nonId );
- }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/translation/hibernate/HibernateTranslationStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/translation/hibernate/HibernateTranslationStore.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/translation/hibernate/HibernateTranslationStore.java 2012-01-22 04:37:14 +0000
@@ -27,7 +27,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
@@ -37,7 +36,6 @@
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
-import org.hisp.dhis.system.util.LocaleUtils;
import org.hisp.dhis.translation.Translation;
import org.hisp.dhis.translation.TranslationStore;
@@ -159,41 +157,4 @@
session.delete( object );
}
}
-
- @SuppressWarnings( "unchecked" )
- public Collection<Locale> getAvailableLocales()
- {
- Session session = sessionFactory.getCurrentSession();
-
- List<Object> objlist = session.createQuery( "select distinct translation.locale from Translation translation" )
- .list();
-
- Collection<Locale> locales = new ArrayList<Locale>();
-
- for ( Object object : objlist )
- {
- Locale locale = LocaleUtils.getLocale( object.toString() );
-
- locales.add( locale );
- }
-
- return locales;
- }
-
- public Translation getTranslation( String className, Locale locale, String property, String value, int nonId )
- {
- Session session = sessionFactory.getCurrentSession();
-
- Criteria criteria = session.createCriteria( Translation.class );
-
- criteria.add( Restrictions.eq( "className", className ) );
- criteria.add( Restrictions.eq( "locale", locale.toString() ) );
- criteria.add( Restrictions.eq( "property", property ) );
- criteria.add( Restrictions.ilike( "value", value.toLowerCase() ) );
- criteria.add( Restrictions.ne( "id", nonId ) );
-
- criteria.setCacheable( true );
-
- return (Translation) criteria.uniqueResult();
- }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/translation/TranslationServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/translation/TranslationServiceTest.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/translation/TranslationServiceTest.java 2012-01-22 04:37:14 +0000
@@ -32,7 +32,6 @@
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
-import java.util.Collection;
import java.util.Locale;
import org.hisp.dhis.DhisSpringTest;
@@ -165,19 +164,4 @@
assertEquals( 5, translationService.getAllTranslations().size() );
}
-
- @Test
- public void testGetAvailableLocales()
- throws Exception
- {
- translationService.addTranslation( translation1a );
- translationService.addTranslation( translation1b );
- translationService.addTranslation( translation2a );
- translationService.addTranslation( translation2b );
- translationService.addTranslation( translation2c );
-
- Collection<Locale> locales = translationService.getAvailableLocales();
-
- assertEquals( 3, locales.size() );
- }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/translation/TranslationStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/translation/TranslationStoreTest.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/translation/TranslationStoreTest.java 2012-01-22 04:37:14 +0000
@@ -32,7 +32,6 @@
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
-import java.util.Collection;
import java.util.Locale;
import org.hisp.dhis.DhisSpringTest;
@@ -167,19 +166,4 @@
assertEquals( 5, translationStore.getAllTranslations().size() );
}
-
- @Test
- public void testGetAvailableLocales()
- throws Exception
- {
- translationStore.addTranslation( translation1a );
- translationStore.addTranslation( translation1b );
- translationStore.addTranslation( translation2a );
- translationStore.addTranslation( translation2b );
- translationStore.addTranslation( translation2c );
-
- Collection<Locale> locales = translationStore.getAvailableLocales();
-
- assertEquals( 3, locales.size() );
- }
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/AbstractPreResultListener.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/AbstractPreResultListener.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/AbstractPreResultListener.java 2012-01-22 04:20:13 +0000
@@ -44,11 +44,6 @@
public abstract class AbstractPreResultListener
implements Interceptor, PreResultListener
{
- /**
- * Determines if a de-serialized file is compatible with this class.
- */
- private static final long serialVersionUID = -4459571006411990169L;
-
private static final Log LOG = LogFactory.getLog( AbstractPreResultListener.class );
private boolean executePreResultListener;
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/ContextInterceptor.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/ContextInterceptor.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/ContextInterceptor.java 2012-01-22 04:20:13 +0000
@@ -41,11 +41,6 @@
public class ContextInterceptor
implements Interceptor
{
- /**
- * Determines if a de-serialized file is compatible with this class.
- */
- private static final long serialVersionUID = 5247533061332275754L;
-
private static final String KEY_IN_MEMORY_DATABASE = "inMemoryDatabase";
private DatabaseInfoProvider databaseInfoProvider;
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/ExceptionInterceptor.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/ExceptionInterceptor.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/ExceptionInterceptor.java 2012-01-22 04:20:13 +0000
@@ -53,11 +53,6 @@
public class ExceptionInterceptor
implements Interceptor
{
- /**
- * Determines if a de-serialized file is compatible with this class.
- */
- private static final long serialVersionUID = 8500468340861599537L;
-
private static final Log LOG = LogFactory.getLog( ExceptionInterceptor.class );
public static final String EXCEPTION_RESULT_KEY = "onExceptionReturn";
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/I18nInterceptor.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/I18nInterceptor.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/I18nInterceptor.java 2012-01-22 04:20:13 +0000
@@ -50,11 +50,6 @@
public class I18nInterceptor
implements Interceptor
{
- /**
- * Determines if a de-serialized file is compatible with this class.
- */
- private static final long serialVersionUID = -1684761883368013838L;
-
private static final String KEY_I18N = "i18n";
private static final String KEY_I18N_FORMAT = "format";
private static final String KEY_LOCALE = "locale";
@@ -82,15 +77,11 @@
// -------------------------------------------------------------------------
public void destroy()
- {
- // TODO Auto-generated method stub
-
+ {
}
public void init()
{
- // TODO Auto-generated method stub
-
}
public String intercept( ActionInvocation invocation )
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/SystemSettingInterceptor.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/SystemSettingInterceptor.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/SystemSettingInterceptor.java 2012-01-22 04:20:13 +0000
@@ -52,11 +52,6 @@
public class SystemSettingInterceptor
implements Interceptor
{
- /**
- * Determines if a de-serialized file is compatible with this class.
- */
- private static final long serialVersionUID = 7410474100313067470L;
-
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/user/SetGeneralSettingsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/user/SetGeneralSettingsAction.java 2012-01-20 10:38:11 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/user/SetGeneralSettingsAction.java 2012-01-22 04:20:13 +0000
@@ -32,6 +32,7 @@
import java.util.Locale;
+import org.apache.commons.lang.StringUtils;
import org.hisp.dhis.i18n.locale.LocaleManager;
import org.hisp.dhis.options.style.StyleManager;
import org.hisp.dhis.user.UserSettingService;
@@ -125,7 +126,7 @@
{
localeManagerInterface.setCurrentLocale( getRespectiveLocale( currentLocale ) );
- localeManagerDB.setCurrentLocale( getRespectiveLocale( currentLocaleDb ) );
+ localeManagerDB.setCurrentLocale( getRespectiveLocale( StringUtils.trimToNull( currentLocaleDb ) ) );
styleManager.setUserStyle( currentStyle );
@@ -142,6 +143,11 @@
private Locale getRespectiveLocale( String locale )
{
+ if ( locale == null )
+ {
+ return null;
+ }
+
String[] tokens = locale.split( "_" );
Locale newLocale = null;
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties 2011-12-15 14:08:46 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties 2012-01-22 04:20:13 +0000
@@ -2,9 +2,7 @@
omit_indicators_zero_numerator_data_mart=Omit indicator values with zero numerator value in data mart
alternativename=Alternative name
db_language=Database Language
-display_property=Display Property
language=Interface Language
-sort_order_property=Sort Order Property
dashboard_charts_to_display=Dashboard Charts to Display
code=Code
system_settings=System settings
@@ -85,7 +83,7 @@
start_page=Start page
forum_integration=Forum integration
no_start_page=No start page
-intro_user_general_settings=Customize the system with user specific settings for locale, sort order, display property, style and more.
+intro_user_general_settings=Customize the system with user specific settings for locale, style and more.
intro_user_message_settings=Customize the system with user specific settings for message email and sms notification.
intro_system_general_settings=Customize the system behavior with regard to aggregation strategy, infrastructural data elements and more.
intro_system_appearance_settings=Customize the system behavior with regard to application title, style, flag, start page.
@@ -119,4 +117,5 @@
message_sms_notification=Message sms notification
completeness_email_notification=Completeness email notification
completeness_recipients=Completeness notification recipients
-no_completeness_recipients=No completeness recipients
\ No newline at end of file
+no_completeness_recipients=No completeness recipients
+use_db_locale_no_translation=Use database locale / no translation
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/userGeneralSettings.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/userGeneralSettings.vm 2011-12-09 10:19:39 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/userGeneralSettings.vm 2012-01-22 04:20:13 +0000
@@ -6,8 +6,6 @@
jQuery.postJSON( 'setUserGeneralSettings.action', {
currentLocale: getFieldValue( 'currentLocale' ),
currentLocaleDb: getFieldValue( 'currentLocaleDb' ),
- currentSortOrder: getFieldValue( 'currentSortOrder' ),
- currentDisplayProperty: getFieldValue( 'currentDisplayProperty' ),
currentStyle: getFieldValue( 'currentStyle' ),
chartsInDashboard: getFieldValue( 'chartsInDashboard' ),
autoSave: jQuery( '#autoSave' ).is(':checked' )
@@ -32,27 +30,12 @@
<h4>$i18n.getString( "db_language" )</h4>
<select id="currentLocaleDb" name="currentLocaleDb" style="min-width:250px">
+ <option value="">[$i18n.getString( "use_db_locale_no_translation" )]</option>
#foreach( $locale in $availableLocalesDb )
<option value="$locale.toString()" #if( $locale == $currentLocaleDb )selected="selected"#end>$locale.getDisplayName()</option>
#end
</select>
-<h4>$i18n.getString( "sort_order_property" )</h4>
-
-<select id="currentSortOrder" name="currentSortOrder" style="min-width:250px">
-#foreach( $sortOrder in $sortOrders )
- <option value="$sortOrder" #if( $sortOrder == $currentSortOrder )selected="selected"#end>$i18n.getString( $sortOrder )</option>
-#end
-</select>
-
-<h4>$i18n.getString( "display_property" )</h4>
-
-<select id="currentDisplayProperty" name="currentDisplayProperty" style="min-width:250px">
-#foreach( $property in $displayProperties )
- <option value="$property" #if( $property == $currentDisplayProperty )selected="selected"#end>$i18n.getString( $property )</option>
-#end
-</select>
-
<h4>$i18n.getString( "style" )</h4>
<select id="currentStyle" name="currentStyle" style="min-width:250px">