예제 #1
0
        public void TesCultureInfoProvider_ReturnsCurrentCulture()
        {
            var cultureInfoProvider = new CultureInfoProvider();
            var cultureInfo         = cultureInfoProvider.GetCultureInfo();

            Assert.AreEqual(System.Globalization.CultureInfo.CurrentCulture, cultureInfo);
        }
    /// <summary>
    /// Reloads the data in the selector.
    /// </summary>
    public void ReloadData()
    {
        CultureInfo ui;

        try
        {
            ui = CultureInfoProvider.GetCultureInfo(MembershipContext.AuthenticatedUser.PreferredUICultureCode);
        }
        catch
        {
            ui = CultureInfoProvider.GetCultureInfo(CultureHelper.DefaultUICultureCode);
        }
        if (ui != null)
        {
            uniSelector.WhereCondition    = SqlHelper.AddWhereCondition(uniSelector.WhereCondition, "CultureID = " + ui.CultureID);
            uniSelector.ReturnColumnName  = "StringKey";
            uniSelector.AdditionalColumns = "StringKey, TranslationText";
            uniSelector.DialogGridName    = "~/CMSFormControls/Selectors/LocalizableTextBox/ResourceStringSelector.xml";
            uniSelector.IsLiveSite        = IsLiveSite;
            uniSelector.Reload(false);
            uniSelector.DialogWindowWidth    = 850;
            uniSelector.ResourcePrefix       = "resourcestring";
            uniSelector.UseDefaultNameFilter = false;
        }
    }
예제 #3
0
    /// <summary>
    /// Deletes the workflow scope(s) and culture assignments used for this example. Called when the "Delete objects" button is pressed.
    /// Expects the "CreateExampleObjects" method to be run first.
    /// </summary>
    private bool DeleteObjects()
    {
        CultureInfo culture = CultureInfoProvider.GetCultureInfo("de-de");

        // Remove the example culture from the site
        CultureSiteInfoProvider.RemoveCultureFromSite(culture.CultureID, CMSContext.CurrentSiteID);

        // Prepare parameters
        string where = "ScopeStartingPath LIKE '/API-Example%'";
        string orderBy = null;
        int    topN    = 0;
        string columns = null;

        DataSet scopes = WorkflowScopeInfoProvider.GetWorkflowScopes(where, orderBy, topN, columns);

        if (!DataHelper.DataSourceIsEmpty(scopes))
        {
            // Loop through all the scopes in case more identical scopes were accidentally created
            foreach (DataRow scopeRow in scopes.Tables[0].Rows)
            {
                // Create scope info object
                WorkflowScopeInfo scope = new WorkflowScopeInfo(scopeRow);

                // Delete the scope
                scope.Delete();
            }

            return(true);
        }

        return(false);
    }
예제 #4
0
    /// <summary>
    /// Creates workflow scope. Called when the "Create scope" button is pressed.
    /// Expects the "CreateWorkflow" method to be run first.
    /// </summary>
    private bool CreateWorkflowScope()
    {
        // Get the workflow
        WorkflowInfo workflow = WorkflowInfoProvider.GetWorkflowInfo("MyNewWorkflow");

        if (workflow != null)
        {
            // Create new workflow scope object
            WorkflowScopeInfo newScope = new WorkflowScopeInfo();

            // Get the site default culture from settings
            string      cultureCode = SettingsKeyInfoProvider.GetStringValue(SiteContext.CurrentSiteName + ".CMSDefaultCultureCode");
            CultureInfo culture     = CultureInfoProvider.GetCultureInfo(cultureCode);

            // Get root document type class ID
            int classID = DataClassInfoProvider.GetDataClassInfo("CMS.Root").ClassID;

            // Set the properties
            newScope.ScopeStartingPath = "/";
            newScope.ScopeCultureID    = culture.CultureID;
            newScope.ScopeClassID      = classID;

            newScope.ScopeWorkflowID = workflow.WorkflowID;
            newScope.ScopeSiteID     = SiteContext.CurrentSiteID;

            // Save the workflow scope
            WorkflowScopeInfoProvider.SetWorkflowScopeInfo(newScope);

            return(true);
        }

        return(false);
    }
    /// <summary>
    /// Page load.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        SiteInfo si = EditedObject as SiteInfo;

        if (si == null)
        {
            return;
        }

        CultureInfo ci             = CultureInfoProvider.GetCultureInfo(CultureHelper.GetDefaultCultureCode(si.SiteName));
        string      currentCulture = ci.CultureCode;

        if (!RequestHelper.IsPostBack())
        {
            txtCulture.Text = ci.CultureName;
        }

        // Set the culture textbox readonly
        txtCulture.Attributes.Add("readonly", "readonly");

        btnChange.Text          = GetString("general.change");
        btnChange.OnClientClick = "OpenCultureChanger('" + si.SiteID + "','" + currentCulture + "'); return false;";

        ltlScript.Text = ScriptHelper.GetScript(@"
var pageChangeUrl='" + ResolveUrl("~/CMSModules/Sites/Pages/CultureChange.aspx") + @"'; 
function ChangeCulture(documentChanged) { 
    var hiddenElem = document.getElementById('" + hdnDocumentsChangeChecked.ClientID + @"');
    hiddenElem.value = documentChanged;
    " + Page.ClientScript.GetPostBackEventReference(btnHidden, String.Empty) + @"
} 
");
    }
