コード例 #1
0
    /// <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";
        }
    }
コード例 #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>
    /// Deletes resource string. Called when the "Delete resource string" button is pressed.
    /// Expects the CreateResourceString method to be run first.
    /// </summary>
    private bool DeleteResourceString()
    {
        // Get the resource string
        ResourceStringInfo deleteString = SqlResourceManager.GetResourceStringInfo("Test.MyNewResourceString");

        // Delete the resource string
        SqlResourceManager.DeleteResourceStringInfo(deleteString);

        return(deleteString != null);
    }
コード例 #4
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);
    }
コード例 #5
0
    protected void btnOK_Click(object sender, EventArgs e)
    {
        try
        {
            // Trim the key before save
            string key = txtKey.Text.Trim();
            // Validate the key
            string result = new Validator().NotEmpty(key, rfvKey.ErrorMessage).IsCodeName(key, GetString("Administration-UICulture_String_New.InvalidCodeName")).Result;

            if (String.IsNullOrEmpty(result))
            {
                // Check if resource string already exists with given code name
                ResourceStringInfo ri = SqlResourceManager.GetResourceStringInfo(key);
                if (ri == null)
                {
                    ri                 = new ResourceStringInfo();
                    ri.StringKey       = key;
                    ri.StringIsCustom  = chkCustomString.Checked;
                    ri.UICultureCode   = uic.UICultureCode;
                    ri.TranslationText = txtText.Text;
                    SqlResourceManager.SetResourceStringInfo(ri);

                    // If text for default culture is set, store it
                    if (!string.IsNullOrEmpty(txtEnglishText.Text.Trim()))
                    {
                        // Set code of default UI culture
                        ri.UICultureCode   = CultureHelper.DefaultUICulture;
                        ri.TranslationText = txtEnglishText.Text;
                        SqlResourceManager.SetResourceStringInfo(ri);
                    }

                    URLHelper.Redirect("Edit.aspx?uicultureid=" + uiCultureID + "&stringid=" + ri.StringId + "&saved=1&showBack=0");
                }
                else
                {
                    lblError.Text    = String.Format(GetString("Administration-UICulture_String_New.StringExists"), key);
                    lblError.Visible = true;
                }
            }

            if (!String.IsNullOrEmpty(result))
            {
                lblError.Text    = result;
                lblError.Visible = true;
            }
        }
        catch (Exception ex)
        {
            lblError.Text    = GetString("general.erroroccurred") + ex.Message;
            lblError.Visible = true;
        }
    }
コード例 #6
0
ファイル: New.aspx.cs プロジェクト: v-jli/jean0407large
    protected void btnOK_Click(object sender, EventArgs e)
    {
        try
        {
            // Trim the key before save
            string key = txtKey.Text.Trim();
            // Validate the key
            string result = new Validator().NotEmpty(key, rfvKey.ErrorMessage).IsCodeName(key, GetString("Administration-UICulture_String_New.InvalidCodeName")).Result;

            if (String.IsNullOrEmpty(result))
            {
                // Check if resource string already exists with given code name
                ResourceStringInfo ri = SqlResourceManager.GetResourceStringInfo(key);
                if (ri == null)
                {
                    ri = new ResourceStringInfo();
                    ri.StringKey = key;
                    ri.StringIsCustom = chkCustomString.Checked;
                    ri.UICultureCode = uic.UICultureCode;
                    ri.TranslationText = txtText.Text;
                    SqlResourceManager.SetResourceStringInfo(ri);

                    // If text for default culture is set, store it
                    if (!string.IsNullOrEmpty(txtEnglishText.Text.Trim()))
                    {
                        // Set code of default UI culture
                        ri.UICultureCode = CultureHelper.DefaultUICulture;
                        ri.TranslationText = txtEnglishText.Text;
                        SqlResourceManager.SetResourceStringInfo(ri);
                    }

                    URLHelper.Redirect("Edit.aspx?uicultureid=" + uiCultureID + "&stringid=" + ri.StringId + "&saved=1&showBack=0");
                }
                else
                {
                    lblError.Text = String.Format(GetString("Administration-UICulture_String_New.StringExists"), key);
                    lblError.Visible = true;
                }
            }

            if (!String.IsNullOrEmpty(result))
            {
                lblError.Text = result;
                lblError.Visible = true;
            }
        }
        catch (Exception ex)
        {
            lblError.Text = GetString("general.erroroccurred") + ex.Message;
            lblError.Visible = true;
        }
    }
コード例 #7
0
    /// <summary>
    /// Updates resource string for given culture.
    /// </summary>
    /// <param name="cultureCode">Culture code</param>
    /// <param name="translationText">Translation text</param>
    private void UpdateString(string cultureCode, string translationText)
    {
        // Update the string
        ResourceStringInfo ri = SqlResourceManager.GetResourceStringInfo(ValidationHelper.GetInteger(hdnID.Value, 0), cultureCode);

        if (ri != null)
        {
            ri.StringIsCustom  = chkIsCustom.Checked;
            ri.UICultureCode   = cultureCode;
            ri.TranslationText = translationText;
            SqlResourceManager.SetResourceStringInfo(ri);
        }
    }
コード例 #8
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();
    }
コード例 #9
0
    /// <summary>
    /// Creates resource string in default culture. Called when the "Create resourcestring" button is pressed.
    /// Expects the CreateUICulture method to be run first.
    /// </summary>
    private bool CreateResourceString()
    {
        // Create new resource string object
        ResourceStringInfo newString = new ResourceStringInfo();

        // Set the properties
        newString.StringKey = "Test.MyNewResourceString";
        newString.UICultureCode = SqlResourceManager.DefaultUICulture;
        newString.TranslationText = "My new resource string translation.";
        newString.StringIsCustom = true;

        // Save the resource string
        SqlResourceManager.SetResourceStringInfo(newString);

        return true;
    }
