Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

A pseudo translator is a piece of code that "translates" text in an automated manner. For example, it may convert all source text to upper case, inject special characters or make the translation longer or shorter. Such approaches are commonly used by software localization teams during development and testing. They are also useful to simply test Beebox translation workflows without having to resort to real translators or (slower or cost incurring) machine translation.Adding your algorithm is just The Beebox user interface lets users find text segments by a large variety of filter criteria. Built-in filters permit to look for untranslated content, problems with embedded codes, etc: 

Image Added

 

You can add your own filters to this list. This is done in a few steps:

  1. Add a class that implements the IBeeboxPseudoTranslator interfaceextendst BeeboxTextFilter.
  2. Code the TranslateIsMatch() method. It receives one segment at a source text time and returns the translated texttrue if the segment passes the filter.
  3. Compile and install your dll.

The code below is a sample implementation. All interface methods are verbosely commented and should be self-explanatory.

Sample class

The Beebox extension below adds a simple pseudo translator that converts source text to uppercasefilter that yields segments that are not translated: A simple but fundamental quality assurance algorithm.

 

Code Block
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wordbee.Beebox.Extensibility;
 
 
namespace Acme.PseudoTranslationSample
{
 
	/// <summary>
	/// This is a samplesimple Beebox extension that adds a simpletext pseudofilter translation option to the Beebox.
	/// If you want to add multiple algorithms, then add multiple classes to your dll and assign them different "ExtensionID"suser interface.
	/// </summary>
	[Serializable]
	public class SamplePseudoTranslatorSampleTextFilter : MarshalByRefObject, IBeeboxPseudoTranslator
	{
 
		/// <summary>
		/// Keeps extension alive. This code is mandatory or your extension won't work.
		/// </summary>
		/// <returns></returns>
		public override object InitializeLifetimeService() { return null; }
 BeeboxTextFilter
	{
 
		/// <summary>
		/// Gets the globally unique id of this extension.
		/// </summary>
		public override string ExtensionID { get { return "acme1acme2"; } }
 
 
		/// <summary>
		/// Gets if the extension is by default enabled. If false, then it must be enabled explicitly in each
		/// Beebox project from the Beebox Admin UI.
		/// </summary>
		public override bool EnableByDefault { get { return true; } }
 
 
 
		/// <summary>
		/// Gets a name. Displayed in the Beebox extension manager page.
		/// </summary>
		public override string Name { get { return "Acme translatorQA filter"; } }
 
 
		/// <summary>
		/// Gets the title of the algorithm shown in the user interface such as the "Actions" tool where a user can pseudo translate
		/// selected content.
		/// </summary>
		public override string UITitle { get { return "Acme translator- Missing translations"; } }
 
 
		/// <summary>
		/// Gets a description. Displayed in the Beebox extension manager page.
		/// </summary>
		public override string Description { get { return "Some words on my algorithm..."; } }
 
 
		/// <summary>
		/// Gets version number. Displayed in the Beebox extension manager page.
		/// </summary>
		public override string Version { get { return "1.0"; } }
 
 
		/// <summary>
		/// Gets the author. Displayed in the Beebox extension manager page.
		/// </summary>
		public override string Author { get { return "Acme Ltd"; } }
 
 
 
 
		/// <summary>
		/// OverrideReturn totrue implementif yourthe machinesegment translation algorithm.
		/// Return null to not translate the source textpasses the filter. Otherwise do return the translationfalse.
		/// </summary>
		/// Basically this method is called<param name="segment">
		/// Segment details with each source text., translation and additional properties:
		/// - Translate "text" and return the result.
Source: The original text
		/// - ReturnTarget: nullThe iftranslated the source text shall(can be leftnull asor is.
		/// </summary>
		/// <param name="text">The text to translate</param>
"" to indicate no translation yet)
		/// <param name="sourceLocale">The ISO code of the source language</param>
- SourceLocale: The source language code
		/// <param name="targetLocale">The ISO code of the target language</param>
- TargetLocale: The target language code
		/// <param name="context">Contains additional information on the segment including the project key and the source file containing the text.</param>- Status: The Quality Assurance status: 0 = not set, 1 = QA Ok, 2 = QA Error
		/// <returns>
		/// Return the translated text.- Validated: The translation currently is approved or not
		/// Return- nullLocked: toThe nottranslation changeis thelocked currentfor translation (null will not clear the translation!)editing by the user
		/// </returns>
		public string Translate(string text, string sourceLocale, string targetLocale, SegmentContext context)
		{
			StringBuilder sb = new StringBuilder(text.Length);
			
			// This sample shows how to pseudo translate by converting all characters to uppercase.
			// The code is a bit more complicate than one might imagine... The reason is that the
			// source text may contain "markup". Think of html tags such as in "Click <a>here</a>".
			// We do not want markup converted and so we must have some logic to skip markup when transforming text.
 
			bool intag = false;
			foreach (char ch in text)
			{
				// Skip any markup. Markup is enclosed between special codes (char)1 and (char)2.
				if (ch == ExtensionsHelper.TAG_MARKER_CLOSE) { sb.Append(ch); intag = false; continue; }		// We have finished markup
				if (ch == ExtensionsHelper.TAG_MARKER_OPEN) intag = true;									// Markup is starting here
				if (intag) { sb.Append(ch); continue; }														// In the middle of markup
 
				// Now we transform the character to uppercase
				sb.Append(char.ToUpper(ch));
			}
 
			return sb.ToString();
		}
 
 
 
 
	}
}- File: The file name containing the segment
		/// - Project: The project key
		/// - Key: Gets the segment key or the context of the segment. File format dependent: "Heading 1", "Hyperlink", ...
		/// - SourcePrevious: The text just before this segment
		/// - SourceNext: The text just after this segment
		/// </param>
		/// <param name="configuration">The extension's parameters. You need to implement the respective virtual methods to permit configuring the parameter individually per project.</param>
		/// <returns>
		/// True: The filter retains the segment
		/// False: The filter discards the segment
		/// </returns>
		public override bool IsMatch(Segment segment, IExtensionConfiguration configuration)
		{
			// We want all empty translations!
			if (string.IsNullOrWhiteSpace(segment.Target)) return true;
 
			// Those with content we skip!
			return false;
		}
 
 
	}
}