Пример #1
0
//	public static void CreateEmptyEntry (Tuple<Entry.Type, int> key) {
//		PlayerData.tally.Add (key, null);
//	}

    public static void AddPOEntry(POEntry entry)
    {
        Tuple <Entry.Type, int> last = PlayerData.POTally.Keys.Last();

        PlayerData.POTally.Add(last, entry);
//		Debug.Log (last);
    }
Пример #2
0
    public static void UpdatePOEntry(Tuple <Entry.Type, int> key, POEntry entry)
    {
        if (PlayerData.POTally.ContainsKey(key))
        {
            PlayerData.POTally [key] = entry;
        }

        PrintPODictionary();
    }
Пример #3
0
 void RecordData()
 {
     //		parameters.PutExtra ("TIME_NEEDLE_REMOVED", System.DateTime.Now.ToString());
     //		parameters.PutExtra ("OBJECT_GIVEN", "");
     //		parameters.PutExtra ("ACTUAL_ANSWER", "");
     //		parameters.PutExtra ("ATTEMPTED_ANSWERS", "");
     //		parameters.PutExtra ("TIME_SOLVED", System.DateTime.Now.ToString());
     //		parameters.PutExtra ("NEEDLE_INTERACTION_COUNT", "");
     //		parameters.PutExtra ("NUMBER_OF_ATTEMPTS", "");
     //		EventBroadcaster.Instance.PostEvent (EventNames.ON_NEEDLE_HIT, parameters);
     currentKey = new Tuple <Entry.Type, int>(Entry.Type.PartitionableObject, PlayerData.partitionableObjectIndex);
     //        if (!DataManager.DoesKeyExist(currentKey))
     Debug.Log("Current " + currentKey.Item1 + " " + currentKey.Item2);
     if (poBoxKey != null)
     {
         Debug.Log("PO Box " + poBoxKey.Item1 + " " + poBoxKey.Item2);
     }
     if (poBoxKey == null)
     {
         entry      = new POEntry();
         entry.name = "Box " + PlayerData.partitionableObjectIndex;
         entry.timeWeaponInteracted = new List <DateTime> ();
         entry.timeWeaponInteracted.Add(System.DateTime.Now);
         entry.interactionCount++;
         Parameters parameters = new Parameters();
         parameters.PutExtra("TYPE", Entry.Type.PartitionableObject.ToString());
         parameters.PutExtra("NUMBER", PlayerData.partitionableObjectIndex);
         DataManager.CreateEmptyEntry(parameters);
         poBoxKey = currentKey;
         PlayerData.IncrementPOIndex();
     }
     else
     {
         entry = DataManager.GetPOEntry(poBoxKey);
         entry.timeWeaponInteracted.Add(System.DateTime.Now);
         entry.interactionCount++;
     }
 }
Пример #4
0
        /// <summary>
        /// Reads a PO file and creates a list of PO entries.
        /// </summary>
        /// <param name="filepath"></param>
        /// <returns></returns>
        // TODO Currently unused, implement a unit test at minimum if wanting to keep this around or make internal or remove.
        public static List <POEntry> ReadPOFile(string filepath)
        {
            const string str       = "msgstr ";
            const string id        = "msgid ";
            const string previd    = "#| msgstr ";
            const string flag      = "#,";
            const string reference = "#:";
            const string ecomment  = "#.";
            const string tcomment  = "#";

            var ret = new List <POEntry>();

            try
            {
                using (var fileStream = new FileStream(filepath, FileMode.Open, FileAccess.Read))
                    using (var streamReader = new StreamReader(fileStream, Utf8WithoutBom))
                    {
                        var    entry = new POEntry();
                        string line;
                        while ((line = streamReader.ReadLine()) != null)
                        {
                            if (line.StartsWith(str))
                            {
                                entry.TranslatedString = line.Substring(str.Length);
                                entry.TranslatedString = entry.TranslatedString.Trim(new char[] { ' ', '\"' });
                            }
                            if (line.StartsWith(id))
                            {
                                entry.UntranslatedString = line.Substring(id.Length);
                                entry.UntranslatedString = entry.UntranslatedString.Trim(new char[] { ' ', '\"' });
                            }
                            if (line.StartsWith(previd))
                            {
                                entry.PreviousUntranslatedString = line.Substring(previd.Length);
                                entry.PreviousUntranslatedString = entry.PreviousUntranslatedString.Trim(new char[] { ' ', '\"' });
                            }
                            if (line.StartsWith(flag))
                            {
                                entry.Flag = line.Substring(flag.Length).Trim();
                            }
                            if (line.StartsWith(reference))
                            {
                                entry.Reference = line.Substring(reference.Length).Trim();
                            }
                            if (line.StartsWith(ecomment))
                            {
                                entry.ExtractedComments = line.Substring(ecomment.Length).Trim();
                            }
                            if (line.StartsWith(tcomment))
                            {
                                entry.TranslatorComments = line.Substring(tcomment.Length).Trim();
                            }

                            if (line.IsNullOrWhitespace() && entry.IsValid())
                            {
                                ret.Add(entry);
                                entry = new POEntry();
                            }
                        }
                    }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }

            return(ret);
        }
Пример #5
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));
                    }
                }
            }
        }
Пример #6
0
    public static void RemovePOEntry(POEntry entry)
    {
        Tuple <Entry.Type, int> key = PlayerData.POTally.FirstOrDefault(x => x.Value == entry).Key;

        PlayerData.POTally.Remove(key);
    }