コード例 #10
0
    /// <summary>
    /// Creates resource string in default culture. Called when the "Create resourcestring" button is pressed.
    /// Expects the CreateUICulture method to be run first.
    /// </summary>
    private bool CreateResourceString()
    {
        // Create new resource string object
        ResourceStringInfo newString = new ResourceStringInfo();

        // Set the properties
        newString.StringKey       = "Test.MyNewResourceString";
        newString.UICultureCode   = SqlResourceManager.DefaultUICulture;
        newString.TranslationText = "My new resource string translation.";
        newString.StringIsCustom  = true;

        // Save the resource string
        SqlResourceManager.SetResourceStringInfo(newString);

        return(true);
    }
コード例 #11
0
    /// <summary>
    /// Gets and updates resource string. Called when the "Get and update resource string" button is pressed.
    /// Expects the CreateResourceString method to be run first.
    /// </summary>
    private bool GetAndUpdateResourceString()
    {
        // Get the resource string
        ResourceStringInfo updateString = SqlResourceManager.GetResourceStringInfo("Test.MyNewResourceString");

        if (updateString != null)
        {
            // Update the properties
            updateString.StringKey = updateString.StringKey.ToLower();

            // Save the changes
            SqlResourceManager.SetResourceStringInfo(updateString);

            return(true);
        }

        return(false);
    }
コード例 #12
0
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that threw event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void UniGridUICultures_OnAction(string actionName, object actionArgument)
    {
        ResourceStringInfo ri = SqlResourceManager.GetResourceStringInfo(actionArgument.ToString(), ui.UICultureCode);

        switch (actionName)
        {
        case "edit":
            URLHelper.Redirect(string.Format("Edit.aspx?stringid={0}&uicultureid={1}", ri.StringId, ui.UICultureID));
            break;

        case "delete":
            SqlResourceManager.DeleteResourceStringInfo(actionArgument.ToString(), ui.UICultureCode);
            break;

        case "deleteResource":
            SqlResourceManager.DeleteResourceStringInfo(actionArgument.ToString(), CultureHelper.DefaultUICulture);
            break;
        }
    }
コード例 #13
0
ファイル: Edit.aspx.cs プロジェクト: tvelzy/RadstackMedia
    /// <summary>
    /// Initializes Master Page.
    /// </summary>
    protected void InitializeMasterPage(ResourceStringInfo ri, bool defaultTextVisible)
    {
        // Initializes page breadcrumbs
        tabs[0, 0] = GetString("UICultures_Strings.Strings");
        tabs[0, 1] = ResolveUrl("List.aspx?UIcultureID=" + uiCultureID);
        tabs[1, 0] = ri.StringKey;
        CurrentMaster.Title.Breadcrumbs = tabs;

        // Set actions
        string[,] actions = new string[1, 8];
        actions[0, 0]     = "HyperLink";
        actions[0, 1]     = GetString("Development-UICulture_Strings_List.NewString");
        actions[0, 3]     = ResolveUrl("New.aspx?uicultureid=" + uiCultureID);
        actions[0, 5]     = GetImageUrl("CMSModules/CMS_UICultures/addstring.png");

        CurrentMaster.HeaderActions.Actions = actions;

        CurrentMaster.Title.HelpName      = "helpTopic";
        CurrentMaster.Title.HelpTopicName = defaultTextVisible ? "newedit_string" : "DefaultNewEdit_string";
    }
コード例 #14
0
    /// <summary>
    /// Create the string
    /// </summary>
    protected void btnCreate_Click(object sender, EventArgs e)
    {
        string key = QueryHelper.GetString("stringKey", "").Trim().Replace("'", "''");

        // Create the key
        ResourceStringInfo rsi = SqlResourceManager.GetResourceStringInfo(key);

        if (rsi == null)
        {
            // Create the key
            rsi = new ResourceStringInfo();
            rsi.StringKey = key;

            rsi.UICultureCode = CultureHelper.DefaultUICulture;
            rsi.TranslationText = key;

            SqlResourceManager.SetResourceStringInfo(rsi);

            URLHelper.Redirect(URLHelper.CurrentURL);
        }
    }
コード例 #15
0
    /// <summary>
    /// Create the string
    /// </summary>
    protected void btnCreate_Click(object sender, EventArgs e)
    {
        string key = QueryHelper.GetString("stringKey", "").Trim().Replace("'", "''");

        // Create the key
        ResourceStringInfo rsi = SqlResourceManager.GetResourceStringInfo(key);

        if (rsi == null)
        {
            // Create the key
            rsi           = new ResourceStringInfo();
            rsi.StringKey = key;

            rsi.UICultureCode   = CultureHelper.DefaultUICulture;
            rsi.TranslationText = key;

            SqlResourceManager.SetResourceStringInfo(rsi);

            URLHelper.Redirect(URLHelper.CurrentURL);
        }
    }
コード例 #16
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;
        }
    }
