Пример #1
0
        private void writeTransFile(StreamWriter writer, StringList origStrings, StringList transStrings, int dstEncoding)
        {
            int        origIndex      = 0;
            int        transIndex     = 0;
            StringList skippedDialogs = new StringList();
            AccelDict  origAccelDict  = buildAccelDict(origStrings);
            AccelDict  transAccelDict = buildAccelDict(transStrings);

            writer.WriteLine(dstEncoding);
            writeAccel(writer, origAccelDict, transAccelDict);
            while (origIndex < origStrings.Count && transIndex < transStrings.Count)
            {
                while (origIndex < origStrings.Count && origStrings[origIndex].StartsWith("A"))
                {
                    origIndex++;
                }
                if (origIndex >= origStrings.Count)
                {
                    break;
                }
                while (transIndex < transStrings.Count && transStrings[transIndex].StartsWith("A"))
                {
                    transIndex++;
                }
                if (transIndex >= transStrings.Count)
                {
                    break;
                }
                String origString       = origStrings[origIndex];
                String dialogName       = origString.Substring(3, origString.IndexOf(':', 3) - 3);
                String startCheck       = origString.Substring(0, 3) + dialogName;
                int    origDialogCount  = 0;
                int    transDialogCount = 0;
                int    newTransIndex    = findDialog(dialogName, transStrings);

                while (origIndex + origDialogCount < origStrings.Count &&
                       origStrings[origIndex + origDialogCount].StartsWith(startCheck))
                {
                    origDialogCount++;
                }
                if (newTransIndex >= 0)
                {
                    startCheck = transStrings[newTransIndex].Substring(0, 3) + dialogName;
                    while (newTransIndex + transDialogCount < transStrings.Count &&
                           transStrings[newTransIndex + transDialogCount].StartsWith(startCheck))
                    {
                        transDialogCount++;
                    }
                }
                if (origDialogCount == transDialogCount)
                {
                    int i;

                    for (i = 0; i < origDialogCount; i++)
                    {
                        writer.WriteLine(origStrings[origIndex + i]);
                        writer.WriteLine(transStrings[newTransIndex + i]);
                    }
                }
                else
                {
                    StringList origDialogStrings  = new StringList();
                    StringList transDialogStrings = new StringList();
                    int        i;

                    for (i = 0; i < origDialogCount; i++)
                    {
                        origDialogStrings.Add(origStrings[origIndex + i]);
                    }
                    for (i = 0; i < transDialogCount; i++)
                    {
                        transDialogStrings.Add(transStrings[newTransIndex + i]);
                    }
                    MismatchForm mismatchForm  = new MismatchForm(origDialogStrings, transDialogStrings);
                    bool         skippedDialog = true;
                    if (mismatchForm.ShowDialog() == DialogResult.OK)
                    {
                        StringList origDlgStrings;
                        StringList transDlgStrings;

                        if (mismatchForm.getStrings(out origDlgStrings, out transDlgStrings))
                        {
                            for (i = 0; i < origDlgStrings.Count; i++)
                            {
                                writer.WriteLine(origDlgStrings[i]);
                                writer.WriteLine(transDlgStrings[i]);
                            }
                            skippedDialog = false;
                        }
                    }
                    if (skippedDialog)
                    {
                        skippedDialogs.Add(dialogName);
                    }
                }
                origIndex  += origDialogCount;
                transIndex += transDialogCount;
            }
            if (skippedDialogs.Count > 0)
            {
                String message = "The following dialog";

                if (skippedDialogs.Count > 1)
                {
                    message += "s";
                }
                message += "won't be translated due to an unhandled mismatch in the string count:\n";
                for (int i = 0; i < skippedDialogs.Count; i++)
                {
                    message += "\n" + skippedDialogs[i];
                }
                MessageBox.Show(this, message, "Resource Translator", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Пример #2
0
        private void writeTransFile(StreamWriter writer, StringList origStrings, StringList transStrings, int dstEncoding)
        {
            int origIndex = 0;
            int transIndex = 0;
            StringList skippedDialogs = new StringList();
            AccelDict origAccelDict = buildAccelDict(origStrings);
            AccelDict transAccelDict = buildAccelDict(transStrings);

            writer.WriteLine(dstEncoding);
            writeAccel(writer, origAccelDict, transAccelDict);
            while (origIndex < origStrings.Count && transIndex < transStrings.Count)
            {
                while (origIndex < origStrings.Count && origStrings[origIndex].StartsWith("A"))
                {
                    origIndex++;
                }
                if (origIndex >= origStrings.Count)
                {
                    break;
                }
                while (transIndex < transStrings.Count && transStrings[transIndex].StartsWith("A"))
                {
                    transIndex++;
                }
                if (transIndex >= transStrings.Count)
                {
                    break;
                }
                String origString = origStrings[origIndex];
                String dialogName = origString.Substring(3, origString.IndexOf(':', 3) - 3);
                String startCheck = origString.Substring(0, 3) + dialogName;
                int origDialogCount = 0;
                int transDialogCount = 0;
                int newTransIndex = findDialog(dialogName, transStrings);

                while (origIndex + origDialogCount < origStrings.Count &&
                    origStrings[origIndex + origDialogCount].StartsWith(startCheck))
                {
                    origDialogCount++;
                }
                if (newTransIndex >= 0)
                {
                    startCheck = transStrings[newTransIndex].Substring(0, 3) + dialogName;
                    while (newTransIndex + transDialogCount < transStrings.Count &&
                        transStrings[newTransIndex + transDialogCount].StartsWith(startCheck))
                    {
                        transDialogCount++;
                    }
                }
                if (origDialogCount == transDialogCount)
                {
                    int i;

                    for (i = 0; i < origDialogCount; i++)
                    {
                        writer.WriteLine(origStrings[origIndex + i]);
                        writer.WriteLine(transStrings[newTransIndex + i]);
                    }
                }
                else
                {
                    StringList origDialogStrings = new StringList();
                    StringList transDialogStrings = new StringList();
                    int i;

                    for (i = 0; i < origDialogCount; i++)
                    {
                        origDialogStrings.Add(origStrings[origIndex + i]);
                    }
                    for (i = 0; i < transDialogCount; i++)
                    {
                        transDialogStrings.Add(transStrings[newTransIndex + i]);
                    }
                    MismatchForm mismatchForm = new MismatchForm(origDialogStrings, transDialogStrings);
                    bool skippedDialog = true;
                    if (mismatchForm.ShowDialog() == DialogResult.OK)
                    {
                        StringList origDlgStrings;
                        StringList transDlgStrings;

                        if (mismatchForm.getStrings(out origDlgStrings, out transDlgStrings))
                        {
                            for (i = 0; i < origDlgStrings.Count; i++)
                            {
                                writer.WriteLine(origDlgStrings[i]);
                                writer.WriteLine(transDlgStrings[i]);
                            }
                            skippedDialog = false;
                        }
                    }
                    if (skippedDialog)
                    {
                        skippedDialogs.Add(dialogName);
                    }
                }
                origIndex += origDialogCount;
                transIndex += transDialogCount;
            }
            if (skippedDialogs.Count > 0)
            {
                String message = "The following dialog";

                if (skippedDialogs.Count > 1)
                {
                    message += "s";
                }
                message += "won't be translated due to an unhandled mismatch in the string count:\n";
                for (int i = 0; i < skippedDialogs.Count; i++)
                {
                    message += "\n" + skippedDialogs[i];
                }
                MessageBox.Show(this, message, "Resource Translator", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }