Example #1
0
 private static void SaveDictionary(string path, TranslateDictionary dictionary)
 {
     using (var stream = File.Create(path))
     {
         var serializer = new BinaryFormatter();
         serializer.Serialize(stream, dictionary);
     }
 }
Example #2
0
        public void Initialize()
        {
            var uri = _document.DocumentUri;

            if (!uri.IsFile)
            {
                throw new InvalidOperationException();
            }


            _documentPath = uri.LocalPath;

            {
                var path = _documentPath + ".dictionary";
                Dictionary = LoadDictionary(path) ?? new TranslateDictionary();
            }


            {
                var path = _documentPath + ".translation";

                var terms = LoadTerms(path);

                if (!ValidateTerms(_document, terms))
                {
                    Dictionary = TranslateDictionary.Merge(Dictionary, CreateDictionary(terms));
                    terms      = ExtractTerms(_document);

                    foreach (var t in terms)
                    {
                        var condidateTerms = Dictionary[t.SourceTerm];

                        string translatedResult;
                        if (condidateTerms.IsSingle(out translatedResult))
                        {
                            t.TranslatedTerm = translatedResult;
                        }

                        else
                        {
                            t.TranslatedTerm = "";
                        }
                    }

                    SaveTerms(path, terms);
                }

                Terms = terms;
            }
        }
Example #3
0
        private static TranslateDictionary CreateDictionary(TranslationTerm[] terms)
        {
            if (terms == null)
            {
                return(null);
            }

            var dictionary = new TranslateDictionary();

            foreach (var t in terms)
            {
                dictionary.AddTerm(t);
            }

            return(dictionary);
        }
Example #4
0
    public static TranslateDictionary Merge( TranslateDictionary dictionary1, TranslateDictionary dictionary2 )
    {

      var dictionary = new TranslateDictionary();

      if ( dictionary1 != null )
      {
        foreach ( var term in dictionary1.SourceTerms )
          dictionary.AddTerm( term, dictionary1[term] );
      }

      if ( dictionary2 != null )
      {
        foreach ( var term in dictionary2.SourceTerms )
          dictionary.AddTerm( term, dictionary2[term] );
      }

      return dictionary;
    }
Example #5
0
        public static TranslateDictionary Merge(TranslateDictionary dictionary1, TranslateDictionary dictionary2)
        {
            var dictionary = new TranslateDictionary();

            if (dictionary1 != null)
            {
                foreach (var term in dictionary1.SourceTerms)
                {
                    dictionary.AddTerm(term, dictionary1[term]);
                }
            }

            if (dictionary2 != null)
            {
                foreach (var term in dictionary2.SourceTerms)
                {
                    dictionary.AddTerm(term, dictionary2[term]);
                }
            }

            return(dictionary);
        }
Example #6
0
    private static TranslateDictionary CreateDictionary( TranslationTerm[] terms )
    {

      if ( terms == null )
        return null;

      var dictionary = new TranslateDictionary();

      foreach ( var t in terms )
        dictionary.AddTerm( t );

      return dictionary;
    }
Example #7
0
 private static void SaveDictionary( string path, TranslateDictionary dictionary )
 {
   using ( var stream = File.Create( path ) )
   {
     var serializer = new BinaryFormatter();
     serializer.Serialize( stream, dictionary );
   }
 }