예제 #1
0
        static void Main(string[] args)
        {
            PropsDocument document = new PropsDocument(true);
            document.Load(@"P:\Perso\i3-label_fr - Copy.properties");

            foreach (PropsElement element in document.Elements)
            {
                Console.WriteLine(element);
            }

            Console.ReadLine();
        }
예제 #2
0
        private void loadTransFileButton_Click(object sender, RoutedEventArgs e)
        {
            if (list.Any(vm => !string.IsNullOrEmpty(vm.NewValue)))
            {
                if (MessageBox.Show(
            @"If you load a new document you may loose your work.
            You might want to save your work first.
            If you click yes you current work will be overriden.", "Save before.", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                {
                    return;
                }
            }

            ChangeIsEnableControls(false);
            transFileName = SelectOpenFile();
            if (string.IsNullOrEmpty(transFileName))
            {
                ChangeIsEnableControls(true);
                return;
            }
            SetMessage("Loading file...");
            ExecuteAsync(() =>
            {
                transDocument = new PropsDocument(false);
                transDocument.Load(transFileName);

                //todo : find a way to keep translate doc comments
                transDocument.RemoveComments();
            }, () =>
            {

                //verify if the new file schema is the same as the reference
                if (!SchemasMatch())
                {
                    MessageBox.Show("This document does not match the reference document.");
                    ChangeIsEnableControls(true);
                    return;
                }

                //fill only the translate column
                List<PropsElement> tempList = transDocument.Elements.ToList();
                if (list != null)
                {
                    foreach (CompViewModelItem vm in list)
                    {
                        if (!vm.IsComment)
                        {
                            PropsElement element = tempList.FirstOrDefault(el => el.Key == vm.Key);
                            if (element == null)
                            {
                                ChangeIsEnableControls(true);
                                throw new Exception("Cant find trans Element when sync loaded trans document.");
                            }
                            vm.NewValue = element.Value;
                            tempList.Remove(element);
                        }
                    }
                    if (tempList.Any())
                    {
                        ChangeIsEnableControls(true);
                        throw new Exception("Elements left in trans document after sync.");
                    }
                }
                ChangeIsEnableControls(true);
                ClearSearch();
            });
        }
예제 #3
0
        private void SaveCurrentWork(object obj)
        {
            if (list == null)
            {
                return;
            }
            string fileName = string.Empty;
            if (obj != null)
            {
                fileName = obj.ToString();
            }

            if (string.IsNullOrEmpty(fileName))
            {
                if (!list.Any(vm => !string.IsNullOrEmpty(vm.NewValue)))
                {//nothing to save
                    return;
                }
                string directory = System.IO.Path.GetDirectoryName(referenceFileName);
                directory = System.IO.Path.Combine(directory, "Backup");
                fileName = System.IO.Path.Combine(directory, DateTime.Now.ToString("dd_MM_yyyy_HH_mm") + ".properties");
                if (!System.IO.Directory.Exists(directory))
                {
                    System.IO.Directory.CreateDirectory(directory);
                }
            }

            PropsDocument doc = new PropsDocument();
            foreach (CompViewModelItem vm in list)
            {
                string value = vm.IsComment ? vm.ReferenceValue : vm.NewValue;
                doc.Add(new PropsElement(vm.Key, value));
            }
            doc.Save(fileName);
        }
예제 #4
0
        private void loadReferenceFileButton_Click(object sender, RoutedEventArgs e)
        {
            if (referenceDocument != null)
            {
                if (MessageBox.Show(
            @"If you load a new document you may loose your work.
            You might want to save your work first.
            If you click yes you current work will be overriden.", "Save before.", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                {
                    return;
                }
            }

            ChangeIsEnableControls(false);

            referenceFileName = SelectOpenFile();
            if (string.IsNullOrEmpty(referenceFileName))
            {
                ChangeIsEnableControls(true);
                return;
            }
            SetMessage("Loading properties...");

            ExecuteAsync(() =>
            {
                referenceDocument = new PropsDocument(true);
                referenceDocument.Load(referenceFileName);

                //creating a new document for translation
                transDocument = new PropsDocument();

                list = new ObservableCollection<CompViewModelItem>();
                foreach (PropsElement element in referenceDocument.Elements)
                {
                    PropsElement copyElement = new PropsElement(element.Key, string.Empty);
                    list.Add(new CompViewModelItem { Key = element.Key, ReferenceValue = element.Value, NewValue = string.Empty });
                    transDocument.Add(copyElement);
                }
            }, () =>
            {
                SetMessage(referenceFileName + " loaded");
                ClearSearch();
                ListControl.ItemsSource = list;

                ChangeIsEnableControls(true);
            });
        }