示例#1
0
        /// <summary>
        /// Create language pairs options based on the TM types found in template. This options will be later used in the UI to enable
        /// following options from Penalty Page: "No tm", "Create new tm", "Choose existing tm"
        /// </summary>
        /// <param name="tmDetails">Path and name for tm found in Studio template</param>
        /// <param name="sourceCultureInfo">Package source language</param>
        /// <param name="targetLanguages">Package target languages</param>
        /// <returns>true and target language supported</returns>
        private LanguagePair GetLanguagePairTmOptions(TemplateTmDetails tmDetails, CultureInfo sourceCultureInfo,
                                                      Language[] targetLanguages)
        {
            var(isCreatedFromPlugin, language) =
                IsTmCreatedFromPlugin(tmDetails.Name, sourceCultureInfo, targetLanguages);
            tmDetails.IsCreatedFromPlugin = isCreatedFromPlugin;
            tmDetails.TargetLanguage      = language;

            if (isCreatedFromPlugin)
            {
                return(new LanguagePair
                {
                    SourceLanguage = sourceCultureInfo,
                    TargetLanguage = new CultureInfo(language.CultureInfo.Name),
                    CreateNewTm = true,
                    TemplatePenalty = tmDetails.Penalty
                });
            }

            var(tmCorrespondsToLanguagePair, targetLanguage) =
                TmSupportsAnyLanguageDirection(new Uri(tmDetails.LocalPath), sourceCultureInfo, targetLanguages);
            if (tmCorrespondsToLanguagePair)
            {
                return(new LanguagePair
                {
                    SourceLanguage = sourceCultureInfo,
                    TargetLanguage = new CultureInfo(targetLanguage.CultureInfo.Name),
                    ChoseExistingTm = true,
                    TmPath = tmDetails.LocalPath,
                    TmName = tmDetails.Name
                });
            }
            return(null);
        }
示例#2
0
        private List <TemplateTmDetails> TmDetailsFromCascadeEntry(XmlDocument projectTemplateDocument, CultureInfo sourceCultureInfo, Language[] targetLanguages)
        {
            if (sourceCultureInfo is null || targetLanguages is null)
            {
                return(null);
            }
            var cascadeEntries = projectTemplateDocument.SelectNodes("/ProjectTemplate/CascadeItem/CascadeEntryItem");

            if (cascadeEntries is null)
            {
                return(null);
            }

            var tmDetails = new List <TemplateTmDetails>();

            foreach (XmlNode cascadeEntryItem in cascadeEntries)
            {
                var details = new TemplateTmDetails();
                if (cascadeEntryItem.Attributes is null)
                {
                    continue;
                }
                foreach (XmlAttribute entryAttribute in cascadeEntryItem.Attributes)
                {
                    if (!entryAttribute.Name.Equals("Penalty"))
                    {
                        continue;
                    }
                    int.TryParse(entryAttribute.Value, out var penaltySet);
                    details.Penalty = penaltySet;

                    foreach (XmlNode mainTranslationProviderItem in cascadeEntryItem.ChildNodes)
                    {
                        if (mainTranslationProviderItem.Attributes is null)
                        {
                            continue;
                        }
                        foreach (XmlAttribute providerAttribute in mainTranslationProviderItem.Attributes)
                        {
                            if (!providerAttribute.Name.Equals("Uri"))
                            {
                                continue;
                            }
                            var uri = new Uri(providerAttribute.Value);
                            details.LocalPath = FileBasedTranslationMemory.GetFileBasedTranslationMemoryFilePath(uri);
                            details.Name      = Path.GetFileNameWithoutExtension(details.LocalPath);
                            details.TransitLanguagePairOptions = GetLanguagePairTmOptions(details, sourceCultureInfo, targetLanguages);
                        }
                    }
                }

                if (details.TransitLanguagePairOptions != null)
                {
                    tmDetails.Add(details);
                }
            }
            return(tmDetails);
        }