예제 #6
0
    /// <summary>
    /// Handle OnExternalDataBound event of the grid.
    /// </summary>
    /// <param name="sender">Sender object</param>
    /// <param name="sourceName">Event source name</param>
    /// <param name="parameter">Event parameter</param>
    /// <returns></returns>
    private object OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerCSafe())
        {
        case "sitedefaultvisitorculture":

            // Get visitor culture
            string defaultCulture = parameter as string;

            // If not set it is Automatic
            if (String.IsNullOrEmpty(defaultCulture))
            {
                return(ResHelper.GetString("Site_Edit.Automatic"));
            }
            else
            {
                CultureInfo ci = CultureInfoProvider.GetCultureInfo(defaultCulture);
                if (ci != null)
                {
                    return(ci.CultureName);
                }
            }

            break;
        }

        return(String.Empty);
    }
예제 #7
0
    protected object UniGridWorkflowScopes_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLower())
        {
        case "classdisplayname":
            string docType = ValidationHelper.GetString(parameter, "");
            if (docType == "")
            {
                return(GetString("general.selectall"));
            }
            return(docType);

        case "scopecultureid":
            int cultureId = ValidationHelper.GetInteger(parameter, 0);
            if (cultureId > 0)
            {
                return(CultureInfoProvider.GetCultureInfo(cultureId).CultureName);
            }
            else
            {
                return(GetString("general.selectall"));
            }

        default:
            return(parameter);
        }
    }
예제 #8
0
    protected object UniGridAliases_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLower())
        {
        case "sitedefaultvisitorculture":

            // Get visitor culture
            string defaultCulture = DataHelper.GetDataRowViewValue((DataRowView)parameter, "SiteDefaultVisitorCulture") as string;

            // If not set it is Automatic
            if (String.IsNullOrEmpty(defaultCulture))
            {
                return(GetString("Site_Edit.Automatic"));
            }
            else
            {
                CultureInfo ci = CultureInfoProvider.GetCultureInfo(defaultCulture);
                if (ci != null)
                {
                    return(ci.CultureName);
                }
            }

            break;
        }

        return(String.Empty);
    }
    private void SaveTranslations()
    {
        foreach (string cultureCode in mTranslations.Keys)
        {
            string translation    = mTranslations[cultureCode.ToLowerCSafe()].Text.Trim();
            int    cultureId      = CultureInfoProvider.GetCultureInfo(cultureCode).CultureID;
            var    resTranslation = ResourceTranslationInfoProvider.GetResourceTranslationInfo(mResourceStringInfo.StringID, cultureId);

            // Save translation only if not empty and if the same translation does not exist in resource file
            if (String.IsNullOrEmpty(translation) || translation.EqualsCSafe(LocalizationHelper.GetFileString(mResourceStringInfo.StringKey, cultureCode, string.Empty, false)))
            {
                ResourceTranslationInfoProvider.DeleteResourceTranslationInfo(resTranslation);
            }
            else
            {
                if (resTranslation == null)
                {
                    resTranslation = new ResourceTranslationInfo();
                }

                resTranslation.TranslationStringID  = mResourceStringInfo.StringID;
                resTranslation.TranslationCultureID = cultureId;
                resTranslation.TranslationText      = translation;

                ResourceTranslationInfoProvider.SetResourceTranslationInfo(resTranslation);
            }
        }
    }
