Exemplo n.º 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);
        }
Exemplo n.º 2
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);
        }