Пример #1
0
        public virtual ITranslationResult Translate(string key, string word, string language)
        {
            ITranslationResult result;

            if (!string.IsNullOrEmpty(key))
            {
                result = this.Translate(key, language);
                if (result.IsSuccessful())
                {
                    return(result);
                }
            }
            result = new TranslationResult();
            if (string.IsNullOrEmpty(language))
            {
                language = this._defaultLanguage;
            }
            StringsStorageEntry entry = this.Storage.GetEntryByWord(word);

            if (entry != null && entry.Words.ContainsKey(language))
            {
                result.Translation = entry.Words[language];
                return(result);
            }
            result.Status = ResultStatus.Unsuccessful;
            return(result);
        }
Пример #2
0
        public virtual StringsStorageEntry GetEntryByWord(string word)
        {
            if (null == this._agent)
            {
                throw new InvalidOperationException("Agent not set");
            }
            StringsStorageEntry result = null;

            if (string.IsNullOrEmpty(word))
            {
                result = null;
            }
            else
            {
                XmlReader reader  = XmlReader.Create(new StringReader(strings));
                string    compare = this.GetFormat(word);
                while (reader.Read())
                {
                    if (reader.HasAttributes)
                    {
                        StringsStorageEntry entry = new StringsStorageEntry();
                        entry.Key = reader.Name;
                        while (reader.MoveToNextAttribute())
                        {
                            entry.Words.Add(reader.Name, this.GetFormatedWord(reader.Value, word));
                            if (reader.Value == compare)
                            {
                                while (reader.MoveToNextAttribute())
                                {
                                    entry.Words.Add(reader.Name, this.GetFormatedWord(reader.Value, word));
                                }
                                result = entry;
                            }
                        }
                    }
                }
            }
            return(result);
        }
Пример #3
0
        public virtual StringsStorageEntry GetEntryByKey(string key, string source)
        {
            if (null == this._agent)
            {
                throw new InvalidOperationException("Agent not set");
            }

            StringsStorageEntry result;

            if (string.IsNullOrEmpty(key))
            {
                result = null;
            }
            else
            {
                StringsStorageEntry entry = null;
                if (String.IsNullOrEmpty(strings))
                {
                    Open();
                }

                XmlReader reader = XmlReader.Create(new StringReader(strings));
                if (reader.ReadToFollowing(key))
                {
                    entry     = new StringsStorageEntry();
                    entry.Key = key;
                    if (reader.HasAttributes)
                    {
                        while (reader.MoveToNextAttribute())
                        {
                            entry.Words.Add(reader.Name, this.GetFormatedWord(reader.Value, source));
                        }
                    }
                }
                result = entry;
            }
            return(result);
        }
Пример #4
0
        public virtual StringsStorageEntry GetEntryByKey(string key, string source)
        {
            if (null == this._agent) throw new InvalidOperationException("Agent not set");

            StringsStorageEntry result;
            if (string.IsNullOrEmpty(key))
                result = null;
            else
            {
                StringsStorageEntry entry = null;
                if (String.IsNullOrEmpty(strings))
                    Open();

                XmlReader reader = XmlReader.Create(new StringReader(strings));
                if (reader.ReadToFollowing(key))
                {
                    entry = new StringsStorageEntry();
                    entry.Key = key;
                    if (reader.HasAttributes)
                    {
                        while (reader.MoveToNextAttribute())
                        {
                            entry.Words.Add(reader.Name, this.GetFormatedWord(reader.Value, source));
                        }
                    }
                }
                result = entry;
            }
            return result;
        }
Пример #5
0
 public virtual StringsStorageEntry GetEntryByWord(string word)
 {
     if (null == this._agent)
     {
         throw new InvalidOperationException("Agent not set");
     }
     StringsStorageEntry result = null;
     if (string.IsNullOrEmpty(word))
     {
         result = null;
     }
     else
     {
         XmlReader reader = XmlReader.Create(new StringReader(strings));
         string compare = this.GetFormat(word);
         while (reader.Read())
         {
             if (reader.HasAttributes)
             {
                 StringsStorageEntry entry = new StringsStorageEntry();
                 entry.Key = reader.Name;
                 while (reader.MoveToNextAttribute())
                 {
                     entry.Words.Add(reader.Name, this.GetFormatedWord(reader.Value, word));
                     if (reader.Value == compare)
                     {
                         while (reader.MoveToNextAttribute())
                         {
                             entry.Words.Add(reader.Name, this.GetFormatedWord(reader.Value, word));
                         }
                         result = entry;
                     }
                 }
             }
         }
     }
     return result;
 }