예제 #10
0
    protected void Page_Load(object sender, EventArgs e)
    {
        stringCodeName = QueryHelper.GetString("stringCodeName", String.Empty);
        cultureId      = QueryHelper.GetInteger("cultureId", 0);

        // Validate culture ID
        if (cultureId <= 0)
        {
            ShowError(GetString("general.invalidcultureid"));
            return;
        }

        if (QueryHelper.GetBoolean("saved", false))
        {
            ShowChangesSaved();
        }

        // Init new header action
        HeaderAction action = new HeaderAction
        {
            Text        = GetString("culture.newstring"),
            RedirectUrl = "~/CMSModules/SystemDevelopment/Development/Resources/UICulture_StringsDefault_New.aspx?cultureId=" + cultureId,
        };

        CurrentMaster.HeaderActions.ActionsList.Add(action);

        codeNameBreadcrumbItem = new BreadcrumbItem
        {
            Text = stringCodeName.ToLowerCSafe(),
        };
        PageBreadcrumbs.AddBreadcrumb(codeNameBreadcrumbItem);

        // Ensure breadcrumbs suffix
        UIHelper.SetBreadcrumbsSuffix(GetString("objecttype.cms_resourcestring"));

        // Initialize controls
        rfvKey.ErrorMessage = GetString("culture.enterakey");

        if (!RequestHelper.IsPostBack())
        {
            CultureInfo uic = CultureInfoProvider.GetCultureInfo(cultureId);

            if (uic != null)
            {
                string             cultureCode = uic.CultureCode;
                FileResourceEditor fre         = new FileResourceEditor(Server.MapPath(FileResourceManager.GetResFilename(cultureCode)), cultureCode);
                if (fre != null)
                {
                    txtKey.Text  = stringCodeName;
                    txtText.Text = fre.GetResourceString(stringCodeName, cultureCode);
                }
            }
            else
            {
                ShowError(GetString("general.invalidcultureid"));
            }
        }
    }
예제 #11
0
    protected void Page_Load(object sender, EventArgs e)
    {
        ScriptHelper.RegisterJQuery(Page);

        string currentSiteName = (SiteID != 0) ? SiteInfoProvider.GetSiteName(SiteID) : SiteContext.CurrentSiteName;
        var    cultures        = CultureSiteInfoProvider.GetSiteCultures(currentSiteName).Items;

        if (cultures.Count > 1)
        {
            string      defaultCulture = CultureHelper.GetDefaultCultureCode(currentSiteName);
            CultureInfo ci             = CultureInfoProvider.GetCultureInfo(SelectedCulture);

            imgLanguage.ImageUrl      = GetFlagIconUrl(SelectedCulture, "16x16");
            imgLanguage.AlternateText = imgLanguage.ToolTip = GetString(ci.CultureName);
            lblLanguageName.Text      = ci.CultureShortName;

            // Generate sub-menu only if more cultures to choose from
            StringBuilder sb = new StringBuilder();
            foreach (var culture in cultures)
            {
                string cultureCode = culture.CultureCode;
                string cultureName = culture.CultureName;

                if (CMSString.Compare(cultureCode, defaultCulture, true) == 0)
                {
                    cultureName += " " + GetString("general.defaultchoice");
                }

                string flagUrl = GetFlagIconUrl(cultureCode, "16x16");

                var click = String.Format("ChangeLanguage({0}); return false;", ScriptHelper.GetString(cultureCode));

                sb.AppendFormat("<li><a href=\"#\" onclick=\"{0}\"><img src=\"{1}\" alt=\"\" class=\"language-flag\"><span class=\"language-name\">{2}</span></a></li>", click, flagUrl, cultureName);
            }

            ltlLanguages.Text = sb.ToString();

            // Split view button
            if (DisplayCompare)
            {
                btnCompare.ToolTip = GetString("SplitMode.CompareLangVersions");
                btnCompare.Text    = GetString("SplitMode.Compare");
                if (UIContext.DisplaySplitMode)
                {
                    btnCompare.AddCssClass("active");
                }
                else
                {
                    btnCompare.RemoveCssClass("active");
                }
            }
        }
        else
        {
            // Hide language menu for one assigned culture on site
            Visible = false;
        }
    }
        /// <summary>
        /// This Repeater "Webpart" Relies on just a path that would be provided through the View's context.  Does not rely on passing
        /// the ViewBag like the NavigationByContext, but does then require the calling View to provide the properties, and if ever more
        /// properties are needed, would need to adjust both Controller and View alike.
        /// </summary>
        /// <returns></returns>
        public ActionResult NavigationByPath(string Path, string Culture, string SiteName)
        {
            // Build the actual Partial View's model from the data provided by the parent View
            ExampleMVCWebPartsSubNavs Model = new ExampleMVCWebPartsSubNavs();

            // Get the Sub Nav Items from the ExampleService
            Model.SubNavigation = _exampleService.GetSubNavFromAliasPath(Path, CultureInfoProvider.GetCultureInfo(Culture));
            return(View("Navigation", Model));
        }
 /// <summary>
 /// Cached helper to get the CultureInfo object for the given Culture code
 /// </summary>
 /// <param name="CultureCode">the Culture code (ex en-US)</param>
 /// <returns>The Culture Info</returns>
 public static CultureInfo GetCulture(string CultureCode)
 {
     return(CacheHelper.Cache <CultureInfo>(cs =>
     {
         var Culture = CultureInfoProvider.GetCultureInfo(CultureCode);
         cs.CacheDependency = CacheHelper.GetCacheDependency("cms.culture|byname|" + CultureCode);
         return Culture;
     }, new CacheSettings(1440, "GetCultureByName", CultureCode)));
 }