コード例 #17
0
    /// <summary>
    /// Handles the UniGrid's OnExternalDataBound event.
    /// </summary>
    protected object UniGridStrings_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerCSafe())
        {
        case "edititem":
            ImageButton ib = sender as ImageButton;
            if (ib != null)
            {
                GridViewRow gvr = parameter as GridViewRow;
                if (gvr != null)
                {
                    DataView dv = gvr.DataItem as DataView;
                    if (dv != null)
                    {
                        if (ui != null)
                        {
                            ResourceStringInfo ri = SqlResourceManager.GetResourceStringInfo(ValidationHelper.GetString(dv[0], ""), ui.UICultureCode);
                            if (ri != null)
                            {
                                ib.OnClientClick = String.Format("location.href='Edit.aspx?stringid={0}&uicultureid={1}'; return false;", ri.StringId, ui.UICultureID);
                            }
                        }
                    }
                }
            }
            break;

        case "stringiscustom":
            return(UniGridFunctions.ColoredSpanYesNo(parameter));

        case "culturetext":
        case "defaulttext":
            return(MacroResolver.RemoveSecurityParameters(parameter.ToString(), true, null));
        }

        return(parameter);
    }
コード例 #18
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  = ResourceStringInfo.Provider.Get(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;
                    ResourceStringInfo.Provider.Set(ri);
                }
            }

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

            // Key not found in DB
            if (ri == null)
            {
                // Try to find it in .resx file
                FileResourceManager resourceManager = LocalizationHelper.GetFileManager(cultureCode);
                if (resourceManager != null)
                {
                    string translation = resourceManager.GetString(key);
                    if (!string.IsNullOrEmpty(translation))
                    {
                        if (!SystemContext.DevelopmentMode)
                        {
                            // Save the key in DB
                            ri = new ResourceStringInfo
                            {
                                StringKey       = key,
                                StringIsCustom  = true,
                                CultureCode     = cultureCode,
                                TranslationText = translation
                            };
                            ResourceStringInfo.Provider.Set(ri);
                        }

                        string script = ScriptHelper.GetScript("CloseDialog(); wopener.SetResource('" + hdnValue + "', '" + key + "', '" + textbox + "', " + ScriptHelper.GetString(translation) + ", '" + btnLocalizeField + "', '" + btnLocalizeString + "', '" + btnRemoveLocalization + "', '" + localizedInputContainer + "');");
                        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;
                    var    localizedText = ScriptHelper.GetString(GetString(key), true, true);
                    string script        = ScriptHelper.GetScript($"wopener.SetResource('{hdnValue}', '{key}', '{textbox}', {localizedText}, '{btnLocalizeField}', '{btnLocalizeString}', '{btnRemoveLocalization}', '{localizedInputContainer}'); CloseDialog();");
                    ScriptHelper.RegisterStartupScript(this, typeof(string), "localizeField", script);
                }
            }
        }
    }
コード例 #19
0
    /// <summary>
    /// Button localize click. In AutomaticMode available only.
    /// </summary>
    void btnLocalize_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(textbox.Text.Trim()))
        {
            // Get maximum length of resource key
            int    maxKeyLength = MAX_KEY_LENGTH;
            string prefix       = ResourceKeyPrefix;
            if (SettingsKeyProvider.DevelopmentMode && String.IsNullOrEmpty(ResourceKeyPrefix))
            {
                prefix = PREFIX;
            }

            if (!String.IsNullOrEmpty(prefix))
            {
                maxKeyLength -= prefix.Length;
            }

            // Initialize resource string
            string newResource = TextHelper.LimitLength(ValidationHelper.GetCodeName(textbox.Text.Trim()), maxKeyLength, String.Empty, true);

            int i = 0;
            if (!newResource.StartsWithCSafe(prefix))
            {
                hdnValue.Value = prefix + newResource;
            }
            else
            {
                hdnValue.Value = newResource;
            }
            // If key exists then create new one with number as a suffix
            while (SqlResourceManager.GetResourceStringInfo(hdnValue.Value) != null)
            {
                // If newly created resource key is longer then allowed length then trim end by one character
                if ((prefix.Length + newResource.Length + ++i) > MAX_KEY_LENGTH)
                {
                    newResource = newResource.Substring(0, newResource.Length - 1);
                }

                if (!newResource.StartsWithCSafe(prefix))
                {
                    hdnValue.Value = prefix + newResource + i;
                }
                else
                {
                    hdnValue.Value = newResource + i;
                }
            }

            // Check if current user's culture exists
            UICultureInfo uiCulture   = null;
            string        cultureCode = CultureHelper.PreferredUICulture;
            try
            {
                uiCulture = UICultureInfoProvider.GetUICultureInfo(CultureHelper.PreferredUICulture);
            }
            // Use default UI culture
            catch
            {
                cultureCode = CultureHelper.DefaultUICulture;
            }
            // Use default UI culture
            if (uiCulture == null)
            {
                cultureCode = CultureHelper.DefaultUICulture;
            }

            // Save ResourceString
            ResourceStringInfo ri = new ResourceStringInfo();
            ri.StringKey       = hdnValue.Value;
            ri.UICultureCode   = cultureCode;
            ri.TranslationText = textbox.Text;
            ri.StringIsCustom  = !SettingsKeyProvider.DevelopmentMode;
            SqlResourceManager.SetResourceStringInfo(ri);

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

            // Set macro settings
            Value = MACRO_START + hdnValue.Value + MACRO_END;
            Reload();
        }
        else
        {
            lblError.Visible        = true;
            lblError.ResourceString = "localize.entertext";
        }
    }
