/// <summary>
        ///     Initializes a new instance of the <see cref="TranslateDocuments" /> class.
        /// </summary>
        /// <param name="Logger">
        ///     The logger.
        /// </param>
        public TranslateDocuments(ConsoleLogger Logger)
            : base(Logger)
        {
            TranslationServiceFacade.Initialize();
            if (!TranslationServiceFacade.IsTranslationServiceReady())
            {
                this.Logger.WriteLine(LogLevel.Error, "Invalid translation service credentials. Use \"DocumentTranslatorCmd setcredentials\", or use the Document Translator Settings option.");
            }

            this.sourceDocuments = new SimpleStringArgument(
                "SourceDocuments",
                true,
                new[] { ',' },
                "Document to translate, or list of documents separated by comma, or a wildcard. Wildcard recurses through subfolders.");

            this.sourceLanguage = new Argument(
                "SourceLanguage",
                false,
                new[] { "Auto-Detect" },
                TranslationServiceFacade.AvailableLanguages.Keys.ToArray(),
                true,
                "The source language. Auto-detect if no language specified.");

            this.targetLanguages = new SimpleStringArgument(
                "TargetLanguages",
                true,
                new string[] { },
                TranslationServiceFacade.AvailableLanguages.Keys.ToArray(),
                new[] { ',' },
                "The target language code, or comma-separated list of language codes.");

            this.Arguments = new ArgumentList(
                new[] { this.sourceDocuments, this.sourceLanguage, this.targetLanguages },
                Logger);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ArgumentList" /> class.
        /// </summary>
        /// <param name="args">
        ///     The args.
        /// </param>
        /// <param name="logger">
        ///     The logger.
        /// </param>
        public ArgumentList(Argument[] args, ILogger logger)
        {
            this.list = new Hashtable();
            this.internalOrderedArgNames = new ArrayList();
            if (args != null)
            {
                this.Set(args);
            }

            this.Logger = logger;
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="TmxToCtf" /> class.
        /// </summary>
        /// <param name="Logger">
        ///     The logger.
        /// </param>
        public TmxToCtf(ConsoleLogger Logger)
            : base(Logger)
        {
            TranslationServiceFacade.Initialize();
            if (!TranslationServiceFacade.IsTranslationServiceReady())
            {
                this.Logger.WriteLine(LogLevel.Error, "Invalid translation service credentials. Use \"DocumentTranslatorCmd setcredentials\", or use the Document Translator Settings option.");
                return;
            }

            this.TmxDocument = new SimpleStringArgument(
                "Tmx",
                true,
                new[] { ',' },
                "TMX Document to upload to CTF.");

            this.sourceLanguage = new Argument(
                "From",
                true,
                new[] { "Auto-Detect" },
                TranslationServiceFacade.AvailableLanguages.Keys.ToArray(),
                true,
                "The source language code. Must be a valid Microsoft Translator language code, and the same as language code used in the TMX, or mapped via TmxLangMap.csv (from, to).");

            this.targetLanguage = new Argument(
                "To",
                true,
                new string[] { "de" },
                TranslationServiceFacade.AvailableLanguages.Keys.ToArray(),
                true,
                "The target language code. Must be a valid Microsoft Translator language code, and the same as language code used in the TMX, or mapped via TmxLangMap.csv (from, to).");

            this.user = new Argument(
                "User",
                false,
                "The user ID recorded in CTF. Default: TmxUpload.");

            this.rating = new Argument(
                "Rating",
                false,
                "The rating with which the entries are created. Must be an integer 1..10. 5 or higher overrides MT. Default: 6.");

            this.boolWrite = new BooleanArgument(
                "Write",
                false,
                false,
                "Write to CTF.");

            this.Arguments = new ArgumentList(
                new[] { this.TmxDocument, this.sourceLanguage, this.targetLanguage, this.user, this.rating, this.boolWrite },
                Logger);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Initializes a new instance of the TranslateXML class.
        /// </summary>
        /// <param name="Logger">
        ///     The logger.
        /// </param>
        public TranslateXML(ConsoleLogger Logger)
            : base(Logger)
        {
            TranslationServiceFacade.Initialize();
            if (!TranslationServiceFacade.IsTranslationServiceReady())
            {
                this.Logger.WriteLine(LogLevel.Error, "Invalid translation service credentials. Use \"DocumentTranslatorCmd setcredentials\", or use the Document Translator Settings option.");
                return;
            }

            this.xmltotranslate = new Argument(
                "XML",
                true,
                "The XML file in need of translation");

            this.elementsdispositioncsv = new Argument(
                "Elements",
                true,
                "CSV file listing the elements to translate");

            this.fromlanguage = new Argument(
                "from",
                false,
                new[] { "Auto-Detect" },
                TranslationServiceFacade.AvailableLanguages.Keys.ToArray(),
                true,
                "The source language. Auto-detect if no language specified.");

            this.tolanguage = new SimpleStringArgument(
                "to",
                true,
                new string[] { },
                TranslationServiceFacade.AvailableLanguages.Keys.ToArray(),
                new[] { ',' },
                "The target language code, or comma-separated list of language codes.");

            this.generatecsv = new BooleanArgument(
                "generate",
                false,
                false,
                "Set to true if you want to generate a list of elements.");

            this.Arguments = new ArgumentList(
                new[] { this.xmltotranslate, this.elementsdispositioncsv, this.fromlanguage, this.tolanguage, this.generatecsv},
                Logger);
        }
Ejemplo n.º 5
0
        public CtfToTmx(ConsoleLogger Logger)
            : base(Logger)
        {
            TranslationServiceFacade.Initialize();
            if (!TranslationServiceFacade.IsTranslationServiceReady())
            {
                this.Logger.WriteLine(LogLevel.Error, "Invalid translation service credentials. Use \"DocumentTranslatorCmd setcredentials\", or use the Document Translator Settings option.");
                return;
            }

            this.TmxDocument = new SimpleStringArgument(
                "Tmx",
                true,
                new[] { ',' },
                "TMX Document to create.");

            this.sourceLanguage = new Argument(
                "From",
                false,
                new[] { "" },
                TranslationServiceFacade.AvailableLanguages.Keys.ToArray(),
                true,
                "The source language code. Must be a valid Microsoft Translator language code, and the same as language code used in the CTF store. Mapped to TMX language code in TmxLangMap.csv.");

            this.targetLanguage = new Argument(
                "To",
                false,
                new[] { "" },
                TranslationServiceFacade.AvailableLanguages.Keys.ToArray(),
                true,
                "The target language code. Must be a valid Microsoft Translator language code, and the same as language code used in the CTF store. Mapped to TMX language code in TmxLangMap.csv.");

            this.user = new Argument(
                "User",
                false,
                "If provided, filter by the given user. The default user name for data uploaded using this tool is TmxUpload. Download is not filtered by default.");

            this.rating = new Argument(
                "Rating",
                false,
                "The download can be filtered by rating. Default is no filtering.");

            this.Arguments = new ArgumentList(
                new[] { this.TmxDocument, this.sourceLanguage, this.targetLanguage, this.user, this.rating },
                Logger);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="SetCredentials" /> class.
        /// </summary>
        /// <param name="Logger">
        ///     The logger.
        /// </param>
        public SetCredentials(ConsoleLogger Logger)
            : base(Logger)
        {
            this.clientID = new Argument(
                "clientID",
                true,
                "Client ID to use for the calls to the Translator service.");

            this.clientSecret = new Argument(
                "clientSecret",
                true,
                "Client secret to use for the calls to the Translator service.");

            this.categoryID = new Argument(
                "categoryID",
                false,
                "Translator Hub category ID to use for calls to the translator service.");

            this.Arguments = new ArgumentList(
                new[] { this.clientID, this.clientSecret, this.categoryID },
                Logger);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     The verify function.
        /// </summary>
        /// <param name="argument">
        ///     The argument.
        /// </param>
        /// <returns>
        ///     The <see cref="bool" />.
        /// </returns>
        public static bool VerifyInt32(Argument argument)
        {
            // TO BE DONE : USE regex instead of Parse call
            foreach (string argValue in argument.Values)
            {
                int.Parse(argValue, CultureInfo.InvariantCulture);
            }

            return true;
        }
Ejemplo n.º 8
0
        /// <summary>
        ///     The verify boolean.
        /// </summary>
        /// <param name="argument">
        ///     The argument.
        /// </param>
        /// <returns>
        ///     The <see cref="bool" />.
        /// </returns>
        public static bool VerifyBoolean(Argument argument)
        {
            bool valuesValid = true;

            // Declare a regular expression comprising of strings "true" or "false"
            var booleanRegex = new Regex("true|false");

            foreach (string argValue in argument.Values)
            {
                // Matching the user specified string against the regular expression
                Match m = booleanRegex.Match(argValue);
                if (!m.Success)
                {
                    valuesValid = false;
                }
            }

            return valuesValid;
        }
Ejemplo n.º 9
0
 /// <summary>
 ///     The split argument values.
 /// </summary>
 /// <param name="separators">
 ///     The separators.
 /// </param>
 /// <param name="argument">
 ///     The argument.
 /// </param>
 public static void SplitArgumentValues(char[] separators, Argument argument)
 {
     int last = argument.Values.Count;
     for (int i = 0; i < last; i++)
     {
         var argValue = (string)argument.Values[i];
         if (argValue.IndexOfAny(separators) >= 0)
         {
             string[] argValues = argValue.Split(separators);
             argument.Values[i] = argValues[0];
             var newValues = new string[argValues.Length - 1];
             Array.Copy(argValues, 1, newValues, 0, newValues.Length);
             argument.Values.AddRange(newValues);
         }
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 ///     The set.
 /// </summary>
 /// <param name="args">
 ///     The args.
 /// </param>
 private void Set(Argument[] args)
 {
     foreach (Argument argument in args)
     {
         this.Set(argument);
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 ///     The set.
 /// </summary>
 /// <param name="argument">
 ///     The argument.
 /// </param>
 private void Set(Argument argument)
 {
     this.list[argument.Name.ToLower(CultureInfo.InvariantCulture).Trim()] = argument;
     this.internalOrderedArgNames.Add(argument.Name.ToLower(CultureInfo.InvariantCulture).Trim());
 }
Ejemplo n.º 12
0
        /// <summary>
        ///     The parse.
        /// </summary>
        /// <param name="args">
        ///     The args.
        /// </param>
        /// <param name="extraArguments">
        ///     The extra arguments.
        /// </param>
        /// <returns>
        ///     The <see cref="bool" />.
        /// </returns>
        public bool Parse(string[] args, Argument[] extraArguments)
        {
            var internalArgs = (string[])args.Clone();
            foreach (Argument argument in this.list.Values)
            {
                if (!argument.ParseAndConsume(internalArgs))
                {
                    this.Logger.WriteLine(
                        LogLevel.Error,
                        "ERROR: Argument [{0}] did not get a valid value from user.",
                        argument.Name);
                    return false;
                }

                this.Logger.WriteLine(
                    LogLevel.Debug,
                    "Argument [{0}] has value [{1}].",
                    argument.Name,
                    argument.ValueString);
            }

            foreach (Argument argument in extraArguments)
            {
                if (!argument.ParseAndConsume(internalArgs))
                {
                    this.Logger.WriteLine(
                        LogLevel.Error,
                        "ERROR: Argument [{0}] did not get a valid value from user.",
                        argument.Name);
                    return false;
                }

                this.Logger.WriteLine(
                    LogLevel.Debug,
                    "Argument [{0}] has value [{1}].",
                    argument.Name,
                    argument.ValueString);
            }

            // If there are any Arguments left we consider
            // it an error too.
            foreach (string argument in internalArgs)
            {
                if (argument != null)
                {
                    this.Logger.WriteLine(LogLevel.Error, "ERROR: Unknown input argument [{0}].", argument);
                    return false;
                }
            }

            return true;
        }