示例#1
0
        private bool checkWantAddResourceFile(
            ZlpFileInfo filePath)
        {
            if (filePath == null)
            {
                return(false);
            }
            else
            {
                if (filePath.Directory.Name.EqualsNoCase(@"Properties"))
                {
                    return(true);
                }
                else
                {
                    // If a "*.Designer.*" companion file exists, assume it
                    // is a Windows Forms resource file and do NOT add the file
                    // since it can be translated directly from within VS.NET.

                    if (Project.IgnoreWindowsFormsResourcesWithDesignerFiles)
                    {
                        var baseFileName = LanguageCodeDetection.GetBaseName(Project, filePath.Name);

                        var files = filePath.Directory.GetFiles($@"{baseFileName}.Designer.*");

                        return(files.Length <= 0);
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
        }
        private void refillLanguagesToTranslate()
        {
            languagesToDisplayCheckListBox.Items.Clear();

            var pairs = new List <MyTuple <string, string> >();

            // ReSharper disable LoopCanBeConvertedToQuery
            foreach (var languageCode in languageCodes)
            // ReSharper restore LoopCanBeConvertedToQuery
            {
                if (!string.IsNullOrEmpty(languageCode))
                {
                    pairs.Add(
                        new MyTuple <string, string>(
                            $@"{LanguageCodeDetection.MakeValidCulture(languageCode).DisplayName} ({languageCode})",
                            languageCode));
                }
            }

            pairs.Sort((x, y) => string.Compare(x.Item1, y.Item1, StringComparison.Ordinal));

            foreach (var pair in pairs)
            {
                var index = languagesToDisplayCheckListBox.Items.Add(pair);

                languagesToDisplayCheckListBox.SetItemChecked(index, false);
            }
        }
        protected override void InitiallyFillLists()
        {
            foreach (var languageCode in languageCodes)
            {
                if (!string.IsNullOrEmpty(languageCode.Item1))
                {
                    referenceLanguageComboBox.Properties.Items.Add(
                        new MyTuple <string, MyTuple <string, string> >(
                            $@"{
                                    LanguageCodeDetection.MakeValidCulture(languageCode.Item1).DisplayName
                                } ({languageCode})",
                            languageCode));
                }
            }

            var items = new List <MyTuple <string, CultureInfo> >();

            foreach (var culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
            {
                items.Add(new MyTuple <string, CultureInfo>(culture.DisplayName, culture));
            }

            items.Sort((x, y) => string.CompareOrdinal(x.Item1, y.Item1));

            foreach (var item in items)
            {
                newLanguageComboBox.Properties.Items.Add(item);
            }

            // --

            fillTranslationEngine();
        }
示例#4
0
        private void refillLanguagesToTranslate()
        {
            languagesToExportCheckListBox.Items.Clear();

            var forbidden =
                referenceLanguageGroupBox.SelectedIndex >= 0 &&
                referenceLanguageGroupBox.SelectedIndex <
                referenceLanguageGroupBox.Properties.Items.Count
                    ? ((MyTuple <string, string>)referenceLanguageGroupBox.SelectedItem).Item2
                    : string.Empty;

            foreach (var languageCode in languageCodes)
            {
                if (!string.IsNullOrEmpty(languageCode) &&
                    languageCode.ToLowerInvariant() != forbidden.ToLowerInvariant())
                {
                    var index = languagesToExportCheckListBox.Items.Add(
                        new MyTuple <string, string>(
                            $@"{LanguageCodeDetection.MakeValidCulture(languageCode).DisplayName} ({languageCode})",
                            languageCode));

                    languagesToExportCheckListBox.SetItemChecked(index, true);
                }
            }
        }
        private void refillLanguagesToTranslate()
        {
            languagesToDisplayCheckListBox.Items.Clear();

            var pairs = new List <Pair <string, string> >();

            // ReSharper disable LoopCanBeConvertedToQuery
            foreach (var languageCode in languageCodes)
            // ReSharper restore LoopCanBeConvertedToQuery
            {
                if (!string.IsNullOrEmpty(languageCode))
                {
                    pairs.Add(
                        new Pair <string, string>(
                            string.Format(
                                @"{0} ({1})",
                                LanguageCodeDetection.MakeValidCulture(languageCode).DisplayName,
                                languageCode),
                            languageCode));
                }
            }

            pairs.Sort((x, y) => x.First.CompareTo(y.First));

            foreach (var pair in pairs)
            {
                var index = languagesToDisplayCheckListBox.Items.Add(pair);

                languagesToDisplayCheckListBox.SetItemChecked(index, false);
            }
        }
        public override void InitiallyFillLists()
        {
            foreach (var languageCode in languageCodes)
            {
                if (!string.IsNullOrEmpty(languageCode.First))
                {
                    referenceLanguageComboBox.Properties.Items.Add(
                        new Pair <string, Pair <string, string> >(
                            string.Format(
                                @"{0} ({1})",
                                LanguageCodeDetection.MakeValidCulture(languageCode.First).DisplayName,
                                languageCode),
                            languageCode));
                }
            }

            var items = new List <Pair <string, CultureInfo> >();

            foreach (var culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
            {
                items.Add(new Pair <string, CultureInfo>(culture.DisplayName, culture));
            }

            items.Sort((x, y) => string.CompareOrdinal(x.First, y.First));

            foreach (var item in items)
            {
                newLanguageComboBox.Properties.Items.Add(item);
            }

            // --

            fillTranslationEngine();
        }
示例#7
0
        protected override void InitiallyFillLists()
        {
            base.InitiallyFillLists();

            // --

            _groups.Sort(
                (x, y) => string.CompareOrdinal(
                    x.GetNameIntelligent(_project),
                    y.GetNameIntelligent(_project)));

            fileGroupsListBox.Items.Clear();

            foreach (var group in _groups)
            {
                if (!group.IgnoreDuringExportAndImport &&
                    (group.ParentSettings == null || !group.ParentSettings.EffectiveIgnoreDuringExportAndImport))
                {
                    var index = fileGroupsListBox.Items.Add(
                        new MyTuple <string, FileGroup>(
                            group.GetNameIntelligent(_project),
                            group));

                    fileGroupsListBox.SetItemChecked(index, true);
                }
            }

            if (_groups.Count == 1)
            {
                // Select one, if only one present.
                selectAllFileGroupsButton_Click(null, null);
            }

            // --

            foreach (var languageCode in languageCodes)
            {
                referenceLanguageGroupBox.Properties.Items.Add(
                    new MyTuple <string, string>(
                        $@"{LanguageCodeDetection.MakeValidCulture(languageCode).DisplayName} ({languageCode})",
                        languageCode));
            }

            if (languageCodes.Length == 1)
            {
                // Select one, if only one present.
                selectAllLanguagesToExportButton_Click(null, null);
            }

            // --
            // Select defaults.

            if (referenceLanguageGroupBox.SelectedIndex < 0 &&
                referenceLanguageGroupBox.Properties.Items.Count > 0)
            {
                referenceLanguageGroupBox.SelectedIndex = 0;
            }
        }
 public static void ApplySpellCheckerCulture(
     SpellChecker spellChecker,
     string languageCode)
 {
     if (spellChecker != null)
     {
         spellChecker.Culture = LanguageCodeDetection.MakeValidCulture(languageCode);
     }
 }
        private static List <Pair <string, int> > dectectLanguageCodesFromTable(
            DataTable table)
        {
            // Make no Set type to keep order.
            var result = new List <Pair <string, int> >();

            // --
            // Header.

            const int columnStartIndex = 0;

            for (var columnIndex = columnStartIndex + 0; columnIndex < table.Columns.Count; ++columnIndex)
            {
                var languageCode = string.IsNullOrEmpty(table.Columns[columnIndex].Caption)
                                       ? table.Columns[columnIndex].ColumnName
                                       : table.Columns[columnIndex].Caption;

                if (languageCode != Resources.SR_CommandProcessorSend_Process_Name &&
                    languageCode != Resources.SR_CommandProcessorSend_Process_Comment &&
                    languageCode != Resources.SR_CommandProcessorSend_Process_Group)
                {
                    if (string.IsNullOrEmpty(languageCode) ||
                        languageCode.Trim().Length <= 0)
                    {
                        break;
                    }
                    else
                    {
                        var lc = StringExtensionMethods.ToLowerInvariantIntelligent(languageCode.Trim());
                        if (LanguageCodeDetection.IsValidCultureName(lc))
                        {
                            var found = false;

                            // ReSharper disable LoopCanBeConvertedToQuery
                            foreach (var pair in result)
                            // ReSharper restore LoopCanBeConvertedToQuery
                            {
                                if (pair.First == lc)
                                {
                                    found = true;
                                    break;
                                }
                            }

                            if (!found)
                            {
                                result.Add(new Pair <string, int>(lc, columnIndex));
                            }
                        }
                    }
                }
            }

            return(result);
        }
        private void refillLanguagesToTranslate()
        {
            var ti = TranslationHelper.GetTranslationEngine(_project);

            languagesToTranslateCheckListBox.Items.Clear();

            string appID;
            string appID2;

            TranslationHelper.GetTranslationAppID(
                MainForm.Current.ProjectFilesControl.Project ?? Project.Empty,
                out appID,
                out appID2);

            var forbidden =
                referenceLanguageGroupBox.SelectedIndex >= 0 &&
                referenceLanguageGroupBox.SelectedIndex <
                referenceLanguageGroupBox.Properties.Items.Count
                    ? ((TranslationLanguageInfo)referenceLanguageGroupBox.SelectedItem).LanguageCode
                    : string.Empty;

            var lcs =
                ti.AreAppIDsSyntacticallyValid(appID, appID2)
                    ? ti.GetDestinationLanguages(appID, appID2)
                    : new TranslationLanguageInfo[] { };

            foreach (var languageCode in languageCodes)
            {
                if (!string.IsNullOrEmpty(languageCode) &&
                    languageCode != forbidden)
                {
                    // Only add those that are supported.
                    if (TranslationHelper.IsSupportedLanguage(
                            languageCode, lcs))
                    {
                        var index = languagesToTranslateCheckListBox.Items.Add(
                            new TranslationLanguageInfo
                        {
                            UserReadableName =
                                $@"{
                                        LanguageCodeDetection.MakeValidCulture(languageCode).DisplayName
                                    } ({languageCode})",
                            LanguageCode = languageCode
                        });

                        languagesToTranslateCheckListBox.SetItemChecked(index, true);
                    }
                }
            }
        }
        protected override void InitiallyFillLists()
        {
            var plc  = projectLanguageCodes;
            var plcl = new List <string>(plc);

            foreach (var languageCode in languageCodes)
            {
                if (!string.IsNullOrEmpty(languageCode.Item1))
                {
                    referenceLanguageComboBox.Properties.Items.Add(
                        new MyTuple <string, MyTuple <string, string> >(
                            string.Format(
                                @"{0}{1} ({2})",
                                plcl.Contains(languageCode.Item1) ? @"* " : string.Empty,
                                LanguageCodeDetection.MakeValidCulture(languageCode.Item1).DisplayName,
                                languageCode),
                            languageCode));
                }
            }

            var items = new List <MyTuple <string, CultureInfo> >();

            // ReSharper disable LoopCanBeConvertedToQuery
            foreach (var culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
            // ReSharper restore LoopCanBeConvertedToQuery
            {
                items.Add(
                    new MyTuple <string, CultureInfo>(
                        string.Format(
                            @"{0}{1} [{2}]",
                            plcl.Contains(culture.Name.ToLowerInvariant()) ? @"* " : string.Empty,
                            culture.DisplayName,
                            culture.Name
                            ),
                        culture));
            }

            items.Sort((x, y) => string.CompareOrdinal(x.Item1, y.Item1));

            foreach (var item in items)
            {
                destinationLanguagesListBox.Items.Add(item);
            }

            // --

            fillTranslationEngine();
        }
        private static string generateFileName(
            FileGroup fileGroup,
            CultureInfo culture)
        {
            var pattern =
                new LanguageCodeDetection(fileGroup.Project).IsNeutralCulture(
                    fileGroup.ParentSettings,
                    culture)
                                        ? fileGroup.Project.NeutralLanguageFileNamePattern
                                        : fileGroup.Project.NonNeutralLanguageFileNamePattern;

            pattern = pattern.Replace(@"[basename]", fileGroup.BaseName);
            pattern = pattern.Replace(@"[languagecode]", culture.Name);
            pattern = pattern.Replace(@"[extension]", fileGroup.BaseExtension);
            pattern = pattern.Replace(@"[optionaldefaulttypes]", fileGroup.BaseOptionalDefaultType);

            return(pattern);
        }
        private void parseLanguageCode()
        {
            var languageCodes =
                ExcelImportController.DetectLanguagesFromExcelFile(
                    sourceFileTextEdit.Text.Trim());

            languagesToImportCheckListBox.Items.Clear();

            if (languageCodes != null)
            {
                foreach (var languageCode in languageCodes)
                {
                    if (!string.IsNullOrEmpty(languageCode) &&
                        LanguageCodeDetection.IsValidCultureName(languageCode))
                    {
                        var index = languagesToImportCheckListBox.Items.Add(
                            new MyTuple <string, string>(
                                string.Format(
                                    @"{0} ({1})",
                                    LanguageCodeDetection.MakeValidCulture(languageCode).DisplayName,
                                    languageCode),
                                languageCode));

                        languagesToImportCheckListBox.SetItemChecked(index, true);
                    }
                }

                if (languageCodes.Length == 1)
                {
                    // Select one, if only one present.
                    selectAllLanguagesToExportButton_Click(null, null);
                }
            }

            // --
            // Try to restore.

            DevExpressExtensionMethods.RestoreSettings(
                languagesToImportCheckListBox,
                _project.DynamicSettingsGlobalHierarchical,
                @"receiveFileFromTranslator.languagesToImportCheckListBox");
        }
        private void updateNewFileNameFromLanguage()
        {
            var culture =
                ((Pair <string, CultureInfo>)newLanguageComboBox.SelectedItem).Second;

            var pattern =
                new LanguageCodeDetection(MainForm.Current.ProjectFilesControl.Project ?? Project.Empty).IsNeutralCulture(
                    _fileGroup.ParentSettings,
                    culture)
                                        ? (MainForm.Current.ProjectFilesControl.Project ?? Project.Empty).NeutralLanguageFileNamePattern
                                        : (MainForm.Current.ProjectFilesControl.Project ?? Project.Empty).NonNeutralLanguageFileNamePattern;

            pattern = pattern.Replace(@"[basename]", _fileGroup.BaseName);
            pattern = pattern.Replace(@"[languagecode]", ((Pair <string, CultureInfo>)newLanguageComboBox.SelectedItem).Second.Name);
            pattern = pattern.Replace(@"[extension]", _fileGroup.BaseExtension);
            // AJ CHANGE
            pattern = pattern.Replace(@"[optionaldefaulttypes]", _fileGroup.BaseOptionalDefaultType);

            newFileNameTextBox.Text = pattern;
        }
示例#15
0
        public bool HasLanguageCode(CultureInfo cultureInfo)
        {
            var lcd = new LanguageCodeDetection(Project);

            // ReSharper disable LoopCanBeConvertedToQuery
            foreach (var filePath in FilePaths)
            // ReSharper restore LoopCanBeConvertedToQuery
            {
                var ci = lcd.DetectCultureFromFileName(
                    ParentSettings,
                    filePath);

                if (string.Compare(ci.Name, cultureInfo.Name, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return(true);
                }
            }

            return(false);
        }
示例#16
0
        string[] IGridEditableData.GetLanguageCodes(Project project)
        {
            var result = new Set <string>();

            foreach (var filePath in ((IGridEditableData)this).FilePaths)
            {
                var lc =
                    new LanguageCodeDetection(
                        ((IGridEditableData)this).Project).DetectLanguageCodeFromFileName(
                        ((IGridEditableData)this).ParentSettings,
                        filePath);

                if (!string.IsNullOrEmpty(lc))
                {
                    result.Add(lc.ToLowerInvariant());
                }
            }

            return(result.ToArray());
        }
示例#17
0
        public string[] GetLanguageCodes(
            Project project)
        {
            var result = new HashSet <string>();

            foreach (var filePath in FilePaths)
            {
                var lc =
                    new LanguageCodeDetection(project).DetectLanguageCodeFromFileName(
                        ParentSettings,
                        filePath);

                if (!string.IsNullOrEmpty(lc))
                {
                    result.Add(lc.ToLowerInvariant());
                }
            }

            return(result.ToArray());
        }
示例#18
0
        private bool checkWantAddResourceFile(
            ZlpFileInfo filePath)
        {
            if (filePath == null)
            {
                return(false);
            }
            else
            {
                if (string.Compare(@"Properties", filePath.Directory.Name, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return(true);
                }
                else
                {
                    // If a "*.Designer.*" companion file exists, assume it
                    // is a Windows Forms resource file and do NOT add the file
                    // since it can be translated directly from within VS.NET.

                    if (Project.IgnoreWindowsFormsResourcesWithDesignerFiles)
                    {
                        var baseFileName =
                            LanguageCodeDetection.GetBaseName(
                                Project,
                                filePath.Name);
                        //filePath.Name.Substring(0, filePath.Name.IndexOf('.'));

                        var files =
                            filePath.Directory.GetFiles(
                                string.Format(@"{0}.Designer.*", baseFileName));

                        return(files.Length <= 0);
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
        }
示例#19
0
        private void parseLanguageCode()
        {
            var languageCodes =
                CommandProcessorReceive.DetectLanguagesFromExcelFile(
                    sourceFileTextEdit.Text.Trim());

            languagesToImportCheckListBox.Items.Clear();

            if (languageCodes != null)
            {
                foreach (var languageCode in languageCodes)
                {
                    if (!string.IsNullOrEmpty(languageCode) &&
                        LanguageCodeDetection.IsValidCultureName(languageCode))
                    {
                        var index = languagesToImportCheckListBox.Items.Add(
                            new Pair <string, string>(
                                string.Format(
                                    @"{0} ({1})",
                                    CultureInfo.GetCultureInfo(languageCode).DisplayName,
                                    languageCode),
                                languageCode));

                        languagesToImportCheckListBox.SetItemChecked(index, true);
                    }
                }
            }

            // --
            // Try to restore.

            DevExpressExtensionMethods.RestoreSettings(
                languagesToImportCheckListBox,
                _project.DynamicSettingsGlobalHierarchical,
                @"receiveFileFromTranslator.languagesToImportCheckListBox");
        }
示例#20
0
        public FileInformation GetFileByLanguageCode(
            Project project,
            string languageCode)
        {
            lock (_fileInfos)
            {
                // ReSharper disable LoopCanBeConvertedToQuery
                foreach (var ffi in _fileInfos)
                // ReSharper restore LoopCanBeConvertedToQuery
                {
                    var lc = new LanguageCodeDetection(project).DetectLanguageCodeFromFileName(
                        ParentSettings,
                        ffi.File.FullName);

                    if (string.Compare(languageCode, lc, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        return(ffi);
                    }
                }

                // Not found.
                return(null);
            }
        }
        /// <summary>
        /// Create the data table for the grid.
        /// </summary>
        private DataTable getTable(
            Project project,
            bool forceCommentColumn)
        {
            // Load File from filesystem
            loadFiles();

            var table = new DataTable();

            // Add primary key columns.
            table.Columns.Add(
                new DataColumn
            {
                ColumnName = @"FileGroup",
                Caption    = Resources.SR_ColumnCaption_FileGroup,
            });
            table.Columns.Add(
                new DataColumn
            {
                ColumnName = @"Name",
                Caption    = Resources.SR_ColumnCaption_Name,
            });
            table.PrimaryKey =
                new[]
            {
                table.Columns[@"FileGroup"],
                table.Columns[@"Name"]
            };

            // AJ CHANGE

            // Add a Column for each filename
            foreach (var resxFile in _resxFiles)
            {
                var cn = resxFile.FilePath.Name;

                var culture =
                    new LanguageCodeDetection(
                        _gridEditableData.Project)
                    .DetectCultureFromFileName(
                        _gridEditableData.ParentSettings,
                        cn);

                var cultureCaption =
                    $@"{culture.DisplayName} ({culture.Name})";

                //Member 802361: only file names are loaded if same culture is not added first. there are no references any more to other files with same culture. So we name each column by culture and not by file name.
                //TODO: please check if no side effects elsewere
                if (!containsCaption(table.Columns, cultureCaption))
                {
                    var column =
                        new DataColumn(culture.Name)
                    {
                        Caption = cultureCaption
                    };
                    table.Columns.Add(column);
                }
            }

            if (GetShowCommentColumn(project) || forceCommentColumn)
            {
                table.Columns.Add(
                    new DataColumn
                {
                    ColumnName = @"Comment",
                    Caption    = Resources.SR_ColumnCaption_Comment
                });
            }

            // --

            // Add rows and fill them with data
            foreach (var resxFile in _resxFiles)
            {
                var fgcs = resxFile.FileInformation.FileGroup.GetChecksum(project);
                var cn   = resxFile.FilePath.Name;

                var culture =
                    new LanguageCodeDetection(
                        _gridEditableData.Project)
                    .DetectCultureFromFileName(
                        _gridEditableData.ParentSettings,
                        cn);

                var cultureCaption =
                    $@"{culture.DisplayName} ({culture.Name})";

                var doc  = resxFile.Document;
                var data = doc.GetElementsByTagName(@"data");

                var captionIndexCache = new Dictionary <string, int>();

                // Each "data" node of the XML document is processed
                foreach (XmlNode node in data)
                {
                    var process = node.Attributes?[@"type"] == null;

                    //skip mimetype like application/x-microsoft.net.object.binary.base64
                    // http://www.codeproject.com/KB/aspnet/ZetaResourceEditor.aspx?msg=3367544#xx3367544xx
                    if (node.Attributes?[@"mimetype"] != null)
                    {
                        process = false;
                    }

                    if (process)
                    {
                        // Get value of the "name" attribute
                        // and look for it in the datatable
                        var name = node.Attributes == null ? string.Empty : node.Attributes[@"name"].Value;
                        var row  = table.Rows.Find(new object[] { fgcs, name });

                        // Fixes the "value of second file displayed in first column" bug_.
                        if (row == null)
                        {
                            table.Rows.Add(fgcs, name);
                            row = table.Rows.Find(new object[] { fgcs, name });

                            // AJ CHANGE
                            if (GetShowCommentColumn(project) || forceCommentColumn)
                            {
                                var comment = node.SelectSingleNode(@"comment");
                                if (comment != null)
                                {
                                    row[@"Comment"] =
                                        string.IsNullOrEmpty(comment.InnerText)
                                            ? string.Empty
                                            : AdjustLineBreaks(comment.InnerText);
                                    row.AcceptChanges();
                                }
                            }
                        }

                        var value = node.SelectSingleNode(@"value");

                        if (value != null)
                        {
                            setAtCultureCaption(
                                captionIndexCache,
                                table.Columns,
                                row,
                                cultureCaption,
                                string.IsNullOrEmpty(value.InnerText)
                                    ? string.Empty
                                    : AdjustLineBreaks(value.InnerText));
                            row.AcceptChanges();
                        }
                    }
                }
            }

            return(table);
        }
		private void updateNewFileNameFromLanguage()
		{
			var culture =
				((Pair<string, CultureInfo>)newLanguageComboBox.SelectedItem).Second;

			var pattern =
				new LanguageCodeDetection(MainForm.Current.ProjectFilesControl.Project ?? Project.Empty).IsNeutralCulture(
				_fileGroup.ParentSettings,
					culture)
					? (MainForm.Current.ProjectFilesControl.Project ?? Project.Empty).NeutralLanguageFileNamePattern
					: (MainForm.Current.ProjectFilesControl.Project ?? Project.Empty).NonNeutralLanguageFileNamePattern;

			pattern = pattern.Replace(@"[basename]", _fileGroup.BaseName);
			pattern = pattern.Replace(@"[languagecode]", ((Pair<string, CultureInfo>)newLanguageComboBox.SelectedItem).Second.Name);
			pattern = pattern.Replace(@"[extension]", _fileGroup.BaseExtension);
			// AJ CHANGE 
			pattern = pattern.Replace(@"[optionaldefaulttypes]", _fileGroup.BaseOptionalDefaultType);

			newFileNameTextBox.Text = pattern;
		}
示例#23
0
        // ADDED: adds resources from file Info lists.
        // I have changed a method doAutomaticallyAddResourceFiles to fill file groups.
        // You can use same method if you call this method from there.
        // ATTENTION: LanguageCodeDetection was modified a bit to support variable amount
        // of point in base name. New method GetBaseName(IInheritedSettings settings, string fileName)
        // was added to get same base name FileGroup gets.
        public void DoAutomaticallyAddResourceFilesFromList(
            BackgroundWorker backgroundWorker,
            ProjectFolder parentProjectFolder,
            ref int fileGroupCount,
            ref int fileCount,
            ICollection <ZlpFileInfo> fileList)
        {
            if (backgroundWorker.CancellationPending)
            {
                throw new OperationCanceledException();
            }
            else if (fileList != null && fileList.Count > 0)
            {
                var fileGroups = Project.FileGroups;
                //if (parentProjectFolder != null)
                //{
                //    fileGroups = parentProjectFolder.ChildFileGroups;
                //}
                foreach (var filePath in fileList)
                {
                    if (backgroundWorker.CancellationPending)
                    {
                        throw new OperationCanceledException();
                    }
                    //other algorithm to determine base name to allow multiple points inside name
                    var baseFileName = LanguageCodeDetection.GetBaseName(Project, filePath.Name);

                    var wantAddResourceFile =
                        checkWantAddResourceFile(filePath);

                    if (wantAddResourceFile)
                    {
                        //find right file group

                        var path      = filePath;
                        var fileGroup = fileGroups.Find(
                            g =>
                            string.Compare(g.BaseName, baseFileName, StringComparison.OrdinalIgnoreCase) == 0 &&
                            string.Compare(g.FolderPath.FullName, path.Directory.FullName,
                                           StringComparison.OrdinalIgnoreCase) == 0);

                        if (fileGroup == null)
                        {
                            fileGroup =
                                new FileGroup(Project)
                            {
                                ProjectFolder = parentProjectFolder
                            };

                            // Look for same entries.
                            if (!Project.FileGroups.HasFileGroupWithChecksum(
                                    fileGroup.GetChecksum(Project)))
                            {
                                fileGroups.Add(fileGroup);

                                fileGroupCount++;
                            }
                        }

                        fileGroup.Add(
                            new FileInformation(fileGroup)
                        {
                            File = filePath
                        });

                        fileCount++;
                    }
                }
            }
        }
		private void mainGridView_ShownEditor(object sender, EventArgs e)
		{
			var project = MainForm.Current.ProjectFilesControl.Project ?? Project.Empty;

			if (project != null && project.UseSpellChecker)
			{
				var name = mainGridView.FocusedColumn.Caption;
				var culture = new LanguageCodeDetection(project).DetectCultureFromFileName(
					GridEditableData.ParentSettings,
					name);

				SpellChecker gridSpellChecker;
				if (!_gridSpellCheckers.TryGetValue(culture, out gridSpellChecker))
				{
					gridSpellChecker = CultureHelper.CreateSpellChecker(culture);
					if (gridSpellChecker != null)
					{
						gridSpellChecker.ParentContainer = mainDataGrid;
					}

					_gridSpellCheckers[culture] = gridSpellChecker;
				}

				if (gridSpellChecker != null)
				{
					gridSpellChecker.SetShowSpellCheckMenu(
					   mainGridView.ActiveEditor,
					   true);
				}
			}
		}
        protected override void InitiallyFillLists()
        {
            base.InitiallyFillLists();

            var infos = new List <TranslationLanguageInfo>();

            TranslationHelper.GetTranslationAppID(
                MainForm.Current.ProjectFilesControl.Project ?? Project.Empty,
                out var appID);

            var ti = TranslationHelper.GetTranslationEngine(_project);

            TranslationLanguageInfo[] lcs;

            //try
            //{
            lcs = ti.AreAppIDsSyntacticallyValid(appID)
                ? ti.GetSourceLanguages(appID)
                : new TranslationLanguageInfo[] { };
            //}
            //catch (Exception e) when (e is WebException || e is HttpException)
            //{
            //    // Hier Exception nicht durchlassen,
            //    // Damit der Dialog nicht undefiniert gefüllt ist.

            //    LogCentral.Current.Warn(e);

            //    lcs = new TranslationLanguageInfo[] { };

            //    Host.NotifyAboutException(e);
            //}

            foreach (var languageCode in languageCodes)
            {
                // Only translate those that are supported.
                if (TranslationHelper.IsSupportedLanguage(languageCode, lcs))
                {
                    if (string.IsNullOrEmpty(languageCode))
                    {
                        infos.Add(
                            new TranslationLanguageInfo
                        {
                            UserReadableName = Resources.SR_TranslationHelper_GetSourceLanguages_AutoDetect,
                            LanguageCode     = string.Empty
                        });
                    }
                    else
                    {
                        infos.Add(
                            new TranslationLanguageInfo
                        {
                            UserReadableName =
                                $@"{
                                            LanguageCodeDetection.MakeValidCulture(languageCode).DisplayName
                                        } ({languageCode})",
                            LanguageCode = languageCode
                        });
                    }
                }
            }

            infos.Sort((x, y) => string.CompareOrdinal(x.UserReadableName, y.UserReadableName));

            referenceLanguageGroupBox.Properties.Items.Clear();
            foreach (var info in infos)
            {
                referenceLanguageGroupBox.Properties.Items.Add(info);
            }

            // --
            // Select defaults.

            _ignore = true;
            if (referenceLanguageGroupBox.SelectedIndex < 0 &&
                referenceLanguageGroupBox.Properties.Items.Count > 0)
            {
                referenceLanguageGroupBox.SelectedIndex = 0;
            }

            _ignore = false;
        }
		private void addDetailTabPage(
			ILanguageColumnFilter filter,
			int imageIndex,
			string name,
			string languageCode)
		{
			var tabPage =
				new XtraTabPage
					{
						Text = name,
						ImageIndex = imageIndex,
					};
			tabControl1.TabPages.Add(tabPage);

			if (!string.IsNullOrEmpty(languageCode))
			{
				if (filter != null && !filter.WantDisplayLanguageColumnInGrid(languageCode))
				{
					tabPage.PageVisible = false;
				}
			}

			var textBox = new MemoEdit();
			textBox.TextChanged += textBox_TextChanged;
			textBox.KeyDown += textBox_KeyDown;
			textBox.Name = @"ColumnText";
			tabPage.Controls.Add(textBox);

			if (!StringExtensionMethods.IsNullOrWhiteSpace(languageCode))
			{
				var isRtl = CultureHelper.CreateCultureErrorTolerant(languageCode).TextInfo.IsRightToLeft;
				if (isRtl)
				{
					textBox.RightToLeft = RightToLeft.Yes;
				}
			}

			textBox.Properties.AcceptsReturn = true;
			textBox.Properties.AcceptsTab = true;
			textBox.AllowDrop = true;
			textBox.Dock = DockStyle.Fill;
			textBox.Properties.HideSelection = false;
			textBox.Properties.ScrollBars = ScrollBars.Vertical;
			textBox.TabIndex = 0;

			// --
			// Spell checker.

			var project = MainForm.Current.ProjectFilesControl.Project ?? Project.Empty;

			if (project != null && project.UseSpellChecker)
			{
				var culture =
					new LanguageCodeDetection(project).DetectCultureFromFileName(
					GridEditableData.ParentSettings,
					name);

				var spellChecker = CultureHelper.CreateSpellChecker(culture);
				if (spellChecker != null)
				{
					spellChecker.ParentContainer = textBox;
					spellChecker.SetShowSpellCheckMenu(textBox, true);
				}
			}
		}
        protected override void InitiallyFillLists()
        {
            base.InitiallyFillLists();

            var infos = new List <TranslationLanguageInfo>();

            string appID;
            string appID2;

            TranslationHelper.GetTranslationAppID(
                MainForm.Current.ProjectFilesControl.Project ?? Project.Empty,
                out appID,
                out appID2);

            var ti = TranslationHelper.GetTranslationEngine(_project);

            var lcs =
                ti.AreAppIDsSyntacticallyValid(appID, appID2)
                    ? ti.GetSourceLanguages(appID, appID2)
                    : new TranslationLanguageInfo[] { };

            foreach (var languageCode in languageCodes)
            {
                // Only translate those that are supported.
                if (TranslationHelper.IsSupportedLanguage(languageCode, lcs))
                {
                    if (string.IsNullOrEmpty(languageCode))
                    {
                        infos.Add(
                            new TranslationLanguageInfo
                        {
                            UserReadableName = Resources.SR_TranslationHelper_GetSourceLanguages_AutoDetect,
                            LanguageCode     = string.Empty
                        });
                    }
                    else
                    {
                        infos.Add(
                            new TranslationLanguageInfo
                        {
                            UserReadableName =
                                $@"{
                                        LanguageCodeDetection.MakeValidCulture(languageCode).DisplayName
                                    } ({languageCode})",
                            LanguageCode = languageCode
                        });
                    }
                }
            }

            infos.Sort((x, y) => string.CompareOrdinal(x.UserReadableName, y.UserReadableName));

            referenceLanguageGroupBox.Properties.Items.Clear();
            foreach (var info in infos)
            {
                referenceLanguageGroupBox.Properties.Items.Add(info);
            }

            // --
            // Select defaults.

            _ignore = true;
            if (referenceLanguageGroupBox.SelectedIndex < 0 &&
                referenceLanguageGroupBox.Properties.Items.Count > 0)
            {
                referenceLanguageGroupBox.SelectedIndex = 0;
            }
            _ignore = false;
        }
示例#28
0
        public string GetNameIntelligent(
            Project project)
        {
            lock (_fileInfos)
            {
                if (string.IsNullOrEmpty(_name) && _fileInfos.Count > 0)
                {
                    // Try guessing several names.

                    var filePath   = _fileInfos[0].File;
                    var folderPath = filePath.Directory;

                    //CHANGED: use base name instead
                    var baseName = LanguageCodeDetection.GetBaseName(project, filePath.Name);
                    filePath = new ZlpFileInfo(ZlpPathHelper.Combine(folderPath.FullName, baseName));

                    if ((string.Equals(@"Properties", folderPath.Name,
                                       StringComparison.InvariantCultureIgnoreCase) ||
                         string.Equals(@"App_GlobalResources", folderPath.Name,
                                       StringComparison.InvariantCultureIgnoreCase)) &&
                        filePath.Name.StartsWith(
                            @"Resources.", StringComparison.InvariantCultureIgnoreCase))
                    {
                        var parentFolderPath = folderPath.Parent;
                        if (parentFolderPath == null)
                        {
                            return(_name);
                        }
                        else
                        {
                            //CHANGED: append fileName, otherwise name is not complete.
                            var pathToMakeRelative = ZlpPathHelper.Combine(parentFolderPath.FullName, filePath.Name);
                            return
                                (shortenFilePath(
                                     ZlpPathHelper.GetRelativePath(
                                         project == null
                                            ? string.Empty
                                            : project.ProjectConfigurationFilePath.DirectoryName,
                                         pathToMakeRelative)));
                        }
                    }
                    else if (string.Equals(@"App_LocalResources", folderPath.Name,
                                           StringComparison.InvariantCultureIgnoreCase))
                    {
                        var name =
                            ZlpPathHelper.GetRelativePath(
                                project == null
                                    ? string.Empty
                                    : project.ProjectConfigurationFilePath.DirectoryName,
                                filePath.FullName);

                        var ext    = ZlpPathHelper.GetExtension(name);
                        var result = name.Substring(0, name.Length - ext.Length);

                        return(shortenFilePath(result));
                    }
                    else
                    {
                        return
                            (shortenFilePath(
                                 ZlpPathHelper.GetRelativePath(
                                     project == null
                                        ? string.Empty
                                        : project.ProjectConfigurationFilePath.DirectoryName,
                                     filePath.FullName)));
                    }
                }
                else
                {
                    return(_name);
                }
            }
        }
		/// <summary>
		/// Store the changes in the data table back to the .RESX files
		/// </summary>
		private void saveTable(
			Project project,
			DataTable table,
			bool wantBackupFiles,
			bool omitEmptyStrings)
		{
			var index = 0;
			var languageCodeDetection = new LanguageCodeDetection(_gridEditableData.Project);

			foreach (var resxFile in _resxFiles)
			{
				try
				{
					var checksum = resxFile.FileInformation.FileGroup.GetChecksum(project);
					var document = resxFile.Document;
					var fileName = resxFile.FilePath.Name;

					//Member 802361: access value by culture and not by filename
					var culture =
						languageCodeDetection.DetectLanguageCodeFromFileName(
							_gridEditableData.Project,
							fileName);

					// 2011-04-09, Uwe Keim: "nb" => "nb-NO".
					var cultureLong = LanguageCodeDetection.MakeValidCulture(culture).Name;

					foreach (DataRow row in table.Rows)
					{
						if (row.RowState != DataRowState.Deleted)
						{
							if (!FileGroup.IsInternalRow(row))
							{
								var fileGroupCheckSum = ConvertHelper.ToInt64(row[@"FileGroup"]);

								// 2010-10-23, Uwe Keim: Only save if same file group.
								if (fileGroupCheckSum == checksum)
								{
									var tagName = (string)row[@"Name"];

									var xpathQuery =
										string.Format(
											@"child::data[attribute::name='{0}']",
											escapeXsltChars(tagName));

									if (document.DocumentElement != null)
									{
										var node = document.DocumentElement.SelectSingleNode(xpathQuery);
										var found = node != null;

										var content = row[cultureLong] as string;
										var textToSet = content ?? string.Empty;

										var commentsAreVisible =
											CommentsAreVisible(project, row, CommentVisibilityScope.InMemory);

										// AJ CHANGE
										var commentToSet =
											commentsAreVisible
												? row[@"Comment"] == DBNull.Value
													? string.Empty
													: (string)row[@"Comment"]
												: null;

										if (found)
										{
											var n = node.SelectSingleNode(@"value");

											//CHANGED: 	Member 802361 if content is null remove this entry
											if (content != null &&
												(!string.IsNullOrEmpty(textToSet) || !omitEmptyStrings))
											{
												// If not present (for whatever reason, e.g. 
												// manually edited and therefore misformed).
												if (n == null)
												{
													n = document.CreateElement(@"value");
													node.AppendChild(n);
												}

												n.InnerText = textToSet;

												// AJ CHANGE
												// Only write the comment to the main resx file
												if (commentsAreVisible)
												{
													if (resxFile == _resxFiles[0])
													{
														n = node.SelectSingleNode(@"comment");
														// If not present (for whatever reason, e.g. 
														// manually edited and therefore misformed).
														if (n == null)
														{
															n = document.CreateElement(@"comment");
															node.AppendChild(n);
														}

														n.InnerText = commentToSet ?? string.Empty;
													}
												}
											}
											else
											{
												if (n != null)
												{
													node.RemoveChild(n);
												}

												if (node.ParentNode != null)
												{
													node.ParentNode.RemoveChild(node);
												}
											}
										}
										else // Resource doesn't exist in XML.
										{
											if (content != null &&
												(!string.IsNullOrEmpty(textToSet) || !omitEmptyStrings))
											{
												// Member 802361: only do it if editing single fileGroup. 
												// If no we don't know where to add the new entry.
												// TODO: may be add to default file in the list?
												if (_gridEditableData.FileGroup == null)
												{
													//look if base file has same tagName
													//if base file skip it
													if (string.Compare(
														_gridEditableData.Project.NeutralLanguageCode,
														culture,
														true) == 0 ||
													    string.Compare(
													    	_gridEditableData.Project.NeutralLanguageCode,
													    	cultureLong,
													    	true) == 0)
													{
														continue;
													}

													// 2011-01-26, Uwe Keim:
													var pattern =
														resxFile.FileInformation.FileGroup.ParentSettings.EffectiveNeutralLanguageFileNamePattern;
													pattern = pattern.Replace(@"[basename]", resxFile.FileInformation.FileGroup.BaseName);
													pattern = pattern.Replace(@"[languagecode]", project.NeutralLanguageCode);
													pattern = pattern.Replace(@"[extension]", resxFile.FileInformation.FileGroup.BaseExtension);
													pattern = pattern.Replace(@"[optionaldefaulttypes]",
													                          resxFile.FileInformation.FileGroup.BaseOptionalDefaultType);

													//has base culture value?
													var baseName = pattern;

													// 2011-01-26, Uwe Keim:
													var file = resxFile;
													var baseResxFile =
														_resxFiles.Find(
															resx =>
															resx.FilePath.Name == baseName &&
															resx.FileInformation.FileGroup.UniqueID ==
															file.FileInformation.FileGroup.UniqueID);
													if (baseResxFile == null ||
													    baseResxFile.Document == null ||
													    baseResxFile.Document.DocumentElement == null)
													{
														continue;
													}

													var baseNode =
														baseResxFile.Document.DocumentElement.
															SelectSingleNode(xpathQuery);
													if (null == baseNode)
													{
														continue;
													}
													//ok we can add it.
												}
												//TODO: use default instead

												//Create the new Node
												XmlNode newData = document.CreateElement(@"data");
												var newName = document.CreateAttribute(@"name");
												var newSpace = document.CreateAttribute(@"xml:space");
												XmlNode newValue = document.CreateElement(@"value");

												// Set the Values
												newName.Value = (string)row[@"Name"];
												newSpace.Value = @"preserve";
												newValue.InnerText = textToSet;

												// Get them together
												if (newData.Attributes != null)
												{
													newData.Attributes.Append(newName);
													newData.Attributes.Append(newSpace);
												}
												newData.AppendChild(newValue);

												// AJ CHANGE
												// Only write the comment to the main resx file
												if (commentsAreVisible && index == 0)
												{
													XmlNode newComment = document.CreateElement(@"comment");
													newComment.InnerText = commentToSet ?? string.Empty;
													newData.AppendChild(newComment);
												}

												XmlNode root = document.DocumentElement;
												if (root != null)
												{
													root.InsertAfter(newData, root.LastChild);
												}
											}
										}
									}
								}
							}
						}
					}
				}
				finally
				{
					index++;
				}
			}

			if (wantBackupFiles)
			{
				backupFiles();
			}

			// Store files back to filesystem
			storeFiles();
		}
        /// <summary>
        /// Store the changes in the data table back to the .RESX files
        /// </summary>
        private void saveTable(
            Project project,
            DataTable table,
            bool wantBackupFiles,
            bool omitEmptyStrings)
        {
            var index = 0;
            var languageCodeDetection = new LanguageCodeDetection(_gridEditableData.Project);

            foreach (var resxFile in _resxFiles)
            {
                try
                {
                    var checksum = resxFile.FileInformation.FileGroup.GetChecksum(project);
                    var document = resxFile.Document;
                    var fileName = resxFile.FilePath.Name;

                    //Member 802361: access value by culture and not by filename
                    var culture =
                        languageCodeDetection.DetectLanguageCodeFromFileName(
                            _gridEditableData.Project,
                            fileName);

                    // 2011-04-09, Uwe Keim: "nb" => "nb-NO".
                    var cultureLong = LanguageCodeDetection.MakeValidCulture(culture).Name;

                    foreach (DataRow row in table.Rows)
                    {
                        if (row.RowState != DataRowState.Deleted)
                        {
                            if (!FileGroup.IsInternalRow(row))
                            {
                                var fileGroupCheckSum = ConvertHelper.ToInt64(row[@"FileGroup"]);

                                // 2010-10-23, Uwe Keim: Only save if same file group.
                                if (fileGroupCheckSum == checksum)
                                {
                                    var tagName = (string)row[@"Name"];

                                    var xpathQuery = $@"child::data[attribute::name='{escapeXsltChars(tagName)}']";

                                    if (document.DocumentElement != null)
                                    {
                                        var node  = document.DocumentElement.SelectSingleNode(xpathQuery);
                                        var found = node != null;

                                        var content   = row[cultureLong] as string;
                                        var textToSet = content ?? string.Empty;

                                        var commentsAreVisible =
                                            CommentsAreVisible(project, row, CommentVisibilityScope.InMemory);

                                        // AJ CHANGE
                                        var commentToSet =
                                            commentsAreVisible
                                                ? row[@"Comment"] == DBNull.Value
                                                    ? string.Empty
                                                    : (string)row[@"Comment"]
                                                : null;

                                        if (found)
                                        {
                                            var n = node.SelectSingleNode(@"value");

                                            //CHANGED:  Member 802361 if content is null remove this entry
                                            if (content != null &&
                                                (!string.IsNullOrEmpty(textToSet) || !omitEmptyStrings))
                                            {
                                                // If not present (for whatever reason, e.g.
                                                // manually edited and therefore misformed).
                                                if (n == null)
                                                {
                                                    n = document.CreateElement(@"value");
                                                    node.AppendChild(n);
                                                }

                                                n.InnerText = textToSet;

                                                // AJ CHANGE
                                                // Only write the comment to the main resx file
                                                if (commentsAreVisible)
                                                {
                                                    if (resxFile == _resxFiles[0])
                                                    {
                                                        n = node.SelectSingleNode(@"comment");
                                                        // If not present (for whatever reason, e.g.
                                                        // manually edited and therefore misformed).
                                                        if (n == null)
                                                        {
                                                            n = document.CreateElement(@"comment");
                                                            node.AppendChild(n);
                                                        }

                                                        n.InnerText = commentToSet ?? string.Empty;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (n != null)
                                                {
                                                    node.RemoveChild(n);
                                                }

                                                node.ParentNode?.RemoveChild(node);
                                            }
                                        }
                                        else // Resource doesn't exist in XML.
                                        {
                                            if (content != null &&
                                                (!string.IsNullOrEmpty(textToSet) || !omitEmptyStrings))
                                            {
                                                // Member 802361: only do it if editing single fileGroup.
                                                // If no we don't know where to add the new entry.
                                                // TODO: may be add to default file in the list?
                                                if (_gridEditableData.FileGroup == null)
                                                {
                                                    //look if base file has same tagName
                                                    //if base file skip it
                                                    if (string.Compare(
                                                            _gridEditableData.Project.NeutralLanguageCode,
                                                            culture,
                                                            StringComparison.OrdinalIgnoreCase) == 0 ||
                                                        string.Compare(
                                                            _gridEditableData.Project.NeutralLanguageCode,
                                                            cultureLong,
                                                            StringComparison.OrdinalIgnoreCase) == 0)
                                                    {
                                                        continue;
                                                    }

                                                    // 2011-01-26, Uwe Keim:
                                                    var pattern =
                                                        resxFile.FileInformation.FileGroup.ParentSettings
                                                        .EffectiveNeutralLanguageFileNamePattern;
                                                    pattern =
                                                        pattern.Replace(@"[basename]",
                                                                        resxFile.FileInformation.FileGroup.BaseName);
                                                    pattern =
                                                        pattern.Replace(@"[languagecode]", project.NeutralLanguageCode);
                                                    pattern =
                                                        pattern.Replace(@"[extension]",
                                                                        resxFile.FileInformation.FileGroup.BaseExtension);
                                                    pattern = pattern.Replace(@"[optionaldefaulttypes]",
                                                                              resxFile.FileInformation.FileGroup.BaseOptionalDefaultType);

                                                    //has base culture value?
                                                    var baseName = pattern;

                                                    // 2011-01-26, Uwe Keim:
                                                    var file         = resxFile;
                                                    var baseResxFile =
                                                        _resxFiles.Find(
                                                            resx =>
                                                            resx.FilePath.Name == baseName &&
                                                            resx.FileInformation.FileGroup.UniqueID ==
                                                            file.FileInformation.FileGroup.UniqueID);

                                                    var baseNode =
                                                        baseResxFile?.Document?.DocumentElement
                                                        ?.SelectSingleNode(xpathQuery);
                                                    if (baseNode == null)
                                                    {
                                                        continue;
                                                    }
                                                    //ok we can add it.
                                                }
                                                //TODO: use default instead

                                                //Create the new Node
                                                XmlNode newData  = document.CreateElement(@"data");
                                                var     newName  = document.CreateAttribute(@"name");
                                                var     newSpace = document.CreateAttribute(@"xml:space");
                                                XmlNode newValue = document.CreateElement(@"value");

                                                // Set the Values
                                                newName.Value      = (string)row[@"Name"];
                                                newSpace.Value     = @"preserve";
                                                newValue.InnerText = textToSet;

                                                // Get them together
                                                if (newData.Attributes != null)
                                                {
                                                    newData.Attributes.Append(newName);
                                                    newData.Attributes.Append(newSpace);
                                                }
                                                newData.AppendChild(newValue);

                                                // AJ CHANGE
                                                // Only write the comment to the main resx file
                                                if (commentsAreVisible && index == 0)
                                                {
                                                    XmlNode newComment = document.CreateElement(@"comment");
                                                    newComment.InnerText = commentToSet ?? string.Empty;
                                                    newData.AppendChild(newComment);
                                                }

                                                XmlNode root = document.DocumentElement;
                                                root?.InsertAfter(newData, root.LastChild);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                finally
                {
                    index++;
                }
            }

            if (wantBackupFiles)
            {
                backupFiles();
            }

            // Store files back to filesystem
            storeFiles(project);
        }
		private static string generateFileName(
			FileGroup fileGroup,
			CultureInfo culture)
		{
			var pattern =
				new LanguageCodeDetection(fileGroup.Project).IsNeutralCulture(
					fileGroup.ParentSettings,
					culture)
					? fileGroup.Project.NeutralLanguageFileNamePattern
					: fileGroup.Project.NonNeutralLanguageFileNamePattern;

			pattern = pattern.Replace(@"[basename]", fileGroup.BaseName);
			pattern = pattern.Replace(@"[languagecode]", culture.Name);
			pattern = pattern.Replace(@"[extension]", fileGroup.BaseExtension);
			pattern = pattern.Replace(@"[optionaldefaulttypes]", fileGroup.BaseOptionalDefaultType);

			return pattern;
		}
		/// <summary>
		/// Create the data table for the grid.
		/// </summary>
		private DataTable getTable(
			Project project,
			bool forceCommentColumn)
		{
			// Load File from filesystem
			loadFiles();

			var table = new DataTable();

			// Add primary key columns.
			table.Columns.Add(
				new DataColumn
					{
						ColumnName = @"FileGroup",
						Caption = Resources.SR_ColumnCaption_FileGroup,
					});
			table.Columns.Add(
				new DataColumn
				{
					ColumnName = @"Name",
					Caption = Resources.SR_ColumnCaption_Name,
				});
			table.PrimaryKey =
				new[]
					{
						table.Columns[@"FileGroup"],
						table.Columns[@"Name"]
					};

			// AJ CHANGE

			// Add a Column for each filename
			foreach (var resxFile in _resxFiles)
			{
				var cn = resxFile.FilePath.Name;

				var culture =
					new LanguageCodeDetection(
						_gridEditableData.Project)
						.DetectCultureFromFileName(
							_gridEditableData.ParentSettings,
							cn);

				var cultureCaption =
					string.Format(
						@"{0} ({1})",
						culture.DisplayName,
						culture.Name);

				//Member 802361: only file names are loaded if same culture is not added first. there are no references any more to other files with same culture. So we name each column by culture and not by file name.
				//TODO: please check if no side effects elsewere
				if (!containsCaption(table.Columns, cultureCaption))
				{
					var column =
						new DataColumn(culture.Name)
							{
								Caption = cultureCaption
							};
					table.Columns.Add(column);
				}
			}

			if (GetShowCommentColumn(project) || forceCommentColumn)
			{
				table.Columns.Add(
					new DataColumn
						{
							ColumnName = @"Comment",
							Caption = Resources.SR_ColumnCaption_Comment
						});
			}

			// --

			// Add rows and fill them with data
			foreach (var resxFile in _resxFiles)
			{
				var fgcs = resxFile.FileInformation.FileGroup.GetChecksum(project);
				var cn = resxFile.FilePath.Name;

				var culture =
					new LanguageCodeDetection(
						_gridEditableData.Project)
						.DetectCultureFromFileName(
							_gridEditableData.ParentSettings,
							cn);

				var cultureCaption =
					string.Format(
						@"{0} ({1})",
						culture.DisplayName,
						culture.Name);

				var doc = resxFile.Document;
				var data = doc.GetElementsByTagName(@"data");

				var captionIndexCache = new Dictionary<string, int>();

				// Each "data" node of the XML document is processed
				foreach (XmlNode node in data)
				{
					var process = true;

					//Check if this is a non string data tag
					if (node.Attributes != null && node.Attributes[@"type"] != null)
					{
						process = false;
					}

					//skip mimetype like application/x-microsoft.net.object.binary.base64
					// http://www.codeproject.com/KB/aspnet/ZetaResourceEditor.aspx?msg=3367544#xx3367544xx
					if (node.Attributes != null && node.Attributes[@"mimetype"] != null)
					{
						process = false;
					}

					if (process)
					{
						// Get value of the "name" attribute 
						// and look for it in the datatable
						var name = node.Attributes == null ? string.Empty : node.Attributes[@"name"].Value;
						var row = table.Rows.Find(new object[] { fgcs, name });

						// Fixes the "value of second file displayed in first column" bug_.
						if (row == null)
						{
							table.Rows.Add(fgcs, name);
							row = table.Rows.Find(new object[] { fgcs, name });

							// AJ CHANGE
							if (GetShowCommentColumn(project) || forceCommentColumn)
							{
								var comment = node.SelectSingleNode(@"comment");
								if (comment != null)
								{
									row[@"Comment"] =
										string.IsNullOrEmpty(comment.InnerText)
											? string.Empty
											: AdjustLineBreaks(comment.InnerText);
									row.AcceptChanges();
								}
							}
						}

						var value = node.SelectSingleNode(@"value");

						if (value != null)
						{
							setAtCultureCaption(
								captionIndexCache,
								table.Columns,
								row,
								cultureCaption,
								string.IsNullOrEmpty(value.InnerText)
									? string.Empty
									: AdjustLineBreaks(value.InnerText));
							row.AcceptChanges();
						}
					}
				}
			}

			return table;
		}