コード例 #20
0
    /// <summary>
    /// Button OK clicked.
    /// </summary>
    void btnOk_Click(object sender, EventArgs e)
    {
        // Check permissions
        if (CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Localization", "LocalizeStrings"))
        {
            string             key = null;
            ResourceStringInfo ri  = null;

            // Check if current user's culture exists
            UICultureInfo uiCulture   = null;
            string        cultureCode = CultureHelper.PreferredUICulture;
            try
            {
                uiCulture = UICultureInfoProvider.GetUICultureInfo(CultureHelper.PreferredUICulture);
            }
            // Use default UI culture
            catch
            {
                cultureCode = CultureHelper.DefaultUICulture;
            }
            // Use default UI culture
            if (uiCulture == null)
            {
                cultureCode = CultureHelper.DefaultUICulture;
            }

            // Creating new resource string
            if (lstExistingOrNew.SelectedIndex == 0)
            {
                if (SettingsKeyProvider.DevelopmentMode && String.IsNullOrEmpty(resourceKeyPrefix))
                {
                    key = txtNewResource.Text.Trim();
                }
                else
                {
                    key = resourceKeyPrefix + txtNewResource.Text.Trim();
                }
                ri = SqlResourceManager.GetResourceStringInfo(key);

                // Resource string doesn't exists yet
                if (ri == null)
                {
                    lblError.Text = new Validator().NotEmpty(key, GetString("Administration-UICulture_String_New.EmptyKey")).IsCodeName(key, GetString("Administration-UICulture_String_New.InvalidCodeName")).Result;
                    if (!String.IsNullOrEmpty(lblError.Text))
                    {
                        lblError.Visible = true;
                    }
                    else
                    {
                        // Save ResourceString
                        ri                 = new ResourceStringInfo();
                        ri.StringKey       = key;
                        ri.UICultureCode   = cultureCode;
                        ri.TranslationText = plainText;
                        ri.StringIsCustom  = !SettingsKeyProvider.DevelopmentMode;
                        SqlResourceManager.SetResourceStringInfo(ri);

                        ScriptHelper.RegisterStartupScript(this, typeof(string), "localizeField", ScriptHelper.GetScript("wopener.SetResourceAndOpen('" + hdnValue + "', '" + key + "', '" + textbox + "', " + ScriptHelper.GetString(plainText) + ", '" + hdnIsMacro + "', '" + btnLocalizeField + "', '" + btnLocalizeString + "', '" + btnRemoveLocalization + "', window);"));
                    }
                }
                // If resource string already exists with different translation
                else
                {
                    lblError.Visible        = true;
                    lblError.ResourceString = "localize.alreadyexists";
                }
            }
            // Using existing resource string
            else
            {
                key = ValidationHelper.GetString(resourceSelector.Value, String.Empty).Trim();
                ri  = SqlResourceManager.GetResourceStringInfo(key);

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

                            ScriptHelper.RegisterStartupScript(this, typeof(string), "localizeField", ScriptHelper.GetScript("wopener.SetResource('" + hdnValue + "', '" + key + "', '" + textbox + "', " + ScriptHelper.GetString(translation) + ", '" + hdnIsMacro + "', '" + btnLocalizeField + "', '" + btnLocalizeString + "', '" + btnRemoveLocalization + "', window);"));
                        }
                        else
                        {
                            lblError.Visible        = true;
                            lblError.ResourceString = "localize.doesntexist";
                        }
                    }
                    else
                    {
                        lblError.Visible        = true;
                        lblError.ResourceString = "localize.doesntexist";
                    }
                }
                // Send to parent window selected resource key
                else
                {
                    string existingTranslation = GetString(key);
                    ScriptHelper.RegisterStartupScript(this, typeof(string), "localizeField", ScriptHelper.GetScript("wopener.SetResource('" + hdnValue + "', '" + key + "', '" + textbox + "', " + ScriptHelper.GetString(existingTranslation) + ", '" + hdnIsMacro + "', '" + btnLocalizeField + "', '" + btnLocalizeString + "', '" + btnRemoveLocalization + "', window);"));
                }
            }
        }
        else
        {
            lblError.ResourceString = "general.actiondenied";
            lblError.Visible        = true;
            pnlControls.Visible     = false;
        }
    }
