[Yanel-commits] rev 28355 - public/yanel/trunk/src/resources/translation/src/java/org/wyona/yanel/impl/resources

simon at wyona.com simon at wyona.com
Thu Nov 1 16:00:32 CET 2007


Author: simon
Date: 2007-11-01 16:00:32 +0100 (Thu, 01 Nov 2007)
New Revision: 28355

Modified:
   public/yanel/trunk/src/resources/translation/src/java/org/wyona/yanel/impl/resources/TranslationResource.java
Log:
see bug http://bugzilla.wyona.com/cgi-bin/bugzilla/show_bug.cgi?id=5639
thanks to josias!

Modified: public/yanel/trunk/src/resources/translation/src/java/org/wyona/yanel/impl/resources/TranslationResource.java
===================================================================
--- public/yanel/trunk/src/resources/translation/src/java/org/wyona/yanel/impl/resources/TranslationResource.java	2007-11-01 14:44:40 UTC (rev 28354)
+++ public/yanel/trunk/src/resources/translation/src/java/org/wyona/yanel/impl/resources/TranslationResource.java	2007-11-01 15:00:32 UTC (rev 28355)
@@ -38,6 +38,7 @@
 import org.wyona.yanel.core.ResourceConfiguration;
 import org.wyona.yanel.core.api.attributes.TranslatableV1;
 import org.wyona.yanel.core.api.attributes.ViewableV2;
+import org.wyona.yanel.core.attributes.translatable.TranslationManager;
 import org.wyona.yanel.core.attributes.viewable.View;
 import org.wyona.yanel.core.attributes.viewable.ViewDescriptor;
 import org.wyona.yanel.core.serialization.SerializerFactory;
@@ -176,11 +177,12 @@
         StringBuffer sb = new StringBuffer("<?xml version=\"1.0\"?>");
         sb.append("<translations xmlns=\"" + NS_URI + "\">");
         
+        String[] realmLanguages = resource.getRealm().getLanguages();
+        
         if (ResourceAttributeHelper.hasAttributeImplemented(resource, "Translatable", "1")) {
             TranslatableV1 translatable = ((TranslatableV1) resource);
             
             List existingLanguages = Arrays.asList(translatable.getLanguages());
-            String[] realmLanguages = resource.getRealm().getLanguages(); 
             
             for (int i = 0; i < realmLanguages.length; i++) {
                 String current = "";
@@ -196,6 +198,29 @@
                             " exists=\"false\"/>");
                 }
             }
+        } else {
+            // try to generate language links even if the resource is not translatable
+            // this makes sense e.g. with the PrefixTranslationManager because in that
+            // case assumptions can be made about how the paths look like.
+            TranslationManager translationMgr = getRealm().getTranslationManager();
+            List existingLanguages = Arrays.asList(translationMgr.getLanguages(resource));
+            
+            for (int i = 0; i < realmLanguages.length; i++) {
+                String current = "";
+                if (currentLanguage.equals(realmLanguages[i])) {
+                    current = "current=\"true\" ";
+                }
+                if (existingLanguages.contains(realmLanguages[i])) {
+                    Resource translation = translationMgr.getTranslation(resource, realmLanguages[i]);
+                    if (translation != null) {
+                        sb.append("<translation language=\"" + realmLanguages[i] + "\" path=\"" + 
+                                translation.getPath() + "\" " + current + " exists=\"true\"/>");
+                    }
+                } else {
+                    sb.append("<translation language=\"" + realmLanguages[i] + "\" " + current + 
+                            " exists=\"false\"/>");
+                }
+            }
         }
         
         sb.append("</translations>");



More information about the Yanel-commits mailing list