예제 #1
0
        /// <summary>
        /// Set for the UserDefined cultureCode a new text matching a stringCode.
        /// </summary>
        /// <param name="stringCode"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public bool SetUserDefinedTranslatedText(StringCode stringCode, string text)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return(false);
            }

            TranslatedTextPage page = null;

            // get the page of the default cultureCode
            if (!_dictTextTranslatedPage.ContainsKey(CultureCode.UserDefined))
            {
                // the culture code does not exists!
                return(false);
            }

            page = _dictTextTranslatedPage[CultureCode.UserDefined];

            // now get the translated text matching the code
            TranslatedText translatedText = page.FindTranslatedTextByStringCode(stringCode);

            // the translated not yet exists, create it
            if (translatedText == null)
            {
                page.Add(stringCode, text);
                return(true);
            }

            // exists, set the new text
            translatedText.ReplaceText(text);
            return(true);
        }
        public bool Add(StringCode stringCode, string text)
        {
            // if exists, bye
            if (_dictTranslatedText.ContainsKey(stringCode))
            {
                return(false);
            }

            TranslatedText translatedText = new TranslatedText(stringCode, text);

            _dictTranslatedText.Add(stringCode, translatedText);
            return(true);
        }
        public bool AddOrReplace(StringCode stringCode, string text)
        {
            TranslatedText translatedText = null;

            // if not exists, create it
            if (_dictTranslatedText.ContainsKey(stringCode))
            {
                translatedText = _dictTranslatedText[stringCode];
            }
            else
            {
                translatedText = new TranslatedText(stringCode, text);
                return(true);
            }

            // replace just the text
            translatedText.ReplaceText(text);
            return(true);
        }
예제 #4
0
        /// <summary>
        /// get the text translation of the string code in the current culture.
        /// If the code is not translated, return an empty string.
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public string GetTranslation(StringCode code)
        {
            TranslatedTextPage page = null;

            // get the page of the default cultureCode
            if (!_dictTextTranslatedPage.ContainsKey(_cultureCode))
            {
                // the culture code does not exists!
                return("(null)");
            }

            page = _dictTextTranslatedPage[_cultureCode];

            // now get the translated text matching the code
            TranslatedText translatedText = page.FindTranslatedTextByStringCode(code);

            if (translatedText == null)
            {
                return("(null)");
            }

            return(translatedText.Text);
        }