Example #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the text for the specified component. The englishText is returned when the text
        /// for the specified object cannot be found for the current UI language.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static string GetStringForObject(IComponent component, string englishText)
        {
            var lm = GetLocalizationManagerForComponent(component);

            if (lm != null)
            {
                string id;
                if (lm.ComponentCache.TryGetValue(component, out id))
                {
                    return(lm.GetLocalizedString(id, englishText));
                }
            }

            return(LocalizationManager.StripOffLocalizationInfoFromText(
                       englishText ?? Utils.GetProperty(component, "Text") as string));
        }
Example #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets a string for the specified string id. The englishText is returned when
        /// a string cannot be found for the specified id and the current UI language.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static string GetString(string stringId, string englishText, string comment, string englishToolTipText,
                                       string englishShortcutKey, IComponent component)
        {
            if (component != null)
            {
                var lm = GetLocalizationManagerForComponent(component) ??
                         GetLocalizationManagerForString(stringId);

                if (lm != null)
                {
                    lm.RegisterComponentForLocalizing(component, stringId, englishText,
                                                      englishToolTipText, englishShortcutKey, comment);

                    return(lm.GetLocalizedString(stringId, englishText));
                }
            }

            return(GetStringFromAnyLocalizationManager(stringId) ??
                   LocalizationManager.StripOffLocalizationInfoFromText(englishText));
        }
Example #3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets a string for the specified string id, in the specified language, or the
        /// englishText if that wasn't found. Prefers the englishText passed here to one that
        /// we might have got out of a TMX/Xliff, as is the non-obvious-but-ultimately-correct
        /// policy for this library.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static string GetString(string stringId, string englishText, string comment, IEnumerable <string> preferredLanguageIds, out string languageIdUsed)
        {
            if (preferredLanguageIds.Count() == 0)
            {
                throw new ArgumentException("preferredLanguageIds was empty");
            }

            if (string.IsNullOrEmpty(englishText))
            {
                throw new ArgumentException("englishText may not be empty (because common... that can't be what you meant to do...");
            }

            var stringFromAnyLocalizationManager = GetStringFromAnyLocalizationManager(stringId, preferredLanguageIds, out languageIdUsed);

            //even if found in English TMX/Xliff, we prefer to use the version that came from the code
            if (languageIdUsed == "en" || string.IsNullOrEmpty(stringFromAnyLocalizationManager))
            {
                languageIdUsed = "en";
                return(LocalizationManager.StripOffLocalizationInfoFromText(englishText));
            }

            return(stringFromAnyLocalizationManager);
        }
 public void UpdateTextFromObject()
 {
     Text = LocalizationManager.StripOffLocalizationInfoFromText(_component is DataGridViewColumn
                         ? ((DataGridViewColumn)_component).HeaderText
                         : Utils.GetProperty(_component, "Text") as string);
 }