Created
October 2, 2018 13:01
-
-
Save andreaGhisa/33dc13bed8df734ae5c69b0787406234 to your computer and use it in GitHub Desktop.
CreateServerBasedTm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ApplicationInitializer] | |
public class Create : IApplicationInitializer | |
{ | |
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(); | |
} | |
} | |
private void CreateLanguageDirections(ServerBasedTranslationMemoryLanguageDirectionCollection directionsCollection) | |
{ | |
var direction = new ServerBasedTranslationMemoryLanguageDirection | |
{ | |
SourceLanguage = CultureInfo.GetCultureInfo("en-US"), | |
TargetLanguage = CultureInfo.GetCultureInfo("de-DE") | |
}; | |
directionsCollection.Add(direction); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment