Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Warren-Dean Langeveldt 7 posts 27 karma points
    Feb 28, 2012 @ 02:17
    Warren-Dean Langeveldt
    0

    Hi Dimitr, im finding this package very useful.awesome job.

    I've extended it to create translations for child nodes, hope thats ok:

    • Added a radio list to the create page ("apply to immediate child nodes", "apply to all child nodes", "only current node")

    <asp:RadioButtonList  ID="ApplyToChildNodes_RB" runat="server" >
        <asp:ListItem Selected=True >Only Current Node</asp:ListItem>
        <asp:ListItem >Apply to Immediate Child Nodes</asp:ListItem>
         <asp:ListItem>Apply to all Child Nodes</asp:ListItem>
                    </asp:RadioButtonList>  

    • Tweaked "TranslationCreation.aspx.cs" as follows:

    private void save_Click(object sender, ImageClickEventArgs e)
            {
                string saved = "";
               
                if (ApplyToChildNodes_RB.SelectedItem.Text == "Apply to Immediate Child Nodes")
                {
                    saved =  ApplyToImmediateChildNodes(_nodeID);
                }
                else if (ApplyToChildNodes_RB.SelectedItem.Text == "Apply to all Child Nodes")
                {
                    saved =  ApplyToChildNodes(_nodeID);
                }
                else
                {
                    saved = createTranslation(_nodeID);
                }

                Response.Redirect(_queryString.BeforeUrl + "?NodeID=" + _nodeID.ToStr() + "&saved=" + saved);
            }


            private string ApplyToChildNodes(int Node)
            {
                var doc = new Document(Node);

                if (doc.ChildCount > 0)
                {
                    foreach (Document child in doc.Children)
                    {
                        ApplyToChildNodes(child.Id);
                    }

                }

                return createTranslation(Node);


            }

            private string ApplyToImmediateChildNodes(int Node)
            {
                var doc = new Document(Node);

                if (doc.ChildCount > 0)
                {
                    foreach (Document child in doc.Children)
                    {
                        createTranslation(child.Id);
                    }

                }

               return createTranslation(Node);
            }

            private String createTranslation(int node_id)
            {
                var saved = "ok";
                if (DocumentTranslation.GetTranslationFolderContentType(node_id) != null)
                {
                    try
                    {
                        if (!DocumentTranslation.TranslationFolderExists(node_id))
                            if (!DocumentTranslation.TranslationFolderCreate(node_id)) throw new Exception();

                        if (CheckBoxList1.Items.Cast<ListItem>().Where(li => li.Selected).Any(li => !DocumentTranslation.TranslationNodeCreate(node_id, li.Value)))
                        {
                            throw new Exception();
                        }

                        DocumentTranslation.SortTranslationNodes(node_id);
                    }
                    catch (Exception ex)
                    {
                        saved = ex.Message == "NoLangProp" ? "NoLangProp" : "failed";
                    }

                   
                }
                return saved;
            }

     

    It works as it should but i might have overlooked something and possibly write the code better. But the idea is probably worth putting into a next release? What do you think?

     

  • dimi309 244 posts 578 karma points
    Mar 01, 2012 @ 06:06
    dimi309
    0

    Hello Warren,

    Thank you for your interest in the Polyglot package and for your nice comments!

    About your question, yes, it is certainly ok to modify the package in any way you like for your own projects. I think that your modification is a very good idea!

    Having had a quick look at your code, I'm thinking that maybe you might want to check, when you apply to child nodes, if a child node itself is a translation folder. In that case it would be a good idea to skip it. Also, I have noticed that in some cases you do not pick up the return value of createTranslation, so you might not be creating the appropriate error message in the interface, whenever something happens to go wrong.

    I hope that this information is helpful. Whenever you believe that your code is complete, if you would like me to test and possibly integrate it into a release, please create a fork and pull request on the project's pages on Codeplex:

    http://polyglot.codeplex.com/SourceControl/list/changesets

    Best regards,

    Dimitri

     

  • Warren-Dean Langeveldt 7 posts 27 karma points
    Mar 02, 2012 @ 03:16
    Warren-Dean Langeveldt
    0

    Hi Dimitri,

    I thought i'd miss something. The other thing that would need to change is to keep the language check list enabled. What happens now, the next time you want to do a bulk translation, you cant select the languages if that current node has already been translated.

    I cant remember but im assuming that it does not bother re-creating translation nodes if it already exists, so it would be safe to have the langauge checklist enabled.

    Also later, maybe have bulk remove translation function. May or may not be necessary

    Regards
    Warren

Please Sign in or register to post replies

Write your reply to:

Draft