예제 #1
0
파일: Lexeme.cs 프로젝트: envis10n/Warrens
        /// <summary>
        /// Add language translations for this
        /// </summary>
        public void FillLanguages()
        {
            IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld));

            //Don't do this if: we have no config, translation is turned off or lacking in the azure key, the language is not a human-ui language
            //it isn't an approved language, the word is a proper noun or the language isnt the base language at all
            if (globalConfig == null || !globalConfig.TranslationActive || string.IsNullOrWhiteSpace(globalConfig.AzureTranslationKey) ||
                !Language.UIOnly || !Language.SuitableForUse || ContainedTypes().Contains(LexicalType.ProperNoun) || Language != globalConfig.BaseLanguage)
            {
                return;
            }

            IEnumerable <ILanguage> otherLanguages = ConfigDataCache.GetAll <ILanguage>().Where(lang => lang != Language && lang.SuitableForUse && lang.UIOnly);

            foreach (ILanguage language in otherLanguages)
            {
                short  formGrouping = -1;
                string newName      = string.Empty;

                Lexeme newLexeme = new Lexeme()
                {
                    Language = language
                };

                foreach (IDictata word in WordForms)
                {
                    LexicalContext context = new LexicalContext(null)
                    {
                        Language    = language,
                        Perspective = word.Perspective,
                        Tense       = word.Tense,
                        Position    = word.Positional,
                        Determinant = word.Determinant,
                        Plural      = word.Plural,
                        Possessive  = word.Possessive,
                        Elegance    = word.Elegance,
                        Quality     = word.Quality,
                        Semantics   = word.Semantics,
                        Severity    = word.Severity,
                        GenderForm  = new Gender()
                        {
                            Feminine = word.Feminine
                        }
                    };

                    IDictata translatedWord = Thesaurus.GetSynonym(word, context);

                    //no linguistic synonym
                    if (translatedWord == this)
                    {
                        string newWord = Thesaurus.GetTranslatedWord(globalConfig.AzureTranslationKey, Name, Language, language);

                        if (!string.IsNullOrWhiteSpace(newWord))
                        {
                            newName        = newWord;
                            newLexeme.Name = newName;

                            Dictata newDictata = new Dictata(newWord, formGrouping++)
                            {
                                Elegance       = word.Elegance,
                                Severity       = word.Severity,
                                Quality        = word.Quality,
                                Determinant    = word.Determinant,
                                Plural         = word.Plural,
                                Perspective    = word.Perspective,
                                Feminine       = word.Feminine,
                                Positional     = word.Positional,
                                Possessive     = word.Possessive,
                                Semantics      = word.Semantics,
                                Antonyms       = word.Antonyms,
                                Synonyms       = word.Synonyms,
                                PhraseAntonyms = word.PhraseAntonyms,
                                PhraseSynonyms = word.PhraseSynonyms,
                                Tense          = word.Tense,
                                WordType       = word.WordType
                            };

                            newDictata.Synonyms = new HashSet <IDictata>(word.Synonyms)
                            {
                                word
                            };
                            word.Synonyms = new HashSet <IDictata>(word.Synonyms)
                            {
                                newDictata
                            };
                            newLexeme.AddNewForm(newDictata);
                        }
                    }
                }

                if (newLexeme.WordForms.Count() > 0)
                {
                    newLexeme.SystemSave();
                    newLexeme.PersistToCache();
                }
            }

            SystemSave();
            PersistToCache();
        }