コード例 #21
0
    /// <summary>
    /// Reloads data.
    /// </summary>
    protected void ReloadData()
    {
        if (!RequestHelper.IsPostBack())
        {
            string key = QueryHelper.GetString("stringKey", "").Trim().Replace("'", "''");;

            txtStringKey.Text = key;
            rsi = SqlResourceManager.GetResourceStringInfo(txtStringKey.Text);

            // Ensure the value if not found
            if (rsi == null)
            {
                string currentCulture = CultureHelper.PreferredUICulture;
                string defaultCulture = CultureHelper.DefaultUICulture;

                string value = ResHelper.GetString(key, defaultCulture, NOT_FOUND);
                if (value != NOT_FOUND)
                {
                    // Create the resource string with current culture value
                    rsi                 = new ResourceStringInfo();
                    rsi.StringKey       = key;
                    rsi.StringIsCustom  = true;
                    rsi.UICultureCode   = defaultCulture;
                    rsi.TranslationText = value;

                    SqlResourceManager.SetResourceStringInfo(rsi);

                    // Impor the current culture
                    if (!currentCulture.Equals(defaultCulture, StringComparison.InvariantCultureIgnoreCase))
                    {
                        rsi.UICultureCode   = currentCulture;
                        rsi.TranslationText = ResHelper.GetString(key, currentCulture);

                        SqlResourceManager.SetResourceStringInfo(rsi);
                    }
                }
            }
        }
        else
        {
            rsi = SqlResourceManager.GetResourceStringInfo(ValidationHelper.GetInteger(hdnID.Value, 0));
        }

        if (rsi != null)
        {
            if (!RequestHelper.IsPostBack())
            {
                chkIsCustom.Checked = rsi.StringIsCustom;
                hdnID.Value         = rsi.StringId.ToString();
            }

            // Get the cultures
            DataSet result         = GetData();
            DataSet defaultCulture = GetDefaultCulture(result);

            if (!DataHelper.DataSourceIsEmpty(result) || !DataHelper.DataSourceIsEmpty(defaultCulture))
            {
                int                   rowCount  = 1;
                TableRow              row       = null;
                TableCell             cellText  = null;
                TableCell             cellValue = null;
                FormEngineUserControl control   = null;
                Control               c         = null;

                // Add default culture translation as a first record
                if (!DataHelper.DataSourceIsEmpty(defaultCulture))
                {
                    AddRow(true, ref rowCount, row, cellText, cellValue, control, c, defaultCulture.Tables[0].Rows[0]);
                }

                // Add all cultures
                if (!DataHelper.DataSourceIsEmpty(result))
                {
                    foreach (DataRow dr in result.Tables[0].Rows)
                    {
                        AddRow(false, ref rowCount, row, cellText, cellValue, control, c, dr);
                    }
                }

                // Display filter for large number of results
                if ((rowCount > 6) || (txtFilter.Text.Trim().Length != 0))
                {
                    pnlHeaderCell.Visible = true;
                    lblHeaderCell.Visible = false;
                }
                else
                {
                    pnlHeaderCell.Visible = false;
                    lblHeaderCell.Visible = true;
                }
            }
            else
            {
                if (txtFilter.Text.Trim().Length != 0)
                {
                    pnlHeaderCell.Visible = true;
                    lblHeaderCell.Visible = false;
                }
                else
                {
                    pnlHeaderCell.Visible = false;
                    lblHeaderCell.Visible = true;
                }
            }
        }
        else
        {
            lblError.ResourceString = "resourcestring.notfound";
            lblError.Visible        = true;
            pnlControls.Visible     = false;
            btnApply.Enabled        = false;
            btnOk.Enabled           = false;
        }
    }
