예제 #1
0
        public static ProjectStats GatherStats(List <Dialogue> dialogues, Language language, DateTime dateFrom, bool workstringOnly, bool workstringFallback)
        {
            var projectStats = new ProjectStats();

            projectStats.RefDialogues = dialogues;

            foreach (Dialogue dialogue in dialogues)
            {
                foreach (DialogueNode dialogueNode in dialogue.ListNodes)   //No need for GetOrderedNodes here
                {
                    if (dialogueNode is DialogueNodeSentence)
                    {
                        var nodeSentence = (dialogueNode as DialogueNodeSentence);
                        if (nodeSentence.LastEditDate < dateFrom)
                        {
                            continue;
                        }

                        string text = nodeSentence.Sentence;
                        if (!workstringOnly)
                        {
                            TranslationEntry entry = dialogue.Translations.GetNodeEntry(dialogueNode, language);
                            if (entry == null)
                            {
                                if (!workstringFallback)
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                text = entry.Text;
                            }
                        }

                        projectStats.AddSentence(dialogue, nodeSentence.SpeakerID, text);
                    }
                    else if (dialogueNode is DialogueNodeReply)
                    {
                        var nodeReply = (dialogueNode as DialogueNodeReply);
                        if (nodeReply.LastEditDate < dateFrom)
                        {
                            continue;
                        }

                        string text = nodeReply.Reply;
                        if (!workstringOnly)
                        {
                            TranslationEntry entry = dialogue.Translations.GetNodeEntry(dialogueNode, language);
                            if (entry == null)
                            {
                                if (!workstringFallback)
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                text = entry.Text;
                            }
                        }

                        projectStats.AddReply(dialogue, text);
                    }
                }
            }

            return(projectStats);
        }
예제 #2
0
        static public void ExportLocasToCSVFile(string directory, Project project, List <Dialogue> dialogues, Language language, bool workstringOnly, bool workstringFallback, DateTime dateFrom, ExporterStats.ProjectStats projectStats)
        {
            string path = Path.Combine(directory, "Loca_" + project.GetName() + "_" + language.VoicingCode + ".csv");

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(path, false, Encoding.UTF8))
            {
                //status, scene, voicing id, index, speaker, context, voicing comments, intensity, sentence, comments
                {
                    ExporterCsv.CsvLineWriter header = new ExporterCsv.CsvLineWriter();
                    header.AddField("Status");
                    header.AddField("Dialogue");
                    header.AddField("Voicing ID");
                    header.AddField("Index");
                    header.AddField("Speaker");
                    header.AddField("Context");
                    header.AddField("Voicing Comments");
                    header.AddField("Voicing Intensity");
                    header.AddField("Sentence");
                    header.AddField("Comments");
                    header.WriteLine(file);
                }

                foreach (Dialogue dialogue in dialogues)
                {
                    int index = 1;

                    var orderedListNodes = new List <DialogueNode>();
                    dialogue.GetOrderedNodes(ref orderedListNodes);
                    foreach (DialogueNode dialogueNode in orderedListNodes)
                    {
                        if (dialogueNode is DialogueNodeSentence)
                        {
                            DialogueNodeSentence dialogueNodeSentence = dialogueNode as DialogueNodeSentence;

                            bool done = false;
                            if (dialogueNodeSentence.LastEditDate < dateFrom)
                            {
                                done = true;
                            }

                            string nodeID    = EditorHelper.GetPrettyNodeVoicingID(dialogue, dialogueNodeSentence);
                            string speaker   = project.GetActorName(dialogueNodeSentence.SpeakerID);
                            string scene     = dialogue.GetName();
                            string context   = dialogueNodeSentence.Context;
                            string comment   = dialogueNodeSentence.Comment;
                            string intensity = dialogueNodeSentence.VoiceIntensity;
                            string status    = (done) ? "OK" : "TODO";

                            string voicedText = dialogueNodeSentence.Sentence;
                            if (!workstringOnly)
                            {
                                TranslationEntry entry = dialogue.Translations.GetNodeEntry(dialogueNode, language);
                                if (entry == null)
                                {
                                    if (!workstringFallback)
                                    {
                                        voicedText = "<Missing Translation>";
                                    }
                                }
                                else
                                {
                                    voicedText = entry.Text;
                                }
                            }

                            // use null as langage to force constant replacement in csv file
                            voicedText = EditorHelper.FormatTextEntry(voicedText, null);  //language = workstring if workstringOnly

                            //voicedText = voicedText.Replace("’", "'");
                            //voicedText = voicedText.Replace("…", "...");

                            if (speaker == "")
                            {
                                speaker = "<Undefined>";
                            }

                            //status, scene, node id, index, speaker, context, voicing comments, intensity, sentence, comments
                            ExporterCsv.CsvLineWriter line = new ExporterCsv.CsvLineWriter();
                            line.AddField(status);
                            line.AddField(scene);
                            line.AddField(nodeID);
                            line.AddField(index);
                            line.AddField(speaker);
                            line.AddField(context);
                            line.AddField(comment);
                            line.AddField(intensity);
                            line.AddField(voicedText);
                            line.AddEmptyField();
                            line.WriteLine(file);

                            ++index;

                            if (!done)
                            {
                                projectStats.AddSentence(dialogue, dialogueNodeSentence.SpeakerID, voicedText);
                            }
                        }
                    }
                }
            }
        }