예제 #14
0
    /// <summary>
    /// Deletes culture. Called when the "Delete culture" button is pressed.
    /// Expects the CreateCulture method to be run first.
    /// </summary>
    private bool DeleteCulture()
    {
        // Get the culture
        CultureInfo deleteCulture = CultureInfoProvider.GetCultureInfo("MyNewCulture");

        // Delete the culture
        CultureInfoProvider.DeleteCultureInfo(deleteCulture);

        return(deleteCulture != null);
    }
예제 #15
0
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // History back count
        BackCount++;

        string newKey = txtKey.Text.Trim().ToLowerCSafe();
        string result = new Validator().NotEmpty(newKey, rfvKey.ErrorMessage).IsCodeName(newKey, GetString("culture.InvalidCodeName")).Result;

        if (String.IsNullOrEmpty(result))
        {
            CultureInfo uic = CultureInfoProvider.GetCultureInfo(cultureId);

            if (uic != null)
            {
                string cultureCode = uic.CultureCode;
                stringCodeName = stringCodeName.ToLowerCSafe();

                FileResourceManager frm            = LocalizationHelper.GetFileManager(cultureCode);
                FileResourceEditor  resourceEditor = new FileResourceEditor(Server.MapPath(FileResourceManager.GetResFilename(cultureCode)), cultureCode);

                try
                {
                    if ((frm != null) && (resourceEditor != null))
                    {
                        if (!stringCodeName.EqualsCSafe(newKey, StringComparison.InvariantCultureIgnoreCase))
                        {
                            frm.DeleteString(stringCodeName);
                            resourceEditor.DeleteResourceString(stringCodeName, cultureCode, true);
                        }

                        frm.SetString(newKey, txtText.Text);
                        resourceEditor.SetResourceString(newKey, txtText.Text, cultureCode);
                    }
                }
                catch (Exception ex)
                {
                    ShowError(GetString("general.saveerror"), ex.Message, null);
                    return;
                }

                ShowChangesSaved();

                codeNameBreadcrumbItem.Text = newKey;
            }
            else
            {
                ShowError(GetString("general.invalidcultureid"));
            }
        }
        else
        {
            ShowError(result);
        }
    }
예제 #16
0
        /// <inheritdoc/>
        public void RemoveSiteCulture(ISite site, string cultureCode)
        {
            // Gets the site and culture objects
            SiteInfo    siteToWork    = SiteInfoProvider.GetSiteInfo(site.SiteName);
            CultureInfo cultureToWork = CultureInfoProvider.GetCultureInfo(cultureCode);

            if ((siteToWork != null) && (cultureToWork != null))
            {
                // Removes the culture from the site
                CultureSiteInfoProvider.RemoveCultureFromSite(cultureToWork.CultureID, siteToWork.SiteID);
            }
        }
    /// <summary>
    /// Saves resource string and its translations. Returns true if the string is successfully saved.
    /// </summary>
    public bool Save()
    {
        if (!EnableTranslations)
        {
            return(false);
        }

        string resKey = ResourceStringKey;

        if (!ValidationHelper.IsCodeName(resKey))
        {
            ShowError(GetString("culture.invalidresstringkey"));
            return(false);
        }

        // Check if key is free for use (must be free or id must be same)
        if (!KeyIsFreeToUse(mResourceStringInfo.StringID, resKey))
        {
            base.ShowError(ResHelper.GetStringFormat("localizable.keyexists", resKey));
            return(false);
        }

        // Check if default translation is set if required
        if (DefaultTranslationRequired)
        {
            string defaultTranslation = mTranslations[CultureHelper.DefaultUICultureCode.ToLowerInvariant()].Text.Trim();
            string defaultCultureName = CultureInfoProvider.GetCultureInfo(CultureHelper.DefaultUICultureCode).CultureName;
            if (String.IsNullOrEmpty(defaultTranslation))
            {
                base.ShowError(ResHelper.GetStringFormat("localizable.deletedefault", defaultCultureName));
                return(false);
            }
        }

        // Log staging tasks synchronously
        using (new CMSActionContext {
            AllowAsyncActions = false
        })
        {
            SaveResourceStringInfo(resKey);
            EditedResourceStringKey = resKey;
            SaveTranslations();
        }

        ShowChangesSaved();

        if (!String.IsNullOrEmpty(RedirectUrlAfterSave))
        {
            RedirectToUrlAfterSave();
        }

        return(true);
    }
예제 #18
0
        /// <inheritdoc/>
        public void AddSiteCulture(ISite site, string cultureCode)
        {
            // Gets the site and culture objects
            SiteInfo    siteToWork    = SiteInfoProvider.GetSiteInfo(site.SiteName);
            CultureInfo cultureToWork = CultureInfoProvider.GetCultureInfo(cultureCode);

            if ((siteToWork != null) && (cultureToWork != null))
            {
                // Assigns the culture to the site
                CultureSiteInfoProvider.AddCultureToSite(cultureToWork.CultureID, siteToWork.SiteID);
            }
        }
    /// <summary>
    /// Removes cultures from edited site. Default culture is skipped and is not removed. Also cultures which
    /// are assigned to documents are not removed.
    /// </summary>
    /// <param name="cultureIds">Set of culture identifiers to delete.</param>
    /// <returns>Returns <c>true</c> if all cultures were successfully removed.</returns>
    private bool RemoveFromSite(IEnumerable <int> cultureIds)
    {
        bool allCulturesDeleted = true;
        bool changed            = false;
        var  defaultCultureCode = CultureHelper.GetDefaultCultureCode(siteInfo.SiteName);
        var  tree = new TreeProvider();

        // Remove all selected items from site
        foreach (int cultureId in cultureIds)
        {
            var culture = CultureInfoProvider.GetCultureInfo(cultureId);
            if (culture == null)
            {
                continue;
            }

            // Skip default culture deletion
            if (culture.CultureCode.EqualsCSafe(defaultCultureCode, true))
            {
                allCulturesDeleted = false;
                Control.AddError(String.Format(ResHelper.GetString("site_edit_cultures.errordeletedefaultculture"), HTMLHelper.HTMLEncode(culture.CultureName)) + '\n');
                continue;
            }

            var cultureDocumentsCount = tree.SelectNodes()
                                        .OnSite(siteInfo.SiteName)
                                        .CombineWithDefaultCulture(false)
                                        .Culture(culture.CultureCode)
                                        .Published(false)
                                        .Count;

            // Skip culture if any document translated to this culture
            if (cultureDocumentsCount > 0)
            {
                allCulturesDeleted = false;
                Control.AddError(String.Format(ResHelper.GetString("site_edit_cultures.errorremoveculturefromsite"), HTMLHelper.HTMLEncode(culture.CultureName)) + '\n');
                continue;
            }

            CultureSiteInfoProvider.RemoveCultureFromSite(culture.CultureCode, siteInfo.SiteName);
            changed = true;
        }

        if (changed)
        {
            Control.ShowChangesSaved();
        }

        return(allCulturesDeleted);
    }
예제 #20
0
    protected void Page_Load(object sender, EventArgs e)
    {
        gridStrings.OnAction += UniGridCultures_OnAction;

        CurrentMaster.DisplaySiteSelectorPanel = true;

        cultureSelector.OnSelectionChanged += cultureSelector_OnSelectionChanged;
        cultureSelector.DropDownSingleSelect.AutoPostBack = true;
        cultureSelector.OnListItemCreated += cultureSelector_OnListItemCreated;

        mCultureCode = QueryHelper.GetString("culturecode", CultureHelper.DefaultUICultureCode);
        mCultureInfo = CultureInfoProvider.GetCultureInfo(mCultureCode);

        if (mCultureInfo != null && mDefaultUICultureInfo != null)
        {
            QueryDataParameters parameters = new QueryDataParameters();
            parameters.Add("@Culture", mCultureInfo.CultureID);
            parameters.AddId("@DefaultCultureID", mDefaultUICultureInfo.CultureID);
            gridStrings.QueryParameters = parameters;

            string defaultTextCaption = String.Format(GetString("culture.defaultwithparameter"), CultureHelper.DefaultUICultureCode);
            gridStrings.GridColumns.Columns.Find(column => column.Source == "DefaultText").Caption = defaultTextCaption;

            if (CurrentCultureIsDefault)
            {
                // Set default translation column to full width
                gridStrings.GridColumns.Columns[2].Width = "100%";

                // Remove 'CultureText' column if current culture is default
                gridStrings.GridColumns.Columns.RemoveAt(1);
            }
            else
            {
                if (!LocalizationHelper.ResourceFileExistsForCulture(mCultureInfo.CultureCode))
                {
                    string url          = "http://devnet.kentico.com/download/localization-packs";
                    string downloadPage = String.Format(@"<a href=""{0}"" target=""_blank"" >{1}</a> ", url, HTMLHelper.HTMLEncode(url));
                    ShowInformation(String.Format(GetString("culture.downloadlocalization"), downloadPage));
                }
            }

            InitializeMasterPage();
        }
        else
        {
            gridStrings.StopProcessing = true;
            ShowError(String.Format(GetString("culture.doesntexist"), HTMLHelper.HTMLEncode(mCultureCode)));
        }
    }
예제 #21
0
        /// <summary>
        /// Provides step parameter formatter function for provided <paramref name="parameterInfo"/>.
        /// If <see cref="ParameterFormatterAttribute"/> is applied on <paramref name="parameterInfo"/>, it will be used to retrieve formatter function, otherwise the default one will be provided.
        /// The returned formatter function uses <see cref="CultureInfoProvider"/> to format parameters.
        /// </summary>
        /// <param name="parameterInfo"><see cref="ParameterInfo"/> object describing step or scenario method parameter.</param>
        /// <returns>Formatter function.</returns>
        /// <exception cref="InvalidOperationException">Throws when more than one <see cref="ParameterFormatterAttribute"/> is applied on <paramref name="parameterInfo"/>.</exception>

        public Func <object, string> GetParameterFormatter(ParameterInfo parameterInfo)
        {
            Func <object, string> defaultFormatter = value => string.Format(CultureInfoProvider.GetCultureInfo(), "{0}", value);
            var formatters = parameterInfo.GetCustomAttributes(typeof(ParameterFormatterAttribute), true)
                             .OfType <ParameterFormatterAttribute>().ToArray();

            if (formatters.Length > 1)
            {
                throw new InvalidOperationException($"Parameter can contain only one attribute ParameterFormatterAttribute. Parameter: {parameterInfo.Name}, Detected attributes: {string.Join(", ", formatters.Select(f => f.GetType().Name).OrderBy(n => n))}");
            }

            return(formatters.Length == 1
                ? value => formatters[0].Format(CultureInfoProvider.GetCultureInfo(), value)
                : defaultFormatter);
        }
예제 #22
0
    /// <summary>
    /// Adds culture to site. Called when the "Add culture to site" button is pressed.
    /// Expects the CreateCulture method to be run first.
    /// </summary>
    private bool AddCultureToSite()
    {
        // Get the culture
        CultureInfo culture = CultureInfoProvider.GetCultureInfo("MyNewCulture");

        if (culture != null)
        {
            // Add culture to the site
            CultureSiteInfoProvider.AddCultureToSite(culture.CultureID, SiteContext.CurrentSiteID);

            return(true);
        }

        return(false);
    }
    /// <summary>
    /// Creates or rebuild department content search index.
    /// </summary>
    /// <param name="departmentNode">Department node</param>
    private void CreateDepartmentContentSearchIndex(TreeNode departmentNode)
    {
        string codeName       = "default_department_" + departmentNode.NodeGUID;
        string departmentName = departmentNode.GetDocumentName();

        SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(codeName);

        if (sii == null)
        {
            // Create search index info
            sii           = new SearchIndexInfo();
            sii.IndexName = codeName;
            string suffix = " - Default";
            sii.IndexDisplayName      = TextHelper.LimitLength(departmentName, 200 - suffix.Length, "") + suffix;
            sii.IndexAnalyzerType     = SearchAnalyzerTypeEnum.StandardAnalyzer;
            sii.IndexType             = TreeNode.OBJECT_TYPE;
            sii.IndexIsCommunityGroup = false;
            sii.IndexProvider         = SearchIndexInfo.LUCENE_SEARCH_PROVIDER;

            // Create search index settings info
            SearchIndexSettingsInfo sisi = new SearchIndexSettingsInfo();
            sisi.ID         = Guid.NewGuid();
            sisi.Path       = departmentNode.NodeAliasPath + "/%";
            sisi.Type       = SearchIndexSettingsInfo.TYPE_ALLOWED;
            sisi.ClassNames = "";

            // Create settings item
            SearchIndexSettings sis = new SearchIndexSettings();

            // Update settings item
            sis.SetSearchIndexSettingsInfo(sisi);

            // Update xml value
            sii.IndexSettings = sis;
            SearchIndexInfoProvider.SetSearchIndexInfo(sii);

            // Assign to current website
            SearchIndexSiteInfoProvider.AddSearchIndexToSite(sii.IndexID, SiteContext.CurrentSiteID);
        }

        // Add current culture to search index
        CultureInfo ci = CultureInfoProvider.GetCultureInfo(departmentNode.DocumentCulture);

        SearchIndexCultureInfoProvider.AddSearchIndexCulture(sii.IndexID, ci.CultureID);

        // Rebuild search index
        SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Rebuild, null, null, sii.IndexName, sii.IndexID);
    }