コード例 #22
0
    /// <summary>
    /// Saves resource translations and returns TRUE if save was successful. Returns FALSE if any error ocurred.
    /// </summary>
    private void Save()
    {
        // Check permissions
        if (CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Localization", "LocalizeStrings"))
        {
            // Change resource key
            string key = txtStringKey.Text.Trim();
            if (key != rsi.StringKey)
            {
                // Validate the key
                string result = new Validator().NotEmpty(key, rfvKey.ErrorMessage).IsCodeName(key, GetString("Administration-UICulture_String_New.InvalidCodeName")).Result;
                if (String.IsNullOrEmpty(result))
                {
                    ResourceStringInfo riNew = SqlResourceManager.GetResourceStringInfo(txtStringKey.Text.Trim());

                    // Check if string with given key is not already defined
                    if ((riNew == null) || (rsi.StringId == riNew.StringId))
                    {
                        // Log deletion of old string
                        if ((!String.Equals(key, rsi.StringKey, StringComparison.OrdinalIgnoreCase)) &&
                            (rsi.Generalized.LogSynchronization == SynchronizationTypeEnum.LogSynchronization))
                        {
                            SynchronizationHelper.LogObjectChange(rsi, TaskTypeEnum.DeleteObject);
                        }

                        rsi.StringKey = key;
                        SqlResourceManager.SetResourceStringInfo(rsi);
                    }
                    // New resource key collides with already existing resource key
                    else
                    {
                        lblError.Text    = String.Format(GetString("Administration-UICulture_String_New.StringExists"), key);
                        lblError.Visible = true;
                    }
                }
                // New resource string key is not code name
                else
                {
                    lblError.Visible = true;
                    lblError.Text    = result;
                }
            }

            string existingTranslation    = null;
            string newTranslation         = null;
            FormEngineUserControl control = null;

            // Go through all cultures
            foreach (string cultureCode in translations.Keys)
            {
                // Check if translation in given culture exists
                existingTranslation = SqlResourceManager.GetStringStrictly(txtStringKey.Text, cultureCode);
                // Get control for given culture
                control = (FormEngineUserControl)translations[cultureCode];

                if (control != null)
                {
                    // Translation is not already created
                    if (String.IsNullOrEmpty(existingTranslation))
                    {
                        // Get new translation
                        newTranslation = ValidationHelper.GetString(control.Value, String.Empty).Trim();

                        // Create new translation in given culture
                        if (!String.IsNullOrEmpty(newTranslation))
                        {
                            UpdateString(cultureCode, newTranslation);
                        }
                        // Translation of default culture must exist
                        else if (cultureCode == CultureHelper.DefaultUICulture)
                        {
                            lblError.Text    = String.Format(ResHelper.GetString("localizable.deletedefault"), defaultCultureName);
                            lblError.Visible = true;
                        }
                    }
                    // Existing translation is being updated
                    else
                    {
                        newTranslation = ValidationHelper.GetString(control.Value, String.Empty).Trim();

                        // Delete translation if new translation is empty
                        if (String.IsNullOrEmpty(newTranslation))
                        {
                            // Delete translation
                            if (cultureCode != CultureHelper.DefaultUICulture)
                            {
                                SqlResourceManager.DeleteResourceStringInfo(txtStringKey.Text, cultureCode);
                            }
                            // Translation in default culture cannot be deleted or set to empty in Localizable textbox
                            else
                            {
                                lblError.Text    = String.Format(ResHelper.GetString("localizable.deletedefault"), defaultCultureName);
                                lblError.Visible = true;
                            }
                        }
                        // Update translation if new translation is not empty
                        else
                        {
                            UpdateString(cultureCode, newTranslation);
                        }
                    }

                    // Set updated translation in current culture
                    if (cultureCode == CultureHelper.PreferredUICulture)
                    {
                        defaultTranslation = newTranslation;
                    }
                }
            }
        }
        // Current user is not global admin
        else
        {
            lblError.ResourceString = "general.actiondenied";
            lblError.Visible        = true;
            pnlControls.Visible     = false;
        }
    }
コード例 #23
0
    /// <summary>
    /// Initializes Master Page.
    /// </summary>
    protected void InitializeMasterPage(ResourceStringInfo ri, bool defaultTextVisible)
    {
        // Initializes page breadcrumbs
        tabs[0, 0] = GetString("UICultures_Strings.Strings");
        tabs[0, 1] = ResolveUrl("List.aspx?UIcultureID=" + uiCultureID);
        tabs[1, 0] = ri.StringKey;
        CurrentMaster.Title.Breadcrumbs = tabs;

        // Set actions
        string[,] actions = new string[1,8];
        actions[0, 0] = "HyperLink";
        actions[0, 1] = GetString("Development-UICulture_Strings_List.NewString");
        actions[0, 3] = ResolveUrl("New.aspx?uicultureid=" + uiCultureID);
        actions[0, 5] = GetImageUrl("CMSModules/CMS_UICultures/addstring.png");

        CurrentMaster.HeaderActions.Actions = actions;

        CurrentMaster.Title.HelpName = "helpTopic";
        CurrentMaster.Title.HelpTopicName = defaultTextVisible ? "newedit_string" : "DefaultNewEdit_string";
    }
コード例 #24
0
    /// <summary>
    /// Button localize click. In AutomaticMode available only.
    /// </summary>
    void btnLocalize_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(textbox.Text.Trim()))
        {
            // Get maximum length of resource key
            int maxKeyLength = MAX_KEY_LENGTH;
            string prefix = ResourceKeyPrefix;
            if (SettingsKeyProvider.DevelopmentMode && String.IsNullOrEmpty(ResourceKeyPrefix))
            {
                prefix = PREFIX;
            }

            if (!String.IsNullOrEmpty(prefix))
            {
                maxKeyLength -= prefix.Length;
            }

            // Initialize resource string
            string newResource = TextHelper.LimitLength(ValidationHelper.GetCodeName(textbox.Text.Trim()), maxKeyLength, String.Empty, true);

            int i = 0;
            if (!newResource.StartsWith(prefix))
            {
                hdnValue.Value = prefix + newResource;
            }
            else
            {
                hdnValue.Value = newResource;
            }
            // If key exists then create new one with number as a suffix
            while (SqlResourceManager.GetResourceStringInfo(hdnValue.Value) != null)
            {
                // If newly created resource key is longer then allowed length then trim end by one character
                if ((prefix.Length + newResource.Length + ++i) > MAX_KEY_LENGTH)
                {
                    newResource = newResource.Substring(0, newResource.Length - 1);
                }

                if (!newResource.StartsWith(prefix))
                {
                    hdnValue.Value = prefix + newResource + i;
                }
                else
                {
                    hdnValue.Value = newResource + i;
                }
            }

            // Check if current user's culture exists
            UICultureInfo uiCulture = null;
            string cultureCode = CultureHelper.PreferredUICulture;
            try
            {
                uiCulture = UICultureInfoProvider.GetUICultureInfo(CultureHelper.PreferredUICulture);
            }
            // Use default UI culture
            catch
            {
                cultureCode = CultureHelper.DefaultUICulture;
            }
            // Use default UI culture
            if (uiCulture == null)
            {
                cultureCode = CultureHelper.DefaultUICulture;
            }

            // Save ResourceString
            ResourceStringInfo ri = new ResourceStringInfo();
            ri.StringKey = hdnValue.Value;
            ri.UICultureCode = cultureCode;
            ri.TranslationText = textbox.Text;
            ri.StringIsCustom = !SettingsKeyProvider.DevelopmentMode;
            SqlResourceManager.SetResourceStringInfo(ri);

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

            // Set macro settings
            this.Value = MACRO_START + hdnValue.Value + MACRO_END;
            Reload();
        }
        else
        {
            lblError.Visible = true;
            lblError.ResourceString = "localize.entertext";
        }
    }
コード例 #25
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);
    }
