示例#1
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);
            }
        }
        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]);
            }
        }
示例#3
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;
 }