コード例 #1
0
 public OpenTranslationAction(TranslationKeyInfo translationKeyInfo, IServiceProvider serviceProvider)
 {
     _translationKeyInfo = translationKeyInfo;
     _serviceProvider = serviceProvider;
     DisplayText = string.Format("{0}: {1} line {2}", _translationKeyInfo.Language, _translationKeyInfo.FilePath, _translationKeyInfo.LineNumber);
     IsEnabled = true;
 }
コード例 #2
0
        public void AddKey(string key, string language, string value, string filePath, int lineNumber)
        {
            var translationInfo = new TranslationKeyInfo
                                      {
                                          Key = key,
                                          Value = value,
                                          FilePath = filePath,
                                          LineNumber = lineNumber,
                                          Language = language
                                      };

            _translations.Add(translationInfo);

            ResetLookups();
        }
コード例 #3
0
 public void AddKey(TranslationKeyInfo keyInfo)
 {
     _translations.Add(keyInfo);
     ResetLookups();
 }
コード例 #4
0
 private string CreateFileKey(TranslationKeyInfo keyInfo)
 {
     var keyEnding = keyInfo.Key.Split('/').LastOrDefault();
     return GetFilePositionKey(keyInfo.FilePath, keyInfo.LineNumber, keyEnding);
 }
コード例 #5
0
        public IEnumerable<TranslationKeyInfo> ReadTranslationKeys(XDocument doc, string xmlFile)
        {
            var languages = doc.Element("languages");
            if (languages == null)
            {
                yield break;
            }

            foreach (var language in languages.Elements("language"))
            {
                var languageIdAttribute = language.Attribute("id");
                if (languageIdAttribute == null)
                {
                    continue;
                }
                var languageId = languageIdAttribute.Value;

                var nodes = language.Descendants().Where(el => !el.Descendants().Any());
                foreach (var xNode in nodes)
                {
                    var ancestors = xNode.Ancestors().ToList();
                    var ancestorsString = ancestors.Take(ancestors.Count - 2)
                        // Skip two last ancestors - languages and language nodes
                        .Aggregate("", AddElementToPath);

                    var key = KeysSeparator + ancestorsString + GetElementXPath(xNode);
                    var seeAttribute = xNode.Attributes("see").FirstOrDefault();
                    var seeReference = seeAttribute == null ? null : seeAttribute.Value;

                    var value = xNode.Value;

                    int lineNumber = ((IXmlLineInfo) xNode).HasLineInfo() ? ((IXmlLineInfo) xNode).LineNumber : -1;

                    var translationInfo = new TranslationKeyInfo
                                              {
                                                  Key = key,
                                                  Value = value,
                                                  SeeReference = seeReference,
                                                  FilePath = xmlFile,
                                                  LineNumber = lineNumber,
                                                  Language = languageId
                                              };

                    yield return translationInfo;
                }
            }
        }