Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-6202

Create a new translation for a document via the unprivileged velocity API

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: 3.0
    • Fix Version/s: None
    • Component/s: Old Core
    • Labels:
      None
    • keywords:
      patch
    • Difficulty:
      Trivial
    • Pull Request Status:
      Awaiting Committer feedback
    • Similar issues:

      Description

      There does not seem to be any way to create a new translation of a document via the restricted API. I therefore propose this as an addition:

      Index: src/main/java/com/xpn/xwiki/doc/XWikiDocument.java
      ===================================================================
      --- src/main/java/com/xpn/xwiki/doc/XWikiDocument.java	(revision 36199)
      +++ src/main/java/com/xpn/xwiki/doc/XWikiDocument.java	(working copy)
      @@ -5348,6 +5348,11 @@
       
           public XWikiDocument getTranslatedDocument(String language, XWikiContext context) throws XWikiException
           {
      +        return getTranslatedDocument(language, false, context);
      +    }
      +
      +    public XWikiDocument getTranslatedDocument(String language, boolean create, XWikiContext context) throws XWikiException
      +    {
               XWikiDocument tdoc = this;
       
               if (!((language == null) || (language.equals("")) || language.equals(getDefaultLanguage()))) {
      @@ -5364,7 +5369,16 @@
                       tdoc = getStore(context).loadXWikiDoc(tdoc, context);
       
                       if (tdoc.isNew()) {
      -                    tdoc = this;
      +                    boolean dontCreate = true;
      +                    if (create && context.getWiki().isMultiLingual(context)) {
      +                        List<String> available
      +                            = Arrays.asList(context.getWiki()
      +                                            .getXWikiPreference("languages", context).split("[, |]"));
      +                        dontCreate = !available.contains(language);
      +                    }
      +                    if (dontCreate) {
      +                        tdoc = this;
      +                    }
                       }
                   } catch (Exception e) {
                       tdoc = this;
      Index: src/main/java/com/xpn/xwiki/api/Document.java
      ===================================================================
      --- src/main/java/com/xpn/xwiki/api/Document.java	(revision 36199)
      +++ src/main/java/com/xpn/xwiki/api/Document.java	(working copy)
      @@ -532,8 +532,18 @@
           }
       
           /**
      +     * @param language Language code for the translation.
      +     * @param create If {@code true}, create a new translation if it does not exist.
            * @return the translated document in the given document
            */
      +    public Document getTranslatedDocument(String language, boolean create) throws XWikiException
      +    {
      +        return this.doc.getTranslatedDocument(language, create, getXWikiContext()).newDocument(getXWikiContext());
      +    }
      +
      +    /**
      +     * @return the translated document in the given document
      +     */
           public Document getTranslatedDocument(String language) throws XWikiException
           {
               return this.doc.getTranslatedDocument(language, getXWikiContext()).newDocument(getXWikiContext());
      
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                tmortagne Thomas Mortagne
                Reporter:
                aj Andreas Jonsson
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Date of First Response: