Exemple #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// This method goes through the collection of the controls that have been extended
        /// and adds to or udates the default values in the string files. Then each extended
        /// control is localized.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void LocalizeControls()
        {
            if (!_okayToLocalizeControls || m_extendedCtrls == null || _manager == null)
            {
                return;
            }

            FinalizationForListViewColumnHeaders();
            FinalizationForDataGridViewColumns();
            FinalizationForILocalizableComponents();

            // Now make sure each extended control is localized.
            foreach (var locInfo in m_extendedCtrls.Values
                     .Where(li => li.Priority != LocalizationPriority.NotLocalizable))
            {
                if (string.IsNullOrEmpty(locInfo.LangId))
                {
                    locInfo.LangId = LocalizationManager.kDefaultLang;
                }
                // Depending on the order in which VS Designer decides to initialize fields, locInfo may be originally created before the Text of the
                // control is set. If so, obtain it again, unless this is an ILocalizableComponent. In that case, the above Finalization
                // method should have taken care of this.
                if (locInfo.Category != LocalizationCategory.LocalizableComponent && string.IsNullOrWhiteSpace(locInfo.Text))
                {
                    locInfo.UpdateTextFromObject();
                }
                // Special case: the Text of a column header is "ColumnHeader" before it is ever set.
                // This means that if we first processed the CH before we set its text, we have noted
                // "ColumnHeader" as its default English name. Get the real one if it has since been updated.
                var ch = locInfo.Component as ColumnHeader;
                if (ch != null && ch.Text != "ColumnHeader" && locInfo.Text == "ColumnHeader")
                {
                    locInfo.UpdateTextFromObject();
                }
                _manager.RegisterComponentForLocalizing(locInfo, (lm, info) =>
                {
                    if (info.Category == LocalizationCategory.LocalizableComponent)
                    {
                        lm.ApplyLocalizationsToILocalizableComponent(info);
                    }
                    else
                    {
                        lm.ApplyLocalization(info.Component);
                    }
                });
            }

            m_extendedCtrls         = null;
            _okayToLocalizeControls = false;
        }