Esempio n. 1
0
        /// <summary>
        /// Create a dictionary from a list of localization files
        /// </summary>
        /// <param name="basePath">Base path to localization files</param>
        /// <param name="localizationFiles">List of paths to localization files</param>
        /// <param name="newDefaultLanguage">default language of the new dictionary</param>
        /// <param name="newCurrentLanguage">current language of the new dictionary</param>
        /// <returns></returns>
        public static DictionaryI18n ReadFromFileList(string basePath, IEnumerable <string> localizationFiles, string newDefaultLanguage, string newCurrentLanguage)
        {
            DictionaryI18n finalDict = null;
            DictionaryI18n partialDict;

            foreach (string file in localizationFiles)
            {
                // The partial dicts are created without default and current language and after loading
                // all dict the default and current language will be stablished
                partialDict = LocalizationRead.ReadFromFilePath(basePath + file, null, null);
                if (finalDict == null)
                {
                    finalDict = partialDict;
                }
                else
                {
                    finalDict.AddRaw(partialDict);
                }
            }

            if (finalDict != null)
            {
                finalDict.setDefaultLanguage(newDefaultLanguage);
                finalDict.setCurrentLanguage(newCurrentLanguage);
            }

            return(finalDict);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds raw data to the dictionary. Current dict shouldn't have entries neither new dict. Only raw data
        /// </summary>
        /// <param name="dictToCombine"></param>
        public void AddRaw(DictionaryI18n dictToCombine)
        {
            if (dictToCombine == null)
            {
                return;
            }

            if (dict.Count == 0 && dictToCombine.dict.Count == 0)
            {
                bool found = false;
                foreach (string lang in languages)
                {
                    if (lang != "." && lang == dictToCombine.languages[1])
                    {
                        found = true;
                    }
                }

                // If the language already exists don't add anything
                // If the new dict has more than one lang don't add anything
                if (!found && dictToCombine.languages.Length == 2)
                {
                    List <string> rawOut = new List <string>();
                    // Generate the dictionary list
                    string newLanguagesList = String.Join(COMMA.ToString(), languages) + COMMA + dictToCombine.languages[1];
                    rawOut.Add(newLanguagesList);
                    languages = newLanguagesList.Split(COMMA);

                    string currentKey;
                    string outString;
                    for (int entryPos = 1; entryPos < rawDict.Length; entryPos++)
                    {
                        currentKey = rawDict[entryPos].Split(COMMA)[0] + COMMA;

                        outString = rawDict[entryPos] + COMMA;
                        for (int newEntryPos = 1; newEntryPos < dictToCombine.rawDict.Length; newEntryPos++)
                        {
                            if (dictToCombine.rawDict[newEntryPos].StartsWith(currentKey))
                            {
                                outString += dictToCombine.rawDict[newEntryPos].Substring(currentKey.Length);
                                break;
                            }
                        }

                        rawOut.Add(outString);
                    }

                    rawDict = rawOut.ToArray();
                }
                else
                {
                    ValkyrieTools.ValkyrieDebug.Log("The AddRaw method only merges a dictionary with only one new lang");
                }
            }
            else
            {
                ValkyrieTools.ValkyrieDebug.Log("The AddRaw method only merges raw dictionaries");
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Add a new dictionary, replaces if exists
 /// </summary>
 /// <param name="name">dictionary name</param>
 /// <param name="dict">DictionaryI18n data</param>
 /// <returns>void</returns>
 public static void AddDictionary(string name, DictionaryI18n dict)
 {
     if (!dicts.ContainsKey(name))
     {
         dicts.Add(name, dict);
     }
     else
     {
         dicts[name] = dict;
     }
 }
        /// <summary>
        /// Transform a ffg key (without ffg prefig, into current language text
        /// </summary>
        /// <param name="dict"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        private static string DictKeyLookup(string dict, string key)
        {
            DictionaryI18n currentDict = selectDictionary(dict);

            if (currentDict == null)
            {
                ValkyrieDebug.Log("Error: current dictionary not loaded");
                return(key);
            }
            return(currentDict.GetValue(key));
        }
Esempio n. 5
0
        /// <summary>
        /// Constructor with the complete localisation elements
        /// </summary>
        /// <param name="completeLocalizationString"></param>
        public EntryI18n(DictionaryI18n dict, string completeLocalizationString)
        {
            referedDictionary = dict;

            string newLinedCompleteLocalizationString = completeLocalizationString.Replace("\\n", "\n");

            if (newLinedCompleteLocalizationString.Contains(QUOTES))
            {
                // with quotes, commas inside quotes isn't considered separator
                List <string> partialTranslation = new List <string>(newLinedCompleteLocalizationString.Split(COMMA));
                List <string> finalTranslation   = new List <string>();
                string        currentTranslation = "";
                bool          oddity             = false;
                foreach (string suposedTranslation in partialTranslation)
                {
                    currentTranslation += suposedTranslation;

                    // Counting quotes inside string to know oddity.
                    bool newOddity = (suposedTranslation.Count(ch => ch == QUOTES) % 2) == 1;

                    if (oddity ^ newOddity)
                    {
                        // If oddity changes we are still inside quotes
                        currentTranslation += COMMA;
                    }
                    else
                    {
                        // If opening and closing quotes, we supress it.
                        if (currentTranslation.Length > 0 && currentTranslation[0] == QUOTES)
                        {
                            currentTranslation = currentTranslation.Substring(1, currentTranslation.Length - 2);
                        }

                        // escaping double quotes
                        finalTranslation.Add(currentTranslation.Replace("\"\"", "\""));
                        currentTranslation = "";
                    }

                    oddity = oddity ^ newOddity;
                }
                translations = finalTranslation.ToArray();
            }
            else
            {
                // Without quotes, all commas are separators
                translations = newLinedCompleteLocalizationString.Split(COMMA);
            }

            if (translations.Length > dict.getLanguages().Length)
            {
                ValkyrieDebug.Log("Incoherent DictI18n with " + dict.getLanguages().Length + " languages including StringI18n with " + translations.Length + " languages : " + newLinedCompleteLocalizationString + System.Environment.NewLine);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Add dict entries from another dict merging rawdata
        /// </summary>
        /// <param name="dictToCombine"></param>
        public void Add(DictionaryI18n dictToCombine)
        {
            if (dictToCombine != null)
            {
                foreach (string key in dictToCombine.dict.Keys)
                {
                    dict[key] = dictToCombine.dict[key];
                }

                int array1OriginalLength = rawDict.Length;
                System.Array.Resize <string>(ref rawDict, array1OriginalLength + dictToCombine.rawDict.Length);
                System.Array.Copy(dictToCombine.rawDict, 0, rawDict, array1OriginalLength, dictToCombine.rawDict.Length);
            }
        }
Esempio n. 7
0
        public static void ClassInitialize(TestContext context)
        {
            // Disble logger
            ValkyrieDebug.enabled = false;

            // Sample dictionary
            string[] file = new string[4]
            {
                DictionaryI18n.FFG_LANGS,
                "MONSTER_BYAKHEE_ATTACK_01,\"The byakhee dives at you, its leathery wings like scythes (; 2). If you pass, you narrowly duck the creature's strike. If you fail, you are whipped to the ground by a swooping blow; suffer 1 Damage and become Dazed.\",\"El byakhee se lanza en picado hacia ti con sus alas correosas similares a guadañas (; 2). Si superas la tirada, te agachas y esquivas por los pelos el ataque de la criatura. Si fallas la tirada, te derriba violentamente con un ataque de pasada; sufres 1 de Daño y adquieres el estado Desconcertado.\",\"Le Byakhee pique vers vous, ses ailes membraneuses déployées tels des faux ( ; 2). En cas de succès, vous évitez de justesse l'attaque de la créature. En cas d'échec, vous êtes fauché ; subissez 1 Dégât et devenez Sonné.\",Mit messerscharfen Schwingen stürzt der Byakhee auf dich zu (; 2). Bei Erfolg kannst du dich im letzten Moment abrollen. Bei Misserfolg wirst du von den Beinen gerissen; du erleidest 1 Schaden und du wirst benommen.,\"La creatura si tuffa verso di te, agitando le sue ali membranose come falci (: 2). Se hai successo, schivi il colpo della creatura chinandoti. Se fallisci, vieni scagliato a terra da un ampio fendente; subisci 1 danno e diventa frastornato.\",\"O byakhee mergulha em sua direção, e você vê as asas coriáceas em forma de gadanhas (; 2). Se passar, você se esquiva por pouco do ataque da criatura. Se falhar, as asas açoitam no golpe rasante, e você vai ao chão; sofra 1 Dano e fique Desnorteado.\",\"Byakhee nurkuje na ciebie, jego skórzaste skrzydła tną jak kosy (; 2). Jeśli zdałeś, w ostatniej chwili padasz na ziemię. Jeśli nie zdałeś, zostajesz powalony siłą uderzenia; przyjmujesz 1 kartę Obrażenia i otrzymujesz stan Oszołomiony.\",ビヤーキーは君に飛びかかった。皮のような翼はまるで鎌のようだ(; 2)。成功:そいつの攻撃をギリギリかわした。 失敗:その急襲を受け、地面にもんどりうって倒れた。;ダメージカードを1枚得て、放心状態になる。,拜亞基向你衝來,張開它如同鐮刀般的堅韌翅膀(;2)。如果檢定成功,你勉強躲過了那隻生物的襲擊。如果檢定失敗,你被猛烈的衝擊打倒在地;受到1點傷害并進入眩暈狀態。",
                "ATTACK_FIREARM_VS_SPIRIT_03,\"You fire at the specter. It does not work. Instead, you focus your mind and scream at it, \"\"Get out!\"\" (+1). The monster suffers damage equal to your test result.\",Disparas al espectro. No sirve de nada. Decides cambiar de estrategia; te concentras y exhortas a la aparición a que se marche (+1). El monstruo sufre tanto Daño como el resultado de tu tirada.,\"Vous tirez sur le spectre, en pure perte. Vous décidez alors de vous concentrer et de hurler : « Fiche le camp ! » (+1). Le monstre subit des dégâts égaux au résultat de votre test.\",\"Du feuerst auf das Gespenst. Als es nicht reagiert, konzentrierst du dich und schreist: „Weiche!“ (+1). Das Monster erleidet Schaden in Höhe deines Probenergebnisses.\",\"Apri il fuoco contro lo spettro ma i colpi non hanno nessun effetto, quindi cerchi di concentrarti sulla creatura urlandole di sparire (+1). Il mostro subisce danni pari al risultato della tua prova.\",\"Você atira contra o espectro. Nada acontece. Em vez disso, você concentra sua mente e grita: “Saia daqui!” (+1). O monstro sofre dano igual ao resultado do seu teste.\",\"Strzelasz do widma. To nie działa. Zamiast tego koncentrujesz się i krzyczysz w jego kierunku, „Przepadnij!” (+1). Potwór przyjmuje obrażenia równe wynikowi twojego testu.\",君はその霊を撃ったが、まるで効果はなかった。そこで君は、精神を集中して、「悪霊退散!」と叫んだ(+1)。;モンスターは、この判定の成功数に等しいダメージを受ける。,你向鬼魂開槍,但是並不起作用。於是,你全神貫注地朝它大喊道:“走開!”(+1)。怪物受到等同於檢定結果的傷害",
                "MONSTER_THRALL_MOVE_01,The {0} moves 2 spaces toward the nearest investigator. Then it attacks the investigator in its space with the highest .,,,Das Monster „{0}“ bewegt sich um 2 Felder auf den nächsten Ermittler zu. Dann greift es den Ermittler mit der höchsten  auf seinem Feld an.,,,\"{0} przemieszcza się o 2 pola w kierunku najbliższego badacza. Następnie atakuje tego badacza na swoim polu, który ma największą .\",The {0} moves 2 spaces toward the nearest investigator. Then it attacks the investigator in its space with the highest ."
            };

            dict = new DictionaryI18n(file, DictionaryI18n.DEFAULT_LANG, DictionaryI18n.DEFAULT_LANG);
        }
Esempio n. 8
0
        public void TestSerializedDictionariesJoinsCorrectly()
        {
            Dictionary <string, List <string> > dictionaries = sut.SerializeMultiple();

            DictionaryI18n partialLocalizationDict;
            DictionaryI18n localizationDict = null;

            foreach (string language in dictionaries.Keys)
            {
                partialLocalizationDict = new DictionaryI18n(dictionaries[language].ToArray(), language, language);

                if (localizationDict == null)
                {
                    localizationDict = partialLocalizationDict;
                }
                else
                {
                    localizationDict.AddRaw(partialLocalizationDict);
                }
            }

            sut.setDefaultLanguage(DictionaryI18n.DEFAULT_LANG);
            localizationDict.setDefaultLanguage(DictionaryI18n.DEFAULT_LANG);
            sut.flushRaw();
            localizationDict.flushRaw();
            // Compare languages
            for (int langPos = 0; langPos < localizationDict.getLanguages().Length; langPos++)
            {
                if (localizationDict.getLanguages()[langPos] != sut.getLanguages()[langPos])
                {
                    Assert.Fail(new StringBuilder()
                                .Append("Languages position don't match: Position:")
                                .Append(langPos)
                                .Append(" SourceLang:")
                                .Append(sut.getLanguages()[langPos])
                                .Append(" TargetLang:")
                                .Append(localizationDict.getLanguages()[langPos])
                                .ToString());
                }

                sut.setCurrentLanguage(localizationDict.getLanguages()[langPos]);
                localizationDict.setCurrentLanguage(localizationDict.getLanguages()[langPos]);
            }
        }
Esempio n. 9
0
        public void TestSerializeMultipleFiles_EnglishSpanish()
        {
            // Sample dictionary
            string[] fileEnglishSpanish = new string[6]
            {
                DictionaryI18n.FFG_LANGS,
                "MONSTER_BYAKHEE_ATTACK_01,\"The byakhee dives at you, its leathery wings like scythes (; 2). If you pass, you narrowly duck the creature's strike. If you fail, you are whipped to the ground by a swooping blow; suffer 1 Damage and become Dazed.\",\"El byakhee se lanza en picado hacia ti con sus alas correosas similares a guadañas (; 2). Si superas la tirada, te agachas y esquivas por los pelos el ataque de la criatura. Si fallas la tirada, te derriba violentamente con un ataque de pasada; sufres 1 de Daño y adquieres el estado Desconcertado.\"",
                "ATTACK_FIREARM_VS_SPIRIT_03,\"You fire at the specter. It does not work. Instead, you focus your mind and scream at it, \"\"Get out!\"\" (+1). The monster suffers damage equal to your test result.\",Disparas al espectro. No sirve de nada. Decides cambiar de estrategia; te concentras y exhortas a la aparición a que se marche (+1). El monstruo sufre tanto Daño como el resultado de tu tirada.",
                "MONSTER_THRALL_MOVE_01,The {0} moves 2 spaces toward the nearest investigator. Then it attacks the investigator in its space with the highest .,",
                "PARAMETER,parameter,parametro,,,,,",
                "CUTSCENE_1_PROLOGUE,\"Your adventure begins with a note shoved under your door. Scrawled in large, unpracticed letters: \\n\\n[i]Hey stupid heroes! \\n\\nEverything is terrible! The Lair of All Goblins has been overrun by wicked things that dumb heroes like you always fight. You must come here, beat them up, and break their things to stop the unthinkable: the end of all goblins! You obviously don’t know where the Lair of All Goblins is, so I drew a map. Don’t lose it!\\n\\nYour fearsome master, \\n\\nSplig\\n\\n[/i]The map is rough but legible, leading to a place you clearly recognize as the Parigreth ruins. Having nothing better to do, you gather your gear and depart.\""
            };

            DictionaryI18n newSut = new DictionaryI18n(fileEnglishSpanish, DictionaryI18n.DEFAULT_LANG, DictionaryI18n.DEFAULT_LANG);

            Dictionary <string, List <string> > dictMultipleSerialization = newSut.SerializeMultiple();

            Assert.IsTrue(dictMultipleSerialization.Keys.Count == 2);
        }
Esempio n. 10
0
        private static bool CheckDictQuery(string dict, string input)
        {
            int           bracketLevel = 0;
            int           lastSection  = 0;
            List <string> elements     = new List <string>();

            // Separate the input into sections
            for (int index = 0; index < input.Length; index++)
            {
                if (input[index].Equals('{'))
                {
                    bracketLevel++;
                }
                if (input[index].Equals('}'))
                {
                    bracketLevel--;
                }
                // Section divider
                if (input[index].Equals(':'))
                {
                    // Not in brackets
                    if (bracketLevel == 0)
                    {
                        // Add previous element
                        elements.Add(input.Substring(lastSection, index - lastSection));
                        lastSection = index + 1;
                    }
                }
            }
            // Add previous element
            elements.Add(input.Substring(lastSection, input.Length - lastSection));

            DictionaryI18n currentDict = selectDictionary(dict);

            if (currentDict == null)
            {
                return(false);
            }
            EntryI18n valueOut;

            return(currentDict.tryGetValue(elements[0], out valueOut));
        }
Esempio n. 11
0
        /// <summary>
        /// Transform a ffg key (without ffg prefig, into current language text
        /// </summary>
        /// <param name="dict"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        private static string DictKeyLookup(string dict, string key)
        {
            DictionaryI18n currentDict = selectDictionary(dict);

            if (currentDict != null)
            {
                EntryI18n valueOut;

                if (currentDict.tryGetValue(key, out valueOut))
                {
                    return(valueOut.getCurrentOrDefaultLanguageString());
                }
                else
                {
                    return(key);
                }
            }
            else
            {
                ValkyrieDebug.Log("Error: current dictionary not loaded");
            }
            return(key);
        }
Esempio n. 12
0
 /// <summary>
 /// Creates an empty instance of a Multilanguage String
 /// </summary>
 public EntryI18n(string key, DictionaryI18n dict)
 {
     referedDictionary = dict;
     translations      = new string[dict.getLanguages().Length];
     translations[0]   = key;
 }
Esempio n. 13
0
 /// <summary>
 /// Add a new dictionary, replaces if exists
 /// </summary>
 /// <param name="name">dictionary name</param>
 /// <param name="dict">DictionaryI18n data</param>
 /// <returns>void</returns>
 public static void AddDictionary(string name, DictionaryI18n dict)
 {
     dicts[name] = dict;
 }