public void TestAshcanPete_ShowsCorrectText() { String dictEntry = "INVESTIGATOR_ASHCAN_PETE,\"\"\"Ashcan\"\" Pete\",Pete Cubo de Basura,\"\"\"Ashcan\"\" Pete\",„Ashcan“ Pete,“Ashcan” Pete,Peter “Chaminé”,Pete „Włóczęga”,ごみあさりのピート,“灰堆”皮特"; EntryI18n actual = new EntryI18n(dict, dictEntry); Assert.AreEqual("\"Ashcan\" Pete", actual.currentLanguageString); }
public void RenamePrefix(string oldPrefix, string newPrefix) { HashSet <string> toRemove = new HashSet <string>(); List <EntryI18n> toAdd = new List <EntryI18n>(); foreach (string s in dict.Keys) { if (s.IndexOf(oldPrefix) == 0) { string newKey = newPrefix + s.Substring(oldPrefix.Length); EntryI18n e = dict[s]; e.key = newKey; toAdd.Add(e); toRemove.Add(s); } } foreach (string s in toRemove) { Remove(s); } foreach (EntryI18n e in toAdd) { dict.Add(e.key, e); } for (int i = 0; i < rawDict.Length; i++) { if (rawDict[i].IndexOf(oldPrefix) == 0) { rawDict[i] = newPrefix + rawDict[i].Substring(oldPrefix.Length); } } }
public void TestQuotesWithoutComma_DoesntSplit() { String dictEntry = ".,\"\",,,,,,,,"; EntryI18n actual = new EntryI18n(dict, dictEntry); String actualString = actual.currentLanguageString; String expected = ""; Assert.AreEqual(expected, actualString); }
public void TestLangsString_LoadsLastLanguage() { dict.currentLanguage = 9; EntryI18n actual = new EntryI18n(dict, DictionaryI18n.FFG_LANGS); String actualString = actual.currentLanguageString; String expected = "Chinese"; dict.setCurrentLanguage(DictionaryI18n.DEFAULT_LANG); Assert.AreEqual(expected, actualString); }
/// <summary> /// Sets a dictionary entry for key and text.Creates or replaces /// </summary> /// <param name="key">key of the string</param> /// <param name="text">text to insert in current language</param> public static void updateScenarioText(string key, string text) { EntryI18n entry; // Search for localization string if (!dicts["qst"].tryGetValue(key, out entry)) { // if not exists, we create a new one entry = new EntryI18n(key, dicts["qst"]); } entry.currentLanguageString = text; }
public void TestDifferentLangInserts_DoesntOverwriteOtherLangTexts() { String dictEntry = ".,,,,,,,,,"; EntryI18n actual = new EntryI18n(dict, dictEntry); for (int nLang = 1; nLang < 10; nLang++) { // First language dict.currentLanguage = nLang; actual.currentLanguageString = nLang.ToString(); } for (int nLang = 1; nLang < 10; nLang++) { // Back to first dict.currentLanguage = nLang; Assert.AreEqual(nLang.ToString(), actual.currentLanguageString); } }
/// <summary> /// Checks if a key exists in the dictionary /// gets its value /// </summary> /// <param name="v">key to find</param> /// <param name="valueOut">variable to store result if exists</param> /// <returns>true if the key exists in the dictionary</returns> public bool tryGetValue(string v, out EntryI18n valueOut) { bool found = dict.TryGetValue(v, out valueOut); if (found) { return(true); } else { // Search element for (int pos = 1; pos < rawDict.Length; pos++) { // if the line is not empty and not slash (/) insert if (rawDict[pos].StartsWith(v + COMMA)) { valueOut = new EntryI18n(this, GetEntry(pos)); Add(valueOut); return(true); } } return(false); } }
/// <summary> /// Create a dict entry with the StringI18n /// </summary> /// <param name="currentKeyValues">line of localization file</param> public void Add(EntryI18n currentKeyValues) { dict.Add(currentKeyValues.key, currentKeyValues); }
/// <summary> /// Create a dict entry with the StringI18n /// </summary> /// <param name="currentKeyValues">line of localization file</param> public void Add(EntryI18n currentKeyValues) { dict[currentKeyValues.key] = currentKeyValues; }