/// <summary>
    /// Saves translation for given resource string.
    /// </summary>
    /// <returns>Returns TRUE if resource string was successfully modified</returns>
    public override bool Save()
    {
        // Save changes only when macro is edited
        if (IsLocalizationMacro && mUserHasPermissionForLocalizations)
        {
            string resKey = GetResouceKeyFromString(OriginalValue);

            if (!IsInplaceMacro(TextBox.Text))
            {
                // Update key
                var ri = ResourceStringInfoProvider.GetResourceStringInfo(resKey);
                if (ri != null)
                {
                    ri.TranslationText = TextBox.Text.Trim();
                    if (CultureInfoProvider.GetCultureID(CultureHelper.PreferredUICultureCode) != 0)
                    {
                        ri.CultureCode = CultureHelper.PreferredUICultureCode;
                    }
                    else
                    {
                        ri.CultureCode = CultureHelper.DefaultUICultureCode;
                    }
                    ResourceStringInfoProvider.SetResourceStringInfo(ri);
                    return(true);
                }
            }
            else
            {
                // Remove localization if in-place macro was inserted
                RemoveLocalization(resKey);
            }
        }
        return(false);
    }
    /// <summary>
    /// Button localize click. In AutomaticMode available only.
    /// </summary>
    void btnLocalize_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(TextBox.Text.Trim()))
        {
            // Initialize resource string
            OriginalValue = LocalizationHelper.GetUniqueResStringKey(TextBox.Text.Trim(), ResourceKeyPrefix, true, MAX_KEY_LENGTH);

            string cultureCode = CultureHelper.PreferredUICultureCode;
            if (String.IsNullOrEmpty(cultureCode))
            {
                cultureCode = CultureHelper.DefaultUICultureCode;
            }

            // Save ResourceString
            ResourceStringInfo ri = new ResourceStringInfo();
            ri.StringKey       = OriginalValue;
            ri.CultureCode     = cultureCode;
            ri.TranslationText = TextBox.Text;
            ri.StringIsCustom  = !SystemContext.DevelopmentMode;
            ResourceStringInfoProvider.SetResourceStringInfo(ri);

            // Open 'localization to other languages' window
            string script = ScriptHelper.GetScript("modalDialog('" + ResolveUrl(LOCALIZE_STRING) + "?hiddenValueControl=" + hdnValue.ClientID + "&stringKey=" + ri.StringKey + "&parentTextbox=" + textbox.ClientID + "', 'localizableString', 600, 635, null, null, true);");
            ScriptHelper.RegisterStartupScript(this, typeof(string), "OpenLocalization", script);

            // Set macro settings
            Value = MACRO_START + OriginalValue + MACRO_END;
            Reload();
        }
        else
        {
            lblError.Visible        = true;
            lblError.ResourceString = "localize.entertext";
        }
    }
 /// <summary>
 /// Removes localization from database if AutomaticMode is on.
 /// </summary>
 private void RemoveLocalization(string resKey)
 {
     // In automatic mode remove resource string key
     if (AutomaticMode)
     {
         ResourceStringInfoProvider.DeleteResourceStringInfo(resKey);
     }
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Localization", "LocalizeStrings"))
        {
            txtStringKey.Enabled = false;
            chkIsCustom.Enabled  = false;
            EnableTranslations   = false;
        }

        mResourceStringInfo = ResourceStringInfoProvider.GetResourceStringInfo(EditedResourceStringKey);
        if (mResourceStringInfo == null)
        {
            mResourceStringInfo = ResourceStringInfoProvider.GetResourceStringInfo(QueryHelper.GetInteger("stringid", 0));
            if (mResourceStringInfo == null)
            {
                // Try to load resource string info by string key
                string stringKey = QueryHelper.GetString("stringkey", String.Empty);
                mResourceStringInfo = ResourceStringInfoProvider.GetResourceStringInfo(stringKey);

                if (mResourceStringInfo == null)
                {
                    mResourceStringInfo = new ResourceStringInfo();
                    mResourceStringInfo.StringIsCustom = !SystemContext.DevelopmentMode;
                    mResourceStringInfo.StringKey      = stringKey;
                }
            }
        }

        // Set edited object
        EditedObject = mResourceStringInfo;

        if (!RequestHelper.IsPostBack())
        {
            txtStringKey.Text   = mResourceStringInfo.StringKey;
            chkIsCustom.Checked = mResourceStringInfo.StringIsCustom;
            plcIsCustom.Visible = SystemContext.DevelopmentMode;

            // Automatically display changes saved text
            if (QueryHelper.GetBoolean("saved", false))
            {
                ShowChangesSaved();
            }

            LoadLastSelectedItem();
        }

        tblHeaderCellLabel.Text = GetString("culture.translation");

        ReloadData();
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Saves translation for given resource string.
    /// </summary>
    /// <returns>Returns TRUE if resource string was successfully modified</returns>
    public override bool Save()
    {
        // Save changes only when translation is edited
        if (IsLocalizationMacro && mUserHasPermissionForLocalizations && LocalizationExists && !IsInplaceMacro(OriginalValue))
        {
            string resKey = GetResourceKeyFromString(OriginalValue);

            // Prevent from creating translation containing macro
            if (!MacroProcessor.IsLocalizationMacro(TextBox.Text))
            {
                resKey = resKey.Trim();

                var translationText = TextBox.Text.Trim();
                if (string.IsNullOrEmpty(translationText))
                {
                    lblError.Visible        = true;
                    lblError.ResourceString = "localize.entertext";
                    return(false);
                }

                var cultureCode = CultureInfoProvider.GetCultureID(CultureHelper.PreferredUICultureCode) != 0
                    ? CultureHelper.PreferredUICultureCode
                    : CultureHelper.DefaultUICultureCode;

                if (IsTranslationChanged(resKey, cultureCode, translationText))
                {
                    // Update / insert key
                    var ri = ResourceStringInfoProvider.GetResourceStringInfo(resKey) ?? new ResourceStringInfo
                    {
                        StringKey      = resKey,
                        StringIsCustom = !SystemContext.DevelopmentMode
                    };

                    ri.TranslationText = translationText;
                    ri.CultureCode     = cultureCode;

                    ResourceStringInfoProvider.SetResourceStringInfo(ri);
                    return(true);
                }

                return(false);
            }
        }

        return(false);
    }
    /// <summary>
    /// Saves translation for given resource string.
    /// </summary>
    /// <returns>Returns TRUE if resource string was successfully modified</returns>
    public override bool Save()
    {
        // Save changes only when translation is edited
        if (IsLocalizationMacro && mUserHasPermissionForLocalizations && LocalizationExists && !IsInplaceMacro(OriginalValue))
        {
            string resKey = GetResouceKeyFromString(OriginalValue);

            // Prevent from creating translation containing macro
            if (!MacroProcessor.IsLocalizationMacro(TextBox.Text))
            {
                resKey = resKey.Trim();

                // Update / insert key
                var ri = ResourceStringInfoProvider.GetResourceStringInfo(resKey) ?? new ResourceStringInfo
                {
                    StringKey      = resKey,
                    StringIsCustom = !SystemContext.DevelopmentMode
                };

                ri.TranslationText = TextBox.Text.Trim();
                if (CultureInfoProvider.GetCultureID(CultureHelper.PreferredUICultureCode) != 0)
                {
                    ri.CultureCode = CultureHelper.PreferredUICultureCode;
                }
                else
                {
                    ri.CultureCode = CultureHelper.DefaultUICultureCode;
                }
                ResourceStringInfoProvider.SetResourceStringInfo(ri);
                return(true);
            }
            else
            {
                // Remove localization if in-place macro was inserted
                RemoveLocalization(resKey);
            }
        }
        return(false);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get parameters from query string
        string resStringKey = QueryHelper.GetString("stringkey", String.Empty);
        string cultureCode  = QueryHelper.GetString("culturecode", String.Empty);

        ResourceStringInfo ri = ResourceStringInfoProvider.GetResourceStringInfo(resStringKey, cultureCode);

        if (ri != null)
        {
            if (ri.StringID > 0)
            {
                // Modify breadcrumbs
                if (PageBreadcrumbs.Items.Count >= 2)
                {
                    var lastBreadcrumb = PageBreadcrumbs.Items.Last();
                    lastBreadcrumb.Text = ri.StringKey;
                }

                // Set actions
                CurrentMaster.HeaderActions.ActionsList.Add(new HeaderAction
                {
                    Text        = GetString("culture.newstring"),
                    RedirectUrl = ResolveUrl("Edit.aspx?culturecode=" + cultureCode),
                    ButtonStyle = ButtonStyle.Default
                });
            }
            else
            {
                // Create new resource string
                resEditor.RedirectUrlAfterSave = "Edit.aspx?stringkey={0}&culturecode=" + cultureCode;
            }
        }
        else
        {
            ShowError(GetString("localize.doesntexist"));
            resEditor.Visible = false;
        }
    }
Ejemplo n.º 8
0
    /// <summary>
    /// Button OK clicked.
    /// </summary>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        // Check if current user's culture exists
        string cultureCode = CultureHelper.PreferredUICultureCode;

        if (String.IsNullOrEmpty(cultureCode))
        {
            cultureCode = CultureHelper.DefaultUICultureCode;
        }

        ResourceStringInfo ri;
        string             key;

        // Creating new resource string
        if (lstExistingOrNew.SelectedValue == "new")
        {
            key = SystemContext.DevelopmentMode ? txtNewResource.Text.Trim() : resourceKeyPrefix + txtNewResource.Text.Trim();
            ri  = ResourceStringInfoProvider.GetResourceStringInfo(key);

            // Resource string doesn't exists yet
            if (ri == null)
            {
                if (!ValidationHelper.IsCodeName(key))
                {
                    ShowError(GetString("culture.invalidresstringkey"));
                }
                else
                {
                    // Save ResourceString
                    ri                 = new ResourceStringInfo();
                    ri.StringKey       = key;
                    ri.CultureCode     = cultureCode;
                    ri.TranslationText = plainText;
                    ri.StringIsCustom  = !SystemContext.DevelopmentMode;
                    ResourceStringInfoProvider.SetResourceStringInfo(ri);
                }
            }

            string script = ScriptHelper.GetScript("wopener.SetResourceAndOpen('" + hdnValue + "', '" + ScriptHelper.GetString(key, false) + "', '" + textbox + "', " + ScriptHelper.GetString(plainText) + ", '" + btnLocalizeField + "', '" + btnLocalizeString + "', '" + btnRemoveLocalization + "', '" + localizedInputContainer + "'); CloseDialog();");
            ScriptHelper.RegisterStartupScript(this, typeof(string), "localizeField", script);
        }
        // Using existing resource string
        else
        {
            key = ValidationHelper.GetString(resourceSelector.Value, String.Empty);
            ri  = ResourceStringInfoProvider.GetResourceStringInfo(key);

            // Key not found in DB
            if (ri == null)
            {
                // Try to find it in .resx file and save it in DB
                FileResourceManager resourceManager = LocalizationHelper.GetFileManager(cultureCode);
                if (resourceManager != null)
                {
                    string translation = resourceManager.GetString(key);
                    if (!String.IsNullOrEmpty(translation))
                    {
                        ri                 = new ResourceStringInfo();
                        ri.StringKey       = key;
                        ri.StringIsCustom  = !SystemContext.DevelopmentMode;
                        ri.CultureCode     = cultureCode;
                        ri.TranslationText = translation;
                        ResourceStringInfoProvider.SetResourceStringInfo(ri);

                        string script = ScriptHelper.GetScript("wopener.SetResource('" + hdnValue + "', '" + key + "', '" + textbox + "', " + ScriptHelper.GetString(translation) + ", '" + btnLocalizeField + "', '" + btnLocalizeString + "', '" + btnRemoveLocalization + "', '" + localizedInputContainer + "'); CloseDialog();");
                        ScriptHelper.RegisterStartupScript(this, typeof(string), "localizeField", script);
                    }
                    else
                    {
                        ShowError(GetString("localize.doesntexist"));
                    }
                }
                else
                {
                    ShowError(GetString("localize.doesntexist"));
                }
            }
            // Send to parent window selected resource key
            else
            {
                using (LocalizationActionContext context = new LocalizationActionContext())
                {
                    context.ResolveSubstitutionMacros = false;
                    string script = ScriptHelper.GetScript("wopener.SetResource('" + hdnValue + "', '" + key + "', '" + textbox + "', " + ScriptHelper.GetLocalizedString(key) + ", '" + btnLocalizeField + "', '" + btnLocalizeString + "', '" + btnRemoveLocalization + "', '" + localizedInputContainer + "'); CloseDialog();");
                    ScriptHelper.RegisterStartupScript(this, typeof(string), "localizeField", script);
                }
            }
        }
    }