public void GetTemplates(TranslationProviderServer tmServer)
        {
            #region "LoopTemplates"
            string templateList = string.Empty;
            foreach (ServerBasedLanguageResourcesTemplate template in tmServer.GetLanguageResourcesTemplates(LanguageResourcesTemplateProperties.All))
            #endregion
            {
                #region "info"
                templateList += "Template name: " + template.Name + "\n";
                templateList += "Description: " + template.Description + "\n";
                #endregion
                #region "VarCount"
                LanguageResourceBundle bundle = template.LanguageResourceBundles[0];
                templateList += "Number of variables in template: " + bundle.Variables.Count.ToString() + "\n\n";
                #endregion
            }

            MessageBox.Show(templateList, "Available language resources remplates");
        }
Esempio n. 2
0
        public void Execute()
        {
            var uri = new Uri(@"Add your url");
            var translationProviderServer = new TranslationProviderServer(uri, false, "user name", "password");

            var serverTm = new ServerBasedTranslationMemory(translationProviderServer)
            {
                Name = "Tm from API"
            };
            var resourceTemplate =
                translationProviderServer.GetLanguageResourcesTemplates(LanguageResourcesTemplateProperties.All);
            var containters = translationProviderServer.GetContainers(ContainerProperties.All);
            var container   = containters.FirstOrDefault(c => c.Name.Equals("APSIC_TM_Container"));

            if (container != null)
            {
                serverTm.Container = container;
                serverTm.ParentResourceGroupPath   = container.ParentResourceGroupPath;
                serverTm.LanguageResourcesTemplate = resourceTemplate?[0];
                CreateLanguageDirections(serverTm.LanguageDirections);

                serverTm.Save();
            }
        }
Esempio n. 3
0
        public void Create(TranslationProviderServer tmServer, string organizationPath, string containerName, string tmName)
        {
            #region "CheckExists"
            foreach (ServerBasedTranslationMemory item in tmServer.GetTranslationMemories(TranslationMemoryProperties.None))
            {
                if (item.Name == tmName)
                {
                    throw new Exception("TM with that name already exists.");
                }
            }
            #endregion

            #region "TM"
            ServerBasedTranslationMemory newTM = new ServerBasedTranslationMemory(tmServer);
            newTM.Name        = tmName;
            newTM.Description = "Programmatically created sample TM";
            newTM.Copyright   = "(c) 2010 SDL International";
            #endregion

            string containerPath = organizationPath;
            if (!containerPath.EndsWith("/"))
            {
                containerPath += "/";
            }

            #region "container"
            containerPath += containerName;
            TranslationMemoryContainer container = tmServer.GetContainer(containerPath, GetContainerProperties());
            newTM.Container = container;
            #endregion

            #region "LanguageDirection"
            CreateLanguageDirections(newTM.LanguageDirections);
            #endregion

            #region "org"
            newTM.ParentResourceGroupPath = organizationPath;
            #endregion

            string templatePath = organizationPath;
            if (!templatePath.EndsWith("/"))
            {
                templatePath += "/";
            }

            #region "templates"
            string sampleFieldTemplateName = "MyFieldTemplate";
            foreach (ServerBasedFieldsTemplate template in tmServer.GetFieldsTemplates(FieldsTemplateProperties.All))
            {
                if (template.Name == sampleFieldTemplateName)
                {
                    newTM.FieldsTemplate = tmServer.GetFieldsTemplate(
                        templatePath + sampleFieldTemplateName, FieldsTemplateProperties.Fields);
                    break;
                }
            }

            string sampleLanguageResourcesTemplateName = "MyLanguageResourcesTemplate";
            foreach (ServerBasedLanguageResourcesTemplate template in tmServer.GetLanguageResourcesTemplates(
                         LanguageResourcesTemplateProperties.LanguageResources))
            {
                if (template.Name == sampleLanguageResourcesTemplateName)
                {
                    newTM.LanguageResourcesTemplate = tmServer.GetLanguageResourcesTemplate(
                        templatePath + sampleLanguageResourcesTemplateName, LanguageResourcesTemplateProperties.None);
                    break;
                }
            }
            #endregion


            newTM.Save();
        }