コード例 #1
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 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);
    }
コード例 #2
0
    private void SaveResourceStringInfo(string resKey)
    {
        mResourceStringInfo.StringIsCustom = chkIsCustom.Checked;
        mResourceStringInfo.StringKey      = resKey;

        ResourceStringInfoProvider.SetResourceStringInfo(mResourceStringInfo);

        // We need reload mResourceStringInfo, because StringId was changed after first save
        mResourceStringInfo = ResourceStringInfoProvider.GetResourceStringInfo(resKey);
    }
コード例 #3
0
    /// <summary>
    /// Key is free to use if is not used, or is used with current resKey.
    /// </summary>
    /// <param name="stringId"></param>
    /// <param name="resKey"></param>
    private bool KeyIsFreeToUse(int stringId, string resKey)
    {
        ResourceStringInfo rsi = ResourceStringInfoProvider.GetResourceStringInfo(resKey);

        if (rsi == null)
        {
            return(true);
        }

        return(rsi.StringID == stringId);
    }
コード例 #4
0
    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();
    }
コード例 #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);
    }
コード例 #6
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 = 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);
    }
コード例 #7
0
    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;
        }
    }
コード例 #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);
                }
            }
        }
    }