예제 #24
0
    /// <summary>
    /// Adds culture to search index. Called when the "Add culture to index" button is pressed.
    /// Expects the CreateSearchIndex method to be run first.
    /// </summary>
    private bool AddCultureToSearchIndex()
    {
        // Get the search index and culture
        SearchIndexInfo index   = SearchIndexInfoProvider.GetSearchIndexInfo("MyNewIndex");
        CultureInfo     culture = CultureInfoProvider.GetCultureInfo("en-us");

        if ((index != null) && (culture != null))
        {
            // Save the binding
            SearchIndexCultureInfoProvider.AddSearchIndexCulture(index.IndexID, culture.CultureID);

            return(true);
        }

        return(false);
    }
예제 #25
0
    private static CultureInfo GetSafeCulture(int cultureId)
    {
        if (cultureId <= 0)
        {
            return(null);
        }

        try
        {
            return(CultureInfoProvider.GetCultureInfo(cultureId));
        }
        catch (Exception)
        {
            return(null);
        }
    }
예제 #26
0
    /// <summary>
    /// Creates culture site. Called when the "Create site" button is pressed.
    /// </summary>
    private bool AddCultureToSite()
    {
        // Get site and culture objects
        SiteInfo    site    = SiteInfoProvider.GetSiteInfo("MyNewSite");
        CultureInfo culture = CultureInfoProvider.GetCultureInfo("ar-sa");

        if ((site != null) && (culture != null))
        {
            // Add culture to site
            CultureSiteInfoProvider.AddCultureToSite(culture.CultureID, site.SiteID);

            return(true);
        }

        return(false);
    }
