/// <summary>
    /// Translates object to new culture.
    /// </summary>
    protected void btnTranslate_Click(object sender, EventArgs e)
    {
        if (TranslationServiceHelper.IsAuthorizedToTranslateDocument(Node, MembershipContext.AuthenticatedUser))
        {
            try
            {
                // Submits the document to translation service
                string err = translationElem.SubmitToTranslation();
                if (string.IsNullOrEmpty(err))
                {
                    // Refresh page
                    string script;
                    if (RequiresDialog)
                    {
                        string url = UrlResolver.ResolveUrl(DocumentURLProvider.GetUrl(Node) + "?" + URLHelper.LanguageParameterName + "=" + RequiredCulture);
                        script = "window.top.location = " + ScriptHelper.GetString(url) + ";";
                    }
                    else
                    {
                        ViewModeEnum mode = ViewModeEnum.Edit;
                        if (!TreePathUtils.IsMenuItemType(Node.NodeClassName) && (PortalContext.ViewMode != ViewModeEnum.EditLive))
                        {
                            mode = ViewModeEnum.EditForm;
                        }
                        script = "if (FramesRefresh) { FramesRefresh(" + Node.NodeID + ", '" + mode + "'); }";
                    }

                    ScriptHelper.RegisterStartupScript(this, typeof(string), "NewCultureRefreshAction", ScriptHelper.GetScript(script));
                }
                else
                {
                    ShowError(err);
                }
            }
            catch (Exception ex)
            {
                ShowError(GetString("ContentRequest.TranslationFailed"), ex.Message);
                TranslationServiceHelper.LogEvent(ex);
            }
        }
        else
        {
            RedirectToAccessDenied("CMS.Content", "SubmitForTranslation");
        }
    }
Example #2
0
 protected void btnTranslate_Click(object sender, EventArgs e)
 {
     if (TranslationServiceHelper.IsAuthorizedToTranslateDocument(node, CMSContext.CurrentUser))
     {
         try
         {
             // Submits the document to translation service
             string err = translationElem.SubmitToTranslation();
             if (string.IsNullOrEmpty(err))
             {
                 // Refresh page
                 if (RequiresDialog)
                 {
                     string url = URLHelper.ResolveUrl(DocumentURLProvider.GetUrl(node.NodeAliasPath) + "?" + URLHelper.LanguageParameterName + "=" + RequiredCulture);
                     ScriptHelper.RegisterStartupScript(this, typeof(string), "NewCultureRefreshAction", ScriptHelper.GetScript(" window.top.location = " + ScriptHelper.GetString(url)));
                 }
                 else
                 {
                     ScriptHelper.RegisterStartupScript(this, typeof(string), "NewCultureRefreshAction", ScriptHelper.GetScript("if (FramesRefresh) { FramesRefresh(" + node.NodeID + "); }"));
                 }
             }
             else
             {
                 ShowError(err);
             }
         }
         catch (Exception ex)
         {
             ShowError(GetString("ContentRequest.TranslationFailed"), ex.Message, null);
             TranslationServiceHelper.LogEvent(ex);
         }
     }
     else
     {
         RedirectToCMSDeskAccessDenied("CMS.Content", "SubmitForTranslation");
     }
 }
Example #3
0
    /// <summary>
    /// Uploads the translations submitted.
    /// </summary>
    /// <returns>Zero if upload was not successful. Positive number if upload was successful (one if whole translation was uploaded and status can be therefore changed, two if only part of submission was uploaded).</returns>
    public bool UploadTranslation()
    {
        // Check permissions
        if (CheckContentPermissions)
        {
            var user = MembershipContext.AuthenticatedUser;
            if (!user.IsAuthorizedPerResource("CMS.Content", "Read"))
            {
                RedirectToAccessDenied("CMS.Content", "Read");
            }
            if (!user.IsAuthorizedPerResource("CMS.Content", "Create"))
            {
                RedirectToAccessDenied("CMS.Content", "Create");
            }
        }

        try
        {
            if ((uploadElem.PostedFile == null) || string.IsNullOrEmpty(uploadElem.PostedFile.FileName))
            {
                ShowError(GetString("newfile.errorempty"));
                return(false);
            }

            if (SubmissionItem != null)
            {
                if (!FileInfo.New(uploadElem.PostedFile.FileName).Extension.TrimStart('.').EqualsCSafe(TranslationServiceHelper.XLIFFEXTENSION, true))
                {
                    ShowError(GetString("translationservice.xliffallowed"));
                    return(false);
                }

                byte[] xliffBytes = uploadElem.FileBytes;
                if (xliffBytes != null)
                {
                    SubmissionItem.SubmissionItemTargetXLIFF = Encoding.UTF8.GetString(xliffBytes);
                    TranslationSubmissionItemInfoProvider.SetTranslationSubmissionItemInfo(SubmissionItem);

                    return(true);
                }
            }
            else if (Submission != null)
            {
                if (uploadElem.PostedFile.FileName.EndsWithCSafe(".zip", true))
                {
                    string badFiles = TranslationServiceHelper.ImportXLIFFfromZIP(Submission, StreamWrapper.New(uploadElem.PostedFile.InputStream));
                    if (string.IsNullOrEmpty(badFiles))
                    {
                        // Update status of the submission to "Translation ready"
                        Submission.SubmissionStatus = TranslationStatusEnum.TranslationReady;
                        TranslationSubmissionInfoProvider.SetTranslationSubmissionInfo(Submission);

                        if (!AutoImport)
                        {
                            return(true);
                        }

                        // Handle auto import
                        string importErr = TranslationServiceHelper.AutoImportSubmission(Submission);
                        if (string.IsNullOrEmpty(importErr))
                        {
                            return(true);
                        }

                        ShowError(importErr);
                        return(false);
                    }

                    ShowError(string.Format(GetString("translationservice.badfilesinzip"), badFiles));
                }
                else
                {
                    ShowError(GetString("translationservice.zipfileexpected"));
                }
            }
        }
        catch (Exception ex)
        {
            TranslationServiceHelper.LogEvent(ex);
            ShowError(ex.Message);
        }

        return(false);
    }