Skip to content

Instantly share code, notes, and snippets.

View cromica's full-sized avatar

Romulus Crisan cromica

View GitHub Profile
@cromica
cromica / 0_reuse_code.js
Created August 22, 2014 07:38
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@cromica
cromica / GetStudioProjectPath
Last active August 29, 2015 14:07
Sample code to get Studio 2014 project path
public string GetStudioProjectPath(string projectName)
{
var folderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var sdlProjectPath = Path.Combine(folderPath,string.Format("Studio 2014\\Projects\\{0}",projectName));
return sdlProjectPath;
}
@cromica
cromica / gist:4c9886d356eadb407d4a
Created October 21, 2014 10:27
Get translation unit context for Studio TM
public override SearchResults[] SearchTranslationUnitsMasked(SearchSettings settings, TranslationUnit[] translationUnits, bool[] mask)
{
var results = base.SearchTranslationUnitsMasked(settings, translationUnits, mask);
//iterate thru results and take the translation units which have context now
return results;
}
@cromica
cromica / AddTranslationMemorySdk.cs
Created December 12, 2014 15:01
Add Translation Memory to a project using Studio SDK
//create a translation provider entry and specify the path to the tm
var entry = new TranslationProviderCascadeEntry(@"path to the tm", true, true, true);
//get default project translation provider configuration
var providerConfiguration = project.GetTranslationProviderConfiguration();
//override project default settings in order to allow us to specify tm's
providerConfiguration.OverrideParent = true;
//add the translation provider to the configuration
providerConfiguration.Entries.Add(entry);
//set tm for all language pairs
project.UpdateTranslationProviderConfiguration(providerConfiguration);
@cromica
cromica / GetComponentBuilderExtensionPoint.cs
Last active August 29, 2015 14:15
Sample code on how you can get a file type component builder using SDL Studio Core API - this sample is obtaining the xml template builder
IExtensionPoint extensionPoint = PluginManager.DefaultPluginRegistry.GetExtensionPoint<FileTypeComponentBuilderAttribute>();
foreach (IExtension extension in extensionPoint.Extensions)
{
IFileTypeComponentBuilder extensionFileTypeComponentBuilder = (IFileTypeComponentBuilder) extension.CreateInstance();
extensionFileTypeComponentBuilder.FileTypeManager = fileTypeManager;
IFileTypeInformation extensionFileTypeInformation = extensionFileTypeComponentBuilder.BuildFileTypeInformation(string.Empty);
string extensionFileTypeDefinitionId = extensionFileTypeInformation.FileTypeDefinitionId.Id;
FileTypeComponentBuilderAttribute attr = extension.ExtensionAttribute as FileTypeComponentBuilderAttribute;
if (Equals(extensionFileTypeDefinitionId, "XML v 1.2.0.0") && attr.IsTemplate)
{
@cromica
cromica / MergeFiles.cs
Created March 11, 2015 13:11
Sample code for merging files using SDL Studio Project Automation API
//specify project creation information
var pi = new ProjectInfo()
{
Name = "Your project name",
LocalProjectFolder = @"Project path",
CreatedBy = "name of the person who created the project",
SourceLanguage = new Language(new CultureInfo("source language")),
TargetLanguages = new[] {new Language(new CultureInfo("target language"))}
};
@cromica
cromica / Program.cs
Created May 20, 2015 11:30
Sample code on how to add Groupshare TM in SDL Studio
var studioProject = new FileBasedProject(@"Project path");
var projectTargetLanguage = new Language("ES-ES");
TranslationProviderConfiguration tmConf =
studioProject.GetTranslationProviderConfiguration();
tmConf.OverrideParent = true;
tmConf.Entries.Add(
(
@cromica
cromica / DisableVerifiers.cs
Last active August 29, 2015 14:21
Disable global verifiers for an SDL Studio project
//load the project
var studioProject = new FileBasedProject(@"{Project file path}");
//get the project settings as settings bundle
ISettingsBundle settingsBundle = studioProject.GetSettings();
//obtain all global verifiers registered
IExtensionPoint globalVerifiersExtensionPoint = PluginManager.DefaultPluginRegistry.GetExtensionPoint<GlobalVerifierAttribute>());
if (globalVerifiersExtensionPoint != null)
{
@cromica
cromica / SegmentTranslatioOnDemand.cs
Created May 28, 2015 09:37
sample code for translating a segment on demand
[Action("SDL.Community.ManageMT.Translate", Name = "Translate", Icon = "icon", Description = "Translate current segment in the editor")]
[ActionLayout(typeof(ControlledMTProvidersRibbon), 60, DisplayType.Normal)]
[Shortcut(Keys.Alt | Keys.T)]
class ControlledMtTranslateViewPartAction : AbstractAction
{
private EditorController _editorController;
private bool _disableMt = CascadeLanguageDirection.DisableMt;
public ControlledMtTranslateViewPartAction()
{
@cromica
cromica / GetSegmentPairsFromParagraph.cs
Created May 28, 2015 10:46
sample code showing how you can obtain the segment pairs of a paragraph using SDL Studio Integration API
var activeParagraphProperties =
_editorController.ActiveDocument.ActiveSegmentPair.GetParagraphUnitProperties();
var segmentPairs = _editorController.ActiveDocument.GetSegmentPairsFromParagraph(activeParagraphProperties.ParagraphUnitId).ToList();
foreach (var segmentPair in segmentPairs)
{
//do some processing on the segment pairs
}