コード例 #26
0
    /// <summary>
    /// Button OK clicked.
    /// </summary>
    void btnOk_Click(object sender, EventArgs e)
    {
        // Check permissions
        if (CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Localization", "LocalizeStrings"))
        {
            string key = null;
            ResourceStringInfo ri = null;

            // Check if current user's culture exists
            UICultureInfo uiCulture = null;
            string cultureCode = CultureHelper.PreferredUICulture;
            try
            {
                uiCulture = UICultureInfoProvider.GetUICultureInfo(CultureHelper.PreferredUICulture);
            }
            // Use default UI culture
            catch
            {
                cultureCode = CultureHelper.DefaultUICulture;
            }
            // Use default UI culture
            if (uiCulture == null)
            {
                cultureCode = CultureHelper.DefaultUICulture;
            }

            // Creating new resource string
            if (lstExistingOrNew.SelectedIndex == 0)
            {
                if (SettingsKeyProvider.DevelopmentMode && String.IsNullOrEmpty(resourceKeyPrefix))
                {
                    key = txtNewResource.Text.Trim();
                }
                else
                {
                    key = resourceKeyPrefix + txtNewResource.Text.Trim();
                }
                ri = SqlResourceManager.GetResourceStringInfo(key);

                // Resource string doesn't exists yet
                if (ri == null)
                {
                    lblError.Text = new Validator().NotEmpty(key, GetString("Administration-UICulture_String_New.EmptyKey")).IsCodeName(key, GetString("Administration-UICulture_String_New.InvalidCodeName")).Result;
                    if (!String.IsNullOrEmpty(lblError.Text))
                    {
                        lblError.Visible = true;
                    }
                    else
                    {
                        // Save ResourceString
                        ri = new ResourceStringInfo();
                        ri.StringKey = key;
                        ri.UICultureCode = cultureCode;
                        ri.TranslationText = plainText;
                        ri.StringIsCustom = !SettingsKeyProvider.DevelopmentMode;
                        SqlResourceManager.SetResourceStringInfo(ri);

                        ScriptHelper.RegisterStartupScript(this, typeof(string), "localizeField", ScriptHelper.GetScript("wopener.SetResourceAndOpen('" + hdnValue + "', '" + key + "', '" + textbox + "', " + ScriptHelper.GetString(plainText) + ", '" + hdnIsMacro + "', '" + btnLocalizeField + "', '" + btnLocalizeString + "', '" + btnRemoveLocalization + "', window);"));
                    }
                }
                // If resource string already exists with different translation
                else
                {
                    lblError.Visible = true;
                    lblError.ResourceString = "localize.alreadyexists";
                }
            }
            // Using existing resource string
            else
            {
                key = ValidationHelper.GetString(resourceSelector.Value, String.Empty).Trim();
                ri = SqlResourceManager.GetResourceStringInfo(key);

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

                            ScriptHelper.RegisterStartupScript(this, typeof(string), "localizeField", ScriptHelper.GetScript("wopener.SetResource('" + hdnValue + "', '" + key + "', '" + textbox + "', " + ScriptHelper.GetString(translation) + ", '" + hdnIsMacro + "', '" + btnLocalizeField + "', '" + btnLocalizeString + "', '" + btnRemoveLocalization + "', window);"));
                        }
                        else
                        {
                            lblError.Visible = true;
                            lblError.ResourceString = "localize.doesntexist";
                        }
                    }
                    else
                    {
                        lblError.Visible = true;
                        lblError.ResourceString = "localize.doesntexist";
                    }
                }
                // Send to parent window selected resource key
                else
                {
                    string existingTranslation = GetString(key);
                    ScriptHelper.RegisterStartupScript(this, typeof(string), "localizeField", ScriptHelper.GetScript("wopener.SetResource('" + hdnValue + "', '" + key + "', '" + textbox + "', " + ScriptHelper.GetString(existingTranslation) + ", '" + hdnIsMacro + "', '" + btnLocalizeField + "', '" + btnLocalizeString + "', '" + btnRemoveLocalization + "', window);"));
                }
            }
        }
        else
        {
            lblError.ResourceString = "general.actiondenied";
            lblError.Visible = true;
            pnlControls.Visible = false;
        }
    }
コード例 #27
0
ファイル: Edit.aspx.cs プロジェクト: tvelzy/RadstackMedia
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get parameters from query string
        GetParameters();

        if (saved)
        {
            ShowChangesSaved();
        }

        lblEnglishText.Text = string.Format(GetString("Administration-UICulture_String_New.EnglishText"), CultureHelper.DefaultUICulture);
        rfvKey.ErrorMessage = GetString("Administration-UICulture_String_New.EmptyKey");

        ResourceStringInfo ri = SqlResourceManager.GetResourceStringInfo(stringID, uiCultureID);

        EditedObject = ri;

        string defaultCulture = CultureHelper.DefaultUICulture;

        uic = UICultureInfoProvider.GetUICultureInfo(uiCultureID);
        if (uic.UICultureCode == defaultCulture)
        {
            // Default culture
            plcDefaultText.Visible = false;
            txtKey.Visible         = true;
            lblKeyEng.Visible      = false;

            if (!RequestHelper.IsPostBack())
            {
                txtKey.Text  = ri.StringKey;
                txtText.Text = SqlResourceManager.GetStringStrictly(ri.StringKey, CultureHelper.DefaultUICulture);
            }
        }
        else
        {
            // Other cultures
            plcDefaultText.Visible = true;
            txtKey.Visible         = false;
            rfvKey.Enabled         = false;
            lblKeyEng.Visible      = true;

            lblKeyEng.Text       = ri.StringKey;
            lblEnglishValue.Text = HTMLHelper.HTMLEncode(MacroResolver.RemoveSecurityParameters(SqlResourceManager.GetStringStrictly(ri.StringKey, CultureHelper.DefaultUICulture), true, null));

            if (!RequestHelper.IsPostBack())
            {
                txtKey.Text  = ri.StringKey;
                txtText.Text = SqlResourceManager.GetStringStrictly(ri.StringKey, uic.UICultureCode);
            }

            // Set default culture text to translate
            txtText.AllowTranslationServices  = true;
            txtText.TranslationSourceText     = ResHelper.GetString(ri.StringKey, defaultCulture);
            txtText.TranslationSourceLanguage = defaultCulture;
            txtText.TranslationTargetLanguage = uic.UICultureCode;
        }

        if (!DialogMode)
        {
            // Initialize master page
            InitializeMasterPage(ri, plcDefaultText.Visible);
        }
        else
        {
            txtKey.Enabled    = false;
            plcCustom.Visible = false;
        }

        if (!RequestHelper.IsPostBack() && (!DialogMode))
        {
            chkCustomString.Checked = ri.StringIsCustom;
        }
    }
