← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12751: Translation minor bug fix - related to saving with existing defaulting.

 

------------------------------------------------------------
revno: 12751
committer: James Chang <jamesbchang@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-10-17 02:09:50 +0700
message:
  Translation minor bug fix - related to saving with existing defaulting.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/translation/Translation.java
  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


--
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/Translation.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/translation/Translation.java	2013-10-06 07:45:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/translation/Translation.java	2013-10-16 19:09:50 +0000
@@ -74,7 +74,7 @@
 
     public String getClassIdPropKey()
     {
-        return className + "-" + id + "-" + property;
+        return className + "-" + id + "-" + locale + "-" + property;
     }
     
     // -------------------------------------------------------------------------

=== 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	2013-10-10 08:26:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/translation/TranslationService.java	2013-10-16 19:09:50 +0000
@@ -65,6 +65,18 @@
     Translation getTranslation( String className, int id, Locale locale, String property );
 
     /**
+     * Retrieves a Translation. Only exact matches on the given
+     * Locale will be returned.
+     * 
+     * @param className the class name.
+     * @param id the id.
+     * @param locale the locale.
+     * @param property the property.
+     * @return a Translation.
+     */
+    Translation getTranslationNoFallback( String className, int id, Locale locale, String property );
+
+    /**
      * Retrieves a Collection of Translations.
      * 
      * @param className the class name.

=== 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	2013-10-10 08:26:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/translation/TranslationStore.java	2013-10-16 19:09:50 +0000
@@ -64,6 +64,18 @@
     Translation getTranslation( String className, int id, Locale locale, String property );
 
     /**
+     * Retrieves a Translation. Only exact matches on the given
+     * Locale will be returned.
+     * 
+     * @param className the class name.
+     * @param id the id.
+     * @param locale the locale.
+     * @param property the property.
+     * @return a Translation.
+     */
+    Translation getTranslationNoFallback( String className, int id, Locale locale, String property  );
+
+    /**
      * Retrieves a Collection of Translations.
      * 
      * @param className the class name.

=== 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	2013-10-16 17:46:06 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java	2013-10-16 19:09:50 +0000
@@ -217,8 +217,8 @@
             {
                 String key = translationEntry.getKey();
                 String value = translationEntry.getValue();
-
-                Translation translation = translationService.getTranslation( className, id, locale, key );
+                
+                Translation translation = translationService.getTranslationNoFallback( className, id, locale, key );
 
                 if ( value != null && !value.trim().isEmpty() )
                 {                    

=== 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	2013-10-10 08:26:52 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/translation/DefaultTranslationService.java	2013-10-16 19:09:50 +0000
@@ -71,6 +71,11 @@
         return translationStore.getTranslation( className, id, locale, property );
     }
 
+    public Translation getTranslationNoFallback( String className, int id, Locale locale, String property )
+    {
+        return translationStore.getTranslationNoFallback( className, id, locale, property );
+    }
+
     public Collection<Translation> getTranslations( String className, int id, Locale locale )
     {
         return translationStore.getTranslations( className, id, locale );

=== 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	2013-10-10 08:26:52 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/translation/hibernate/HibernateTranslationStore.java	2013-10-16 19:09:50 +0000
@@ -96,6 +96,25 @@
     }
 
     @SuppressWarnings( "unchecked" )
+    public Translation getTranslationNoFallback( String className, int id, Locale locale, String property )
+    {
+        Session session = sessionFactory.getCurrentSession();
+
+        Criteria criteria = session.createCriteria( Translation.class );
+
+        criteria.add( Restrictions.eq( "className", className ) );
+        criteria.add( Restrictions.eq( "id", id ) );
+        criteria.add( Restrictions.eq( "locale", locale.toString() ) );
+        criteria.add( Restrictions.eq( "property", property ) );
+
+        criteria.setCacheable( true );
+
+        List<Translation> translations = criteria.list();     
+               
+        return !translations.isEmpty() ? translations.get( 0 ) : null;
+    }
+    
+    @SuppressWarnings( "unchecked" )
     public Collection<Translation> getTranslations( String className, int id, Locale locale )
     {
         Session session = sessionFactory.getCurrentSession();