예제 #27
0
    /// <summary>
    /// Remove culture from site. Called when the "Remove culture from site" button is pressed.
    /// Expects the CreateCultureSite method to be run first.
    /// </summary>
    private bool RemoveCultureFromSite()
    {
        // Get site and culture objects
        SiteInfo    site    = SiteInfoProvider.GetSiteInfo("MyNewSite");
        CultureInfo culture = CultureInfoProvider.GetCultureInfo("ar-sa");

        if ((site != null) && (culture != null))
        {
            // Delete the culture site
            CultureSiteInfoProvider.RemoveCultureFromSite(culture.CultureID, site.SiteID);

            return(true);
        }

        return(false);
    }
    /// <summary>
    /// Handles OnAfterValidate event of the UI form.
    /// </summary>
    /// <param name="sender">Sender object</param>
    /// <param name="e">Event argument</param>
    protected void OnAfterValidate(object sender, EventArgs e)
    {
        int    cultureId    = Control.EditedObject.Generalized.ObjectID;
        string cultureCode  = ValidationHelper.GetString(Control.GetFieldValue("CultureCode"), String.Empty).Trim();
        string cultureAlias = ValidationHelper.GetString(Control.GetFieldValue("CultureAlias"), String.Empty).Trim();

        // Check validity of culture code
        if (!CultureHelper.IsValidCultureInfoName(cultureCode))
        {
            Control.ShowError(Control.GetString("Culture.ErrorNoGlobalCulture"));
            Control.StopProcessing = true;
        }

        if (CultureHelper.IsNeutralCulture(cultureCode) && !Control.StopProcessing)
        {
            Control.ShowError(Control.GetString("culture.neutralculturecannotbeused"));
            Control.StopProcessing = true;
        }

        // Check if culture already exists for new created cultures
        if (cultureId == 0 && CultureInfoProvider.GetCultureInfo(cultureCode) != null && !Control.StopProcessing)
        {
            Control.ShowError(Control.GetString("culture_new.cultureexists"));
            Control.StopProcessing = true;
        }

        // Check whether culture alias is unique
        if (cultureId == 0 && !String.IsNullOrEmpty(cultureAlias) && !Control.StopProcessing)
        {
            CultureInfo cultureInfo = CultureInfoProvider.GetCultureInfoForCulture(cultureAlias);
            if ((cultureInfo != null) || CMSString.Equals(cultureAlias, cultureCode, true))
            {
                Control.ShowError(Control.GetString("Culture.AliasNotUnique"));
                Control.StopProcessing = true;
            }
        }

        // Show warning if culture is UI and there is no resx file
        bool isUiCulture = ValidationHelper.GetBoolean(Control.GetFieldValue("CultureIsUICulture"), false);

        if (!Control.StopProcessing && !LocalizationHelper.ResourceFileExistsForCulture(cultureCode) && isUiCulture)
        {
            string url          = "http://www.kentico.com/Support/Support-files/Localization-packs";
            string downloadPage = String.Format(@"<a href=""{0}"" target=""_blank"" >{1}</a> ", url, HTMLHelper.HTMLEncode(url));
            Control.ShowWarning(String.Format(Control.GetString("culture.noresxwarning"), downloadPage));
        }
    }
예제 #29
0
    /// <summary>
    /// Creates the initial document strucutre used for the example. Called when the "Create document structure" button is pressed.
    /// </summary>
    private bool CreateDocumentStructure()
    {
        // Add a new culture to the current site
        CultureInfo culture = CultureInfoProvider.GetCultureInfo("de-de");

        CultureSiteInfoProvider.AddCultureToSite(culture.CultureID, CMSContext.CurrentSiteID);

        // Create new instance of the Tree provider
        TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

        // Get parent node
        TreeNode parentNode = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/", "en-us");

        if (parentNode != null)
        {
            // Create the API Example folder
            TreeNode newNode = TreeNode.New("CMS.Folder", tree);

            newNode.DocumentName    = "API Example";
            newNode.DocumentCulture = "en-us";

            newNode.Insert(parentNode);

            parentNode = newNode;

            // Create the Source folder - the document to be moved will be stored here
            newNode = TreeNode.New("CMS.Folder", tree);

            newNode.DocumentName    = "Source";
            newNode.DocumentCulture = "en-us";

            newNode.Insert(parentNode);

            // Create the Target folder - a document will be moved here
            newNode = TreeNode.New("CMS.Folder", tree);

            newNode.DocumentName    = "Target";
            newNode.DocumentCulture = "en-us";

            newNode.Insert(parentNode);

            return(true);
        }

        return(false);
    }
예제 #30
0
    /// <summary>
    /// On unigrids external databond.
    /// </summary>
    /// <param name="sender">Sender</param>
    /// <param name="sourceName">Name</param>
    /// <param name="parameter">Parameter</param>
    private object unigridScopes_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName.ToLowerCSafe())
        {
        // Class name
        case "documenttype":
            int           classID   = ValidationHelper.GetInteger(parameter, 0);
            DataClassInfo dataClass = DataClassInfoProvider.GetDataClassInfo(classID);
            if (dataClass != null)
            {
                return(dataClass.ClassDisplayName);
            }
            else
            {
                return(GetString("general.all"));
            }

        // Culture
        case "culture":
            int cultureID = ValidationHelper.GetInteger(parameter, 0);
            if (cultureID > 0)
            {
                CultureInfo culture = CultureInfoProvider.GetCultureInfo(cultureID);
                if (culture != null)
                {
                    return(culture.CultureCode);
                }
            }
            return(GetString("general.all"));

        // Levels
        case "levels":
            string levels = ValidationHelper.GetString(parameter, String.Empty);
            if (string.IsNullOrEmpty(levels))
            {
                return(GetString("general.all"));
            }

            // Format levels
            levels = levels.Replace("/", String.Empty).Replace("{", " ").Replace("}", ",");
            return(levels.TrimEnd(','));
        }

        return(null);
    }