예제 #3
0
        static public void ExportToPO(string directory, Project project, List <Dialogue> dialogues, Language language, bool workstringOnly, bool workstringFallback)
        {
            string path = Path.Combine(directory, "Dialogues.po");

            var  locas     = new Dictionary <string, POEntry>();
            bool isDefault = workstringOnly || (project.GetDefaultLanguage() == language);

            //Fill existing locas

            /*if (File.Exists(path))
             * {
             *  using (System.IO.StreamReader file = new System.IO.StreamReader(path, Encoding.UTF8))
             *  {
             *      while (!file.EndOfStream)
             *      {
             *          string lineId = file.ReadLine();
             *          if (lineId.StartsWith("msgid"))
             *          {
             *              lineId = lineId.Replace("msgid", "");
             *              lineId = lineId.Trim();
             *              lineId = lineId.Substring(1);
             *              lineId = lineId.Substring(0, lineId.Length - 1);
             *
             *              string lineStr = file.ReadLine();
             *              if (lineStr.StartsWith("msgstr"))
             *              {
             *                  lineStr = lineStr.Replace("msgstr", "");
             *                  lineStr = lineStr.Trim();
             *                  lineStr = lineStr.Substring(1);
             *                  lineStr = lineStr.Substring(0, lineStr.Length - 1);
             *
             *                  if (!locas.ContainsKey(lineId))
             *                      locas.Add(lineId, new POEntry() { text = lineStr });
             *              }
             *          }
             *      }
             *  }
             * }*/

            //Parse texts to localize and fill nodes references
            foreach (Dialogue dialogue in dialogues)
            {
                var orderedListNodes = new List <DialogueNode>();
                dialogue.GetOrderedNodes(ref orderedListNodes);
                foreach (DialogueNode dialogueNode in orderedListNodes)
                {
                    if (dialogueNode is DialogueNodeSentence || dialogueNode is DialogueNodeReply)
                    {
                        string workstring;
                        if (dialogueNode is DialogueNodeSentence)
                        {
                            workstring = (dialogueNode as DialogueNodeSentence).Sentence;
                        }
                        else
                        {
                            workstring = (dialogueNode as DialogueNodeReply).Reply;
                        }

                        POEntry entry;
                        if (!locas.TryGetValue(workstring, out entry))
                        {
                            string localizedText = workstring;
                            if (!workstringOnly)
                            {
                                TranslationEntry translation = dialogue.Translations.GetNodeEntry(dialogueNode, language);
                                if (translation == null)
                                {
                                    if (!workstringFallback)
                                    {
                                        localizedText = "";
                                    }
                                }
                                else
                                {
                                    localizedText = translation.Text;
                                }
                            }

                            localizedText = EditorHelper.FormatTextEntry(localizedText, language);  //language = workstring if workstringOnly

                            entry = new POEntry()
                            {
                                text = localizedText
                            };
                            locas.Add(workstring, entry);
                        }

                        entry.nodes.Add(EditorHelper.GetPrettyNodeID(dialogue, dialogueNode));
                    }
                }
            }

            //Re-write file
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(path, false, Encoding.UTF8))
            {
                string date = Utility.GetDateAsString(Utility.GetCurrentTime());

                //Header
                file.WriteLine("# Dialogues " + language.Name + " translation.");
                file.WriteLine("# ");
                file.WriteLine("msgid \"\"");
                file.WriteLine("msgstr \"\"");
                file.WriteLine("\"Project-Id-Version: Dialogues\\n\"");
                file.WriteLine("\"POT-Creation-Date: " + date + "\\n\"");
                file.WriteLine("\"PO-Revision-Date: " + date + "\\n\"");
                file.WriteLine("\"Language-Team: \\n\"");
                file.WriteLine("\"Language: " + language.LocalizationCode + "\\n\"");
                file.WriteLine("\"MIME-Version: 1.0\\n\"");
                file.WriteLine("\"Content-Type: text/plain; charset=UTF-8\\n\"");
                file.WriteLine("\"Content-Transfer-Encoding: 8bit\\n\"");
                file.WriteLine("\"Plural-Forms: nplurals=2; plural=(n != 1);\\n\"");
            }

            //Write entries
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(path, true, Encoding.UTF8))
            {
                foreach (var kvp in locas)
                {
                    if (kvp.Value.nodes.Count > 0)
                    {
                        file.WriteLine("");
                        foreach (string node in kvp.Value.nodes)
                        {
                            file.WriteLine(String.Format("#: {0}", node));
                        }
                        file.WriteLine(String.Format("msgid \"{0}\"", kvp.Key));
                        file.WriteLine(String.Format("msgstr \"{0}\"", kvp.Value.text));
                    }
                }
            }
        }