4 Replies Latest reply on May 5, 2014 2:57 AM by George Florentin

    Use xml:lang to switch language information with dropdown button

    alexanderklapfer Level 1

      Hallo,

      I would like to build a multilingual form. 4 languages stored inside one single PDF. The language should be changed with a dropdown Button.

      result.jpg

       

      I added in the XML view the attributes like the following.

      screen_2.jpg

       

      My question:

      • how I can create a script for the dropdown Button who changes me every element with an xml:lang indication ?
      • the script should work for pdf's with more than one page

       

      It would be great If somebody could help me. I tryed this script from this grat blog, the result'll be the same, but I guess that working with the xml:lang element it's a better way to mantain a single multilang PDF.

       

      Thank you for every help I get.

      alex

        • 2. Re: Use xml:lang to switch language information with dropdown button
          George Florentin Level 1

          Here is another solution for you:

          - create 4 check-boxes (EN, FR, DE, IT), each in it's own subform - set as repeater, with minimum 0;

          - on "change" event of the drop-down you set the instance to 1 for the subform which contains the check-box you are interested in and instance 0 for the rest;

          - this will work and is easy to maintain in future, but when you change the language (and instances are added/removed) the check-boxes will be reset (if the user selects the check-box and then changes the language).

           

          If this method does not help you, tell me and maybe I can think of something else.

           

          From experience, messing with the XML as you are trying to do is never a good idea.

          • 3. Re: Re: Use xml:lang to switch language information with dropdown button
            alexanderklapfer Level 1

            Hallo, thank you for your help.

             

            In Life Cycle I wasn't able to set up the scripting but I reached the aim using Adobe InDesign.

             

            1. I buid the layout in Indesign
            2. In InDesign I can place form elements like radio buttons, form fields, ecc.
              N.B.: Each language element on a specific layer
            3. I save the PDF from InDesign
            4. I open the PDF inside ACROBAT
            5. I insert the JAVA script on a button. The script manages the visibility of layers.
              N.B.: A solution with a dropdown box doesn't work becaus the rights management in the free reader version don't accept some JAVA code !!! With button everything work's !

             

            //read quantity of layer and create array
            var layers = this.getOCGs();
            
            //lock system layers
            for(var i=0;i<this.layers.length;i++)
            {
                            //visibility of layers
                            if(layers[i].name == "deutsch")
                            layers[i].state = false;
                            if(layers[i].name == "italiano")
                            layers[i].state = false;
                            if(layers[i].name == "francais")
                            layers[i].state = false;
                            if(layers[i].name == "english")
                            layers[i].state = true;
            }
            

             

            If you want to take a look on my solution, here is the PDF with buttons:

            https://cloud.technoalpin.com/public.php?service=files&t=e68f345052968b17257e1d227b7b5687

             

            If you want to take a look on my solution, here is the PDF with dropdown:

            https://cloud.technoalpin.com/public.php?service=files&t=f2f61d880384909b3a3cf2aabdc6c475

             

            It's possible to get a similar result in Lifecycle Designer too ? This because in this way I only use one Software not two and the performance is much better.

             

            Best regards

            alex

             

            Here the code for the dropdown button named "language". You must copy the code in the section CUSTOM CALCULATION FIELD.

            In the PDF you must have the named layers

            • deutsch
            • italiano
            • francais
            • english
            • form (this layer 'll be locked at the beginning)
            • background (this layer 'll be locked at the beginning)

             

            //read quantity of layer and create array
            var layers = this.getOCGs();
            
            //lock system layers
            for(var i=0;i<this.layers.length;i++)
            {
                //if(layers[i].name == "button")
                //layers[i].locked = true;
                if(layers[i].name == "form")
                layers[i].locked = true;
                if(layers[i].name == "background")
                layers[i].locked = true;
            }
            
            //read value of combobox
            event.value = this.getField("language").value;
            
            //make choise 
            switch(event.value){
                    case "deutsch":
                        //app.alert ("deutsch", 3);
                        //find layer by names in array
                        for(var i=0;i<this.layers.length;i++)
                        {
                            //visibility of layers
                            if(layers[i].name == "deutsch")
                            layers[i].state = true;
                            if(layers[i].name == "italiano")
                            layers[i].state = false;
                            if(layers[i].name == "francais")
                            layers[i].state = false;
                            if(layers[i].name == "english")
                            layers[i].state = false;
                        }
                        break;
            
                    case "italiano":
                        //app.alert ("italiano", 3);
                        for(var i=0;i<this.layers.length;i++)
                        {
                            //visibility of layers
                            if(layers[i].name == "deutsch")
                            layers[i].state = false;
                            if(layers[i].name == "italiano")
                            layers[i].state = true;
                            if(layers[i].name == "francais")
                            layers[i].state = false;
                            if(layers[i].name == "english")
                            layers[i].state = false;
                        }
                        break;
            
                    case "francais":
                        //app.alert ("francais", 3);
                        for(var i=0;i<this.layers.length;i++)
                        {
                            //visibility of layers
                            if(layers[i].name == "deutsch")
                            layers[i].state = false;
                            if(layers[i].name == "italiano")
                            layers[i].state = false;
                            if(layers[i].name == "francais")
                            layers[i].state = true;
                            if(layers[i].name == "english")
                            layers[i].state = false;
                        }
                        break;
            
                    case "english":
                        //app.alert ("english", 3);
                        for(var i=0;i<this.layers.length;i++)
                        {
                            //visibility of layers
                            if(layers[i].name == "deutsch")
                            layers[i].state = false;
                            if(layers[i].name == "italiano")
                            layers[i].state = false;
                            if(layers[i].name == "francais")
                            layers[i].state = false;
                            if(layers[i].name == "english")
                            layers[i].state = true;
                        }
                        break;
                    }
            
            • 4. Re: Re: Use xml:lang to switch language information with dropdown button
              George Florentin Level 1

              To avoid counting the elements on every iteration, replace this line

              for(var i=0;i<this.layers.length;i++)

              with this line

              for(var i=0,j=this.layers.length;i<j;i++)