コード例 #28
0
ファイル: Edit.aspx.cs プロジェクト: tvelzy/RadstackMedia
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // History back count
        BackCount++;
        string result = null;

        // Trim the key before save
        string key = txtKey.Text.Trim();

        // Validate the code name if default culture
        if (uic.UICultureCode == CultureHelper.DefaultUICulture)
        {
            result = new Validator()
                     .NotEmpty(key, rfvKey.ErrorMessage)
                     .IsCodeName(key, GetString("Administration-UICulture_String_New.InvalidCodeName"))
                     .Result;
        }

        if (!string.IsNullOrEmpty(result))
        {
            // Display error message
            ShowError(result);
            return;
        }

        // Update the string
        ResourceStringInfo ri = SqlResourceManager.GetResourceStringInfo(stringID, uiCultureID);

        if (ri != null)
        {
            // Check if string with given key is not already defined
            ResourceStringInfo existing = SqlResourceManager.GetResourceStringInfo(key);
            if ((existing == null) || (existing.StringId == ri.StringId))
            {
                ri.StringIsCustom  = chkCustomString.Checked;
                ri.UICultureCode   = uic.UICultureCode;
                ri.TranslationText = txtText.Text;

                if (txtKey.Visible)
                {
                    // If key changed, log deletion of old string
                    string newKey = key;

                    if ((!CMSString.Equals(ri.StringKey, newKey, true)) &&
                        (ri.Generalized.LogSynchronization == SynchronizationTypeEnum.LogSynchronization))
                    {
                        SynchronizationHelper.LogObjectChange(ri, TaskTypeEnum.DeleteObject);
                    }

                    ri.StringKey = key;
                }

                // Update key
                SqlResourceManager.SetResourceStringInfo(ri);

                ShowChangesSaved();

                tabs[1, 0] = ri.StringKey;
            }
            else
            {
                ShowError(string.Format(GetString("Administration-UICulture_String_New.StringExists"), key));
            }
        }
    }
コード例 #29
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();
    }
コード例 #30
0
    /// <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, 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.Trim();
            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";
        }
    }
コード例 #31
0
    /// <summary>
    /// Reloads data.
    /// </summary>
    protected void ReloadData()
    {
        if (!RequestHelper.IsPostBack())
        {
            string key = QueryHelper.GetString("stringKey", "").Trim().Replace("'", "''");;

            txtStringKey.Text = key;
            rsi = SqlResourceManager.GetResourceStringInfo(txtStringKey.Text);

            // Ensure the value if not found
            if (rsi == null)
            {
                string currentCulture = CultureHelper.PreferredUICulture;
                string defaultCulture = CultureHelper.DefaultUICulture;

                string value = ResHelper.GetString(key, defaultCulture, NOT_FOUND);
                if (value != NOT_FOUND)
                {
                    // Create the resource string with current culture value
                    rsi = new ResourceStringInfo();
                    rsi.StringKey = key;
                    rsi.StringIsCustom = true;
                    rsi.UICultureCode = defaultCulture;
                    rsi.TranslationText = value;

                    SqlResourceManager.SetResourceStringInfo(rsi);

                    // Impor the current culture
                    if (!currentCulture.Equals(defaultCulture, StringComparison.InvariantCultureIgnoreCase))
                    {
                        rsi.UICultureCode = currentCulture;
                        rsi.TranslationText = ResHelper.GetString(key, currentCulture);

                        SqlResourceManager.SetResourceStringInfo(rsi);
                    }
                }
            }
        }
        else
        {
            rsi = SqlResourceManager.GetResourceStringInfo(ValidationHelper.GetInteger(hdnID.Value, 0));
        }

        if (rsi != null)
        {
            if (!RequestHelper.IsPostBack())
            {
                chkIsCustom.Checked = rsi.StringIsCustom;
                hdnID.Value = rsi.StringId.ToString();
            }

            // Get the cultures
            DataSet result = GetData();
            DataSet defaultCulture = GetDefaultCulture(result);

            if (!DataHelper.DataSourceIsEmpty(result) || !DataHelper.DataSourceIsEmpty(defaultCulture))
            {
                int rowCount = 1;
                TableRow row = null;
                TableCell cellText = null;
                TableCell cellValue = null;
                FormEngineUserControl control = null;
                Control c = null;

                // Add default culture translation as a first record
                if (!DataHelper.DataSourceIsEmpty(defaultCulture))
                {
                    AddRow(true, ref rowCount, row, cellText, cellValue, control, c, defaultCulture.Tables[0].Rows[0]);
                }

                // Add all cultures
                if (!DataHelper.DataSourceIsEmpty(result))
                {
                    foreach (DataRow dr in result.Tables[0].Rows)
                    {
                        AddRow(false, ref rowCount, row, cellText, cellValue, control, c, dr);
                    }
                }

                // Display filter for large number of results
                if ((rowCount > 6) || (txtFilter.Text.Trim().Length != 0))
                {
                    pnlHeaderCell.Visible = true;
                    lblHeaderCell.Visible = false;
                }
                else
                {
                    pnlHeaderCell.Visible = false;
                    lblHeaderCell.Visible = true;
                }
            }
            else
            {
                if (txtFilter.Text.Trim().Length != 0)
                {
                    pnlHeaderCell.Visible = true;
                    lblHeaderCell.Visible = false;
                }
                else
                {
                    pnlHeaderCell.Visible = false;
                    lblHeaderCell.Visible = true;
                }
            }
        }
        else
        {
            lblError.ResourceString = "resourcestring.notfound";
            lblError.Visible = true;
            pnlControls.Visible = false;
            btnApply.Enabled = false;
            btnOk.Enabled = false;
        }
    }
コード例 #32
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 + "', '" + key + "', '" + 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);
                }

            }
        }
    }