예제 #1
0
        public void Awake()
        {
            DontDestroyOnLoad(this);

            MethodInfo processAndRequestMethod = typeof(UILabel).GetMethod("ProcessAndRequest");

            processAndRequest = label => processAndRequestMethod?.Invoke(label, null);

            Memory    = new TranslationMemory(DataPath);
            Clipboard = gameObject.AddComponent <Clipboard>();
            Subtitles = gameObject.AddComponent <Subtitles>();

            InitConfig();

            Memory.LoadTranslations();

            TranslationHooks.TranslateText    += OnTranslateString;
            TranslationHooks.AssetTextureLoad += OnAssetTextureLoad;
            TranslationHooks.ArcTextureLoad   += OnTextureLoad;
            TranslationHooks.SpriteLoad       += OnTextureLoad;
            TranslationHooks.ArcTextureLoaded += OnArcTextureLoaded;
            TranslationHooks.TranslateGraphic += OnTranslateGraphic;
            TranslationHooks.PlaySound        += OnPlaySound;
            TranslationHooks.GetOppositePair  += OnGetOppositePair;
            TranslationHooks.GetOriginalText  += OnGetOriginalText;
            Logger.WriteLine("Hooking complete");
        }
예제 #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a new instance of a localization manager for the specified application id.
        /// If a localization manager has already been created for the specified id, then
        /// that is returned.
        /// </summary>
        /// <param name="kind">Translation memory type to use</param>
        /// <param name="desiredUiLangId">The language code of the desired UI language. If
        /// there are no translations for that ID, a message is displayed and the UI language
        /// falls back to the default.</param>
        /// <param name="appId">The application Id (e.g. 'Pa' for Phonology Assistant).
        /// This should be a unique name that identifies the manager for an assembly or
        /// application.</param>
        /// <param name="appName">The application's name. This will appear to the user
        /// in the localization dialog box as a parent item in the tree.</param>
        /// <param name="appVersion"></param>
        /// <param name="directoryOfInstalledFiles">The full folder path of the original Xliff/TMX
        /// files installed with the application.</param>
        /// <param name="relativeSettingPathForLocalizationFolder">The path, relative to
        /// %appdata%, where your application stores user settings (e.g., "SIL\SayMore").
        /// A folder named "localizations" will be created there.</param>
        /// <param name="applicationIcon"> </param>
        /// <param name="emailForSubmissions">This will be used in UI that helps the translator
        /// know what to do with their work</param>
        /// <param name="namespaceBeginnings">A list of namespace beginnings indicating
        /// what types to scan for localized string calls. For example, to only scan
        /// types found in Pa.exe and assuming all types in that assembly begin with
        /// 'Pa', then this value would only contain the string 'Pa'.</param>
        /// ------------------------------------------------------------------------------------
        public static ILocalizationManager Create(TranslationMemory kind, string desiredUiLangId,
                                                  string appId, string appName, string appVersion, string directoryOfInstalledFiles,
                                                  string relativeSettingPathForLocalizationFolder,
                                                  Icon applicationIcon, string emailForSubmissions, params string[] namespaceBeginnings)
        {
            TranslationMemoryKind = kind;
            EmailForSubmissions   = emailForSubmissions;
            switch (kind)
            {
            case TranslationMemory.Tmx:
                return(LocalizationManagerInternal <TMXDocument> .CreateTmx(desiredUiLangId,
                                                                            appId, appName, appVersion, directoryOfInstalledFiles,
                                                                            relativeSettingPathForLocalizationFolder, applicationIcon,
                                                                            namespaceBeginnings));

            case TranslationMemory.XLiff:
                return(LocalizationManagerInternal <XLiffDocument> .CreateXliff(desiredUiLangId,
                                                                                appId, appName, appVersion, directoryOfInstalledFiles,
                                                                                relativeSettingPathForLocalizationFolder, applicationIcon,
                                                                                namespaceBeginnings));

            default:
                throw new ArgumentException($"Unknown translation memory kind {kind}",
                                            nameof(kind));
            }
        }
예제 #3
0
        private void AddLanguagesFromTmToCombo(string tmFilePath)
        {
            var oTm = new TranslationMemory();

            oTm.Open($"{tmFilePath.Replace(".tmw", string.Empty)}.mdf", Environment.UserName,
                     TmAccess.tmaTmAccessMode.tmaTmAccessRead, null, 0);
            _sourceLangLcid = oTm.Setup.SourceLocale;
            _targetLangLcid = oTm.Setup.TargetLocales;
            try
            {
                var ci = new CultureInfo(Convert.ToInt32(_sourceLangLcid));
                txtSourceLanguage.Text = ci.DisplayName;
                var targetLanguages = _targetLangLcid.Split(',');
                txtTargetLanguage.Text = string.Empty;
                foreach (var targetLanguage in targetLanguages)
                {
                    var tci = new CultureInfo(Convert.ToInt32(targetLanguage));
                    txtTargetLanguage.Text += tci.DisplayName + ",";
                }
                if (txtTargetLanguage.Text != string.Empty)
                {
                    txtTargetLanguage.Text = txtTargetLanguage.Text.Substring(0, txtTargetLanguage.Text.Length - 1);
                }

                HelpTooltip.SetToolTip(txtSourceLanguage, txtSourceLanguage.Text);
                HelpTooltip.SetToolTip(txtTargetLanguage, txtTargetLanguage.Text);
            } catch (Exception e)
            {
            }
            oTm.Close();
        }
예제 #4
0
 private void JishEdit_Load(object sender, EventArgs _e)
 {
     TranslationMemory.LoadFromFile();
     Dictionary <string, string> .Enumerator e = TranslationMemory.GetEnumerator();
     while (e.MoveNext())
     {
         AddEntry(e.Current.Key, e.Current.Value);
     }
 }
예제 #5
0
        public override void UpdateFromMemory()
        {
            string s = TranslationMemory.GetEntry(JapText);

            if (s.Length > 0)
            {
                txtEng.Text = TranslationMemory.GetEntry(JapText);
            }
        }
 public override void UpdateFromMemory()
 {
     foreach (GenericTArgOpts arg in commandArgs)
     {
         if (arg.memoryStore)
         {
             int idx = commandArgs.IndexOf(arg);
             engs[idx].Text = TranslationMemory.GetEntry(japs[idx].Text);
         }
     }
 }
예제 #7
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Creates a new instance of a localization manager for the specified application id.
 /// If a localization manager has already been created for the specified id, then
 /// that is returned.
 /// </summary>
 /// <param name="kind">Translation memory type to use</param>
 /// <param name="desiredUiLangId">The language code of the desired UI language. If
 /// there are no translations for that ID, a message is displayed and the UI language
 /// falls back to the default.</param>
 /// <param name="appId">The application Id (e.g. 'Pa' for Phonology Assistant).
 /// This should be a unique name that identifies the manager for an assembly or
 /// application.</param>
 /// <param name="appName">The application's name. This will appear to the user
 /// in the localization dialog box as a parent item in the tree.</param>
 /// <param name="appVersion"></param>
 /// <param name="directoryOfInstalledFiles">The full folder path of the original Xliff/TMX
 /// files installed with the application.</param>
 /// <param name="relativeSettingPathForLocalizationFolder">The path, relative to
 /// %appdata%, where your application stores user settings (e.g., "SIL\SayMore").
 /// A folder named "localizations" will be created there.</param>
 /// <param name="applicationIcon"> </param>
 /// <param name="emailForSubmissions">This will be used in UI that helps the translator
 /// know what to do with their work</param>
 /// <param name="namespaceBeginnings">A list of namespace beginnings indicating
 /// what types to scan for localized string calls. For example, to only scan
 /// types found in Pa.exe and assuming all types in that assembly begin with
 /// 'Pa', then this value would only contain the string 'Pa'.</param>
 /// ------------------------------------------------------------------------------------
 public static ILocalizationManager Create(TranslationMemory kind, string desiredUiLangId,
                                           string appId, string appName, string appVersion, string directoryOfInstalledFiles,
                                           string relativeSettingPathForLocalizationFolder,
                                           Icon applicationIcon, string emailForSubmissions, params string[] namespaceBeginnings)
 {
     return(Create(kind, desiredUiLangId,
                   appId, appName, appVersion, directoryOfInstalledFiles,
                   relativeSettingPathForLocalizationFolder,
                   applicationIcon, emailForSubmissions,
                   null, namespaceBeginnings));
 }
예제 #8
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     TranslationMemory.Clear();
     foreach (JishEntry je in panel1.Controls)
     {
         if (je.GetLeft() != "" && je.GetRight() != "")
         {
             TranslationMemory.AddEntry(je.GetLeft(), je.GetRight());
         }
     }
     TranslationMemory.WriteToFile();
 }
예제 #9
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Setup for each test.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected void TestSetup(TranslationMemory kind, string installedTranslationDir)
        {
            var dir = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);

            m_manager = LocalizationManager.Create(kind, "en", "Test", "Test", "1.0",
                                                   Path.Combine(dir, installedTranslationDir),
                                                   "", null, "")
                        as ILocalizationManagerInternal <T>;
            m_translationPath = m_manager.GetPathForLanguage("en", true);
            m_extender        = new L10NSharpExtender {
                LocalizationManagerId = "Test"
            };
        }
예제 #10
0
        public void Initialize(Guid id)
        {
            var connectionString = Settings.GetStringDB();

            //TOD нужно передавать глассарий
            //memoryId = Guid.Parse("47faa0d8-56da-4e09-b151-ded06b587338");
            memoryId = id;
            gsr      = new TranslationMemoryRepository(connectionString);
            IEnumerable <TranslationMemory> gList = gsr.GetForEditAsync(memoryId).Result;
            List <TranslationMemory>        tt    = gList.ToList();

            memory = tt[0];
            //TODO нужно обработать создание нового глоссария, если текущего нет

            glossaryRep = new GlossaryRepository(connectionString);
            tWriter     = new TranslationWriter(_localDefault);
            ts          = new TranslationSubstringRepository(connectionString);
        }
예제 #11
0
        /// <summary>
        /// Typically root directory of installed files is something like [application exe directory]/localizations.
        /// root directory of user modifiable tmx files has to be outside program files, something like
        /// GetXAppDataFolder()/localizations, where GetXAppDataFolder would typically return something like
        /// Company/Program (e.g. SIL/SayMore)
        /// </summary>
        /// <param name="kind"></param>
        /// <param name="desiredUiLangId"></param>
        /// <param name="rootDirectoryOfInstalledTranslationFiles">The folder path of the original TMX files
        /// installed with the application.  The Chorus TMX files will be in a Chorus subdirectory of this directory.</param>
        /// <param name="relativeDirectoryOfUserModifiedTranslationFiles">The path, relative to %APPDATA%, where your
        /// application stores user settings (e.g., "SIL\SayMore"). A folder named "Chorus\localizations" will be created there.</param>
        public static void SetUpLocalization(TranslationMemory kind, string desiredUiLangId,
                                             string rootDirectoryOfInstalledTranslationFiles, string relativeDirectoryOfUserModifiedTranslationFiles)

        {
            string directoryOfInstalledTmxFiles    = Path.Combine(rootDirectoryOfInstalledTranslationFiles, "Chorus");
            string directoryOfUserModifiedTmxFiles = Path.Combine(relativeDirectoryOfUserModifiedTranslationFiles, "Chorus");

            // This is safer than Application.ProductVersion, which might contain words like 'alpha' or 'beta',
            // which (on the SECOND run of the program) fail when L10NSharp tries to make a Version object out of them.
            var versionObj = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            // We don't need to reload strings for every "revision" (that might be every time we build).
            var version = "" + versionObj.Major + "." + versionObj.Minor + "." + versionObj.Build;

            LocalizationManager.Create(kind, desiredUiLangId, "Chorus",
                                       Application.ProductName, version, directoryOfInstalledTmxFiles,
                                       directoryOfUserModifiedTmxFiles,
                                       Icon.FromHandle(Properties.Resources.chorus32x32.GetHicon()), // should call DestroyIcon, but when?
                                       "*****@*****.**", "Chorus");
        }
예제 #12
0
        public ObservableCollection <TranslationMemory> GetTms(IEnumerable <string> files, ObservableCollection <TranslationMemory> tmCollection)
        {
            var newTmsCollection = new ObservableCollection <TranslationMemory>();

            foreach (var file in files)
            {
                if (IsValid(file))
                {
                    continue;
                }

                var fileBasedTm = new TranslationMemory(file);

                if (tmCollection.All(tm => tm.Name != fileBasedTm.Name))
                {
                    newTmsCollection.Add(fileBasedTm);
                }
            }

            return(newTmsCollection);
        }
예제 #13
0
        public void Awake()
        {
            DontDestroyOnLoad(this);

            if (!Directory.Exists(DataPath))
            {
                Directory.CreateDirectory(DataPath);
            }

            ConfigPath = Path.Combine(DataPath, "IMGUITranslationLoader.ini");

            Preferences = !File.Exists(ConfigPath) ? new IniFile() : IniFile.FromFile(ConfigPath);

            Memory = new TranslationMemory(DataPath);

            InitConfig();

            Memory.LoadTranslations();

            TranslationHooks.Translate = Translate;
            Logger.WriteLine("Hooking complete");
        }
예제 #14
0
 public override void UpdateFromMemory()
 {
     txtEng.Text = TranslationMemory.GetEntry(JapText);
 }
예제 #15
0
        private void AddLanguagesFromTmToCombo(string tmFilePath)
        {
            var oTm = new TranslationMemory();
            oTm.Open($"{tmFilePath.Replace(".tmw", string.Empty)}.mdf", Environment.UserName,
                                    TmAccess.tmaTmAccessMode.tmaTmAccessRead, null, 0);
            _sourceLangLcid = oTm.Setup.SourceLocale;
            _targetLangLcid = oTm.Setup.TargetLocales;
            try
            {
                var ci = new CultureInfo(Convert.ToInt32(_sourceLangLcid));
                txtSourceLanguage.Text = ci.DisplayName;
                var targetLanguages = _targetLangLcid.Split(',');
                txtTargetLanguage.Text = string.Empty;
                foreach (var targetLanguage in targetLanguages)
                {
                    var tci = new CultureInfo(Convert.ToInt32(targetLanguage));
                    txtTargetLanguage.Text += tci.DisplayName + ",";
                }
                if (txtTargetLanguage.Text != string.Empty) txtTargetLanguage.Text = txtTargetLanguage.Text.Substring(0, txtTargetLanguage.Text.Length - 1);

                HelpTooltip.SetToolTip(txtSourceLanguage, txtSourceLanguage.Text);
                HelpTooltip.SetToolTip(txtTargetLanguage, txtTargetLanguage.Text);
            } catch(Exception e)
            {
            }
            oTm.Close();
        }
예제 #16
0
        /// <summary>
        ///     The execute method.
        /// </summary>
        /// <returns>
        ///     The <see cref="bool" />.
        /// </returns>
        public override bool Execute()
        {
            string SntFileName = Path.GetTempPath() + "_TmxUpload.snt";
            string uservalue   = user.ValueString;

            if (uservalue == string.Empty)
            {
                uservalue = "TmxUpload";
            }
            string ratingvalue = rating.ValueString;

            if (ratingvalue == string.Empty)
            {
                ratingvalue = "6";
            }

            TmxFile TmxIn = new TmxFile(this.TmxDocument.ValueString);

            string[] sntFilenames = TmxIn.WriteToSNTFiles(SntFileName);
            if (sntFilenames.Length != 2)
            {
                Logger.WriteLine(LogLevel.Error, "More than 2 languages in the TMX file. Must have exactly 2.");
                deleteSNTfiles(sntFilenames);
                return(false);
            }

            TranslationMemory TM = new TranslationMemory();

            TM.sourceLangID = this.sourceLanguage.ValueString.ToLowerInvariant();
            TM.targetLangID = this.targetLanguage.ValueString.ToLowerInvariant();

            // Read langauge names from Tmx
            string TmxSourceLanguage = Path.GetFileNameWithoutExtension(sntFilenames[0]);

            TmxSourceLanguage = TmxSourceLanguage.Substring(TmxSourceLanguage.LastIndexOf('_') + 1).ToLowerInvariant();
            string TmxTargetLanguage = Path.GetFileNameWithoutExtension(sntFilenames[1]);

            TmxTargetLanguage = TmxTargetLanguage.Substring(TmxTargetLanguage.LastIndexOf('_') + 1).ToLowerInvariant();

            if (TmxSourceLanguage.Substring(0, 2) != TM.sourceLangID)
            {
                Logger.WriteLine(LogLevel.Error, "Source language mismatch between command line {0} and TMX language {1}. Please edit TmxLangMap.csv to fix. Aborting.", TM.sourceLangID, TmxSourceLanguage);
                deleteSNTfiles(sntFilenames);
                return(false);
            }

            if (TmxTargetLanguage.Substring(0, 2) != TM.targetLangID)
            {
                Logger.WriteLine(LogLevel.Error, "Target language mismatch between command line {0} and TMX language {1}. Please edit TmxLangMap.csv to fix. Aborting.", TM.targetLangID, TmxTargetLanguage);
                deleteSNTfiles(sntFilenames);
                return(false);
            }


            string[] sntSource = File.ReadAllLines(sntFilenames[0]);
            string[] sntTarget = File.ReadAllLines(sntFilenames[1]);
            if (sntSource.Length != sntTarget.Length)
            {
                Logger.WriteLine(LogLevel.Error, "Unequal number of segments. The TMX must have the same number of segments in the two given languages.");
                deleteSNTfiles(sntFilenames);
                return(false);
            }

            Logger.WriteLine(LogLevel.None, "{0} translation units read.", sntSource.Length);

            TmxWriter ErrorTmx = new TmxWriter(Path.GetFileNameWithoutExtension(this.TmxDocument.ValueString) + ".errors." + TmxSourceLanguage + "_" + TmxTargetLanguage + "." + DateTime.Now.ToString("yyyyMMddThhmmssZ") + ".tmx", TmxSourceLanguage, TmxTargetLanguage);

            //Load into TM and perform error check on each line.
            int ratioViolationCount    = 0; //counts number of ratio violations
            int sntCountViolationCount = 0; //counts number of unequal sentence count violation.

            for (int sntLineIndex = 0; sntLineIndex < sntSource.Length; sntLineIndex++)
            {
                //show a progress message.
                if ((sntLineIndex % 10) == 0)
                {
                    Logger.WriteLine(LogLevel.Debug, "{0} of {1} sentences aligned and error checked.", sntLineIndex, sntSource.Length);
                }

                //Length discrepancy check
                float ratio = Math.Abs(sntSource[sntLineIndex].Length / sntTarget[sntLineIndex].Length);
                if ((ratio > 3) && ((sntSource.Length > 15) || (sntTarget.Length > 15))) //skip the segment, and add to error.tmx
                {
                    Logger.WriteLine(LogLevel.Debug, "Length ratio exceeded. Segment skipped: {0}", sntSource[sntLineIndex].Substring(0, (60 < sntSource[sntLineIndex].Length)?60:sntSource[sntLineIndex].Length));
                    ratioViolationCount++;
                    ErrorTmx.TmxWriteSegment(sntSource[sntLineIndex], sntTarget[sntLineIndex], TmxSourceLanguage, TmxTargetLanguage, TmxWriter.TUError.lengthratio);

                    if ((ratioViolationCount / sntSource.Length) > 0.10)
                    {
                        Logger.WriteLine(LogLevel.Error, "Length ratio exceeded for 10% of segments. Probably not a translation. Aborting.");
                        deleteSNTfiles(sntFilenames);
                        return(false);
                    }
                    continue;
                }

                //TODO: special handling of bpt/ept
                sntSource[sntLineIndex] = System.Net.WebUtility.HtmlDecode(sntSource[sntLineIndex]);
                sntTarget[sntLineIndex] = System.Net.WebUtility.HtmlDecode(sntTarget[sntLineIndex]);

                //throw away segments with tags
                if ((sntSource[sntLineIndex].Contains("<") && sntSource[sntLineIndex].Contains(">")) && (sntTarget[sntLineIndex].Contains("<") && sntTarget[sntLineIndex].Contains(">")))
                {
                    Logger.WriteLine(LogLevel.Debug, "Tagged segment. Segment skipped: {0}", sntSource[sntLineIndex].Substring(0, (60 < sntSource[sntLineIndex].Length) ? 60 : sntSource[sntLineIndex].Length));
                    ErrorTmx.TmxWriteSegment(sntSource[sntLineIndex], sntTarget[sntLineIndex], TmxSourceLanguage, TmxTargetLanguage, TmxWriter.TUError.tagging);
                    continue;
                }

                //Encode the remaining <>&
                sntSource[sntLineIndex] = System.Net.WebUtility.HtmlEncode(sntSource[sntLineIndex]);
                sntTarget[sntLineIndex] = System.Net.WebUtility.HtmlEncode(sntTarget[sntLineIndex]);



                int[] sourceSentLengths = TranslationServiceFacade.BreakSentences(sntSource[sntLineIndex], TM.sourceLangID);
                int[] targetSentLengths = TranslationServiceFacade.BreakSentences(sntTarget[sntLineIndex], TM.targetLangID);

                //unequal sentence count violation check
                if (sourceSentLengths.Length != targetSentLengths.Length)
                {
                    sntCountViolationCount++;
                    Logger.WriteLine(LogLevel.Debug, "Unequal number of sentences in segment. Segment skipped: {0}", sntSource[sntLineIndex].Substring(0, (60 < sntSource[sntLineIndex].Length)?60:sntSource[sntLineIndex].Length));
                    ErrorTmx.TmxWriteSegment(sntSource[sntLineIndex], sntTarget[sntLineIndex], TmxSourceLanguage, TmxTargetLanguage, TmxWriter.TUError.sentencecountmismatch);

                    if ((sntCountViolationCount / sntSource.Length) > 0.10)
                    {
                        Logger.WriteLine(LogLevel.Error, "Unequal sentence count exceeded for 10% of segments. Probably not a translation. Aborting.");
                        deleteSNTfiles(sntFilenames);
                        return(false);
                    }
                    continue;
                }


                //Split multiple sentences
                int startIndexSrc = 0;
                int startIndexTgt = 0;
                for (int j = 0; j < sourceSentLengths.Length; j++)
                {
                    TranslationUnit TU = new TranslationUnit();
                    TU.strSource  = sntSource[sntLineIndex].Substring(startIndexSrc, sourceSentLengths[j]);
                    TU.strTarget  = sntTarget[sntLineIndex].Substring(startIndexTgt, targetSentLengths[j]);
                    startIndexSrc = sourceSentLengths[j];
                    startIndexTgt = targetSentLengths[j];
                    TU.rating     = int.Parse(ratingvalue);
                    TU.user       = uservalue.ToUpperInvariant();
                    TM.Add(TU);
                }
            }
            ErrorTmx.Dispose();


            //Add the whole TM list to CTF, if a CTF write was requested.

            if (boolWrite.ValueString.ToLowerInvariant() == "true")
            {
                int SentenceCount = 0;
                foreach (TranslationUnit TU in TM)
                {
                    TranslationServiceFacade.AddTranslation(TU.strSource, TU.strTarget, TM.sourceLangID, TM.targetLangID, TU.rating, TU.user);
                    if ((SentenceCount % 10) == 0)
                    {
                        Logger.WriteLine(LogLevel.Debug, "{0} of {1} sentences written. Continuing...", SentenceCount, sntSource.Length);
                    }
                    //Do not change the sleep time. This is slow and needs to be slow - the AddTranslation method is designed for interactive use.
                    Thread.Sleep(500);
                    SentenceCount++;
                }
                Logger.WriteLine(LogLevel.Msg, "{0} sentences written to CTF. Write complete. ", SentenceCount);
            }
            else
            {
                //Just list the entire TM on screen.
                foreach (TranslationUnit TU in TM)
                {
                    Logger.WriteLine(LogLevel.None, "{0} || {1}", TU.strSource, TU.strTarget);
                }
            }


            return(true);
        }
예제 #17
0
        private string getScope(WSAggregateTranslationScope aggscope, WSAssetTranslationScope scope, WSLocale locale, BaseExtendable mtdProject, IMTDService service, int sequence)
        {
            //create Quote Section

            // TODO: This line should probably go away. We should pass the correct entity relation so that the words counts are loaded in the correct Assessment and Quote sections.
            EntityVersion newVersion = new EntityVersion();

//            I don't think we need this here. We don't want to create a new quote and assessment section for every locale.
//            createQuoteSectionAndAssessment(service, mtdProject, newVersion, projName, projDescription);



            TranslationMemory memory = new TranslationMemory();
            int total_word_count     = 0;

            if (scope != null)
            {
                memory.Words_XTrans += scope.getIceWordCount;
                memory.Words_Rep    += scope.getRepetitionWordCount;
                memory.Words_100    += scope.getPerfectWordCount;
                memory.Words_95     += scope.getFuzzyWordCount[0];
                memory.Words_85     += scope.getFuzzyWordCount[1];
                memory.Words_75     += scope.getFuzzyWordCount[2];
                memory.Words_50     += scope.getFuzzyWordCount[3];
                memory.Words_NM     += scope.getFuzzyWordCount[4];
                total_word_count    += memory.Words_XTrans + memory.Words_Rep + memory.Words_100 + memory.Words_95 + memory.Words_85 + memory.Words_75 + memory.Words_50 + memory.Words_NM;
            }
            else  //aggregate scopes for 'auto' quote
            {
                foreach (WSAssetTranslationScope ats in aggscope.getScopes)
                {
                    memory.Words_XTrans += ats.getIceWordCount;
                    memory.Words_Rep    += ats.getRepetitionWordCount;
                    memory.Words_100    += ats.getPerfectWordCount;
                    memory.Words_95     += ats.getFuzzyWordCount[0];
                    memory.Words_85     += ats.getFuzzyWordCount[1];
                    memory.Words_75     += ats.getFuzzyWordCount[2];
                    memory.Words_50     += ats.getFuzzyWordCount[3];
                    memory.Words_NM     += ats.getFuzzyWordCount[4];
                    total_word_count    += memory.Words_XTrans + memory.Words_Rep + memory.Words_100 + memory.Words_95 + memory.Words_85 + memory.Words_75 + memory.Words_50 + memory.Words_NM;
                }
            }
            string custIID     = ConfigurationSettings.AppSettings["CUSTOMER_IID"];
            int    customerIID = Convert.ToInt32(custIID);
            string lang        = locale.getName.ToUpper();

            lang = lang.Replace(" - UTF8", "");  //Code lang names are LANG_LOCATION unlike lang name in WS
            lang = lang.Replace(" (", "_");
            lang = lang.Replace(")", "");

            //Code test = Code.FindAltType("LOC", "ar_EG");
            //use alternate_type to find code in MDL

            Code langCode = Code.Find("LOC", lang);

            QuoteItem[] existingItems = null;
            Rate        currRate      = null;
            string      retValue      = null;

            if (langCode != null)  //it should never be null, otherwise what is the translation?
            {
                currRate = service.LoadRate(customerIID, langCode);
            }
            else
            {
                retValue = "missing langCode for " + lang;
                return(retValue);
            }

            // Now do Translation memory Items
            Code wordCode = Code.Find("QUOTE_UNIT", "WORDS");

            if (total_word_count > 0)
            {
                // If separate ICE matches selected, split them into their own category, otherwise add them to REPS
                if (memory.Words_XTrans > 0)
                {
                    Code      repCode   = Code.Find("QUOTE_ITEM", "TRANSLATION_ICE");
                    QuoteItem storeItem = fetchMemItemMatch(newVersion, langCode, repCode, wordCode, memory.Words_XTrans, 0 /* currRate.Reps_Rate */, ref sequence, existingItems);
                    service.Store(storeItem);
                    retValue = retValue + " XTrans Quote IID " + storeItem.Quote_Item_IID;
                }
                if ((memory.Words_Rep + memory.Words_100) > 0)
                {
                    Code      repCode   = Code.Find("QUOTE_ITEM", "TRANSLATION_REPS");
                    QuoteItem storeItem = fetchMemItemMatch(newVersion, langCode, repCode, wordCode, (memory.Words_Rep + memory.Words_100), currRate.Reps_Rate, ref sequence, existingItems);
                    service.Store(storeItem);
                    retValue = retValue + " 100 Quote IID " + storeItem.Quote_Item_IID;
                }

                if ((memory.Words_95 + memory.Words_85 + memory.Words_75) > 0)
                {
                    Code      fuzzyCode = Code.Find("QUOTE_ITEM", "TRANSLATION_FUZZY");
                    QuoteItem storeItem = fetchMemItemMatch(newVersion, langCode, fuzzyCode, wordCode, memory.Words_95 + memory.Words_85 + memory.Words_75, currRate.Fuzzy_Rate, ref sequence, existingItems);
                    service.Store(storeItem);
                    retValue = retValue + " 95 Quote IID " + storeItem.Quote_Item_IID;
                }

                if ((memory.Words_50 + memory.Words_NM) > 0)
                {
                    Code      newCode   = Code.Find("QUOTE_ITEM", "TRANSLATION_NEW");
                    QuoteItem storeItem = fetchMemItemMatch(newVersion, langCode, newCode, wordCode, memory.Words_50 + memory.Words_NM, currRate.New_Rate, ref sequence, existingItems);
                    service.Store(storeItem);
                    retValue = retValue + " 50 Quote IID " + storeItem.Quote_Item_IID;
                }
            }

            // TODO: This should be imported into the assessment and quote section matching the Entity Relation
            return(retValue);
        }
예제 #18
0
        /// <summary>
        ///     The execute method.
        /// </summary>
        /// <returns>
        ///     The <see cref="bool" />.
        /// </returns>
        public override bool Execute()
        {
            string SntFileName = Path.GetTempPath() + "_TmxUpload.snt";
            string uservalue = user.ValueString;
            if (uservalue == string.Empty) uservalue = "TmxUpload";
            string ratingvalue = rating.ValueString;
            if (ratingvalue == string.Empty) ratingvalue = "6";

            TmxFile TmxIn = new TmxFile(this.TmxDocument.ValueString);
            string[] sntFilenames = TmxIn.WriteToSNTFiles(SntFileName);
            if (sntFilenames.Length != 2) {
                Logger.WriteLine(LogLevel.Error, "More than 2 languages in the TMX file. Must have exactly 2.");
                deleteSNTfiles(sntFilenames);
                return false;
            }

            TranslationMemory TM = new TranslationMemory();
            TM.sourceLangID = this.sourceLanguage.ValueString.ToLowerInvariant();
            TM.targetLangID = this.targetLanguage.ValueString.ToLowerInvariant();

            // Read langauge names from Tmx
            string TmxSourceLanguage = Path.GetFileNameWithoutExtension(sntFilenames[0]);
            TmxSourceLanguage = TmxSourceLanguage.Substring(TmxSourceLanguage.LastIndexOf('_') + 1).ToLowerInvariant();
            string TmxTargetLanguage = Path.GetFileNameWithoutExtension(sntFilenames[1]);
            TmxTargetLanguage = TmxTargetLanguage.Substring(TmxTargetLanguage.LastIndexOf('_') + 1).ToLowerInvariant();

            if (TmxSourceLanguage.Substring(0, 2) != TM.sourceLangID)
            {
                Logger.WriteLine(LogLevel.Error, "Source language mismatch between command line {0} and TMX language {1}. Please edit TmxLangMap.csv to fix. Aborting.", TM.sourceLangID, TmxSourceLanguage);
                deleteSNTfiles(sntFilenames);
                return false;
            }

            if (TmxTargetLanguage.Substring(0, 2) != TM.targetLangID)
            {
                Logger.WriteLine(LogLevel.Error, "Target language mismatch between command line {0} and TMX language {1}. Please edit TmxLangMap.csv to fix. Aborting.", TM.targetLangID, TmxTargetLanguage);
                deleteSNTfiles(sntFilenames);
                return false;
            }

            string[] sntSource = File.ReadAllLines(sntFilenames[0]);
            string[] sntTarget = File.ReadAllLines(sntFilenames[1]);
            if (sntSource.Length != sntTarget.Length){
                Logger.WriteLine(LogLevel.Error, "Unequal number of segments. The TMX must have the same number of segments in the two given languages.");
                deleteSNTfiles(sntFilenames);
                return false;
            }

            Logger.WriteLine(LogLevel.None, "{0} translation units read.", sntSource.Length);

            TmxWriter ErrorTmx = new TmxWriter(Path.GetFileNameWithoutExtension(this.TmxDocument.ValueString) + ".errors." + TmxSourceLanguage + "_" + TmxTargetLanguage + "." + DateTime.Now.ToString("yyyyMMddThhmmssZ") + ".tmx", TmxSourceLanguage, TmxTargetLanguage);

            //Load into TM and perform error check on each line.
            int ratioViolationCount = 0; //counts number of ratio violations
            int sntCountViolationCount = 0; //counts number of unequal sentence count violation.
            for (int sntLineIndex = 0; sntLineIndex < sntSource.Length; sntLineIndex++)
            {
                //show a progress message.
                if ((sntLineIndex % 10) == 0) Logger.WriteLine(LogLevel.Debug, "{0} of {1} sentences aligned and error checked.", sntLineIndex, sntSource.Length);

                //Length discrepancy check
                float ratio = Math.Abs(sntSource[sntLineIndex].Length / sntTarget[sntLineIndex].Length);
                if ((ratio > 3) && ((sntSource.Length > 15) || (sntTarget.Length > 15))) //skip the segment, and add to error.tmx
                {
                    Logger.WriteLine(LogLevel.Debug, "Length ratio exceeded. Segment skipped: {0}", sntSource[sntLineIndex].Substring(0, (60<sntSource[sntLineIndex].Length)?60:sntSource[sntLineIndex].Length));
                    ratioViolationCount++;
                    ErrorTmx.TmxWriteSegment(sntSource[sntLineIndex], sntTarget[sntLineIndex], TmxSourceLanguage, TmxTargetLanguage, TmxWriter.TUError.lengthratio);

                    if ((ratioViolationCount / sntSource.Length) > 0.10)
                    {
                        Logger.WriteLine(LogLevel.Error, "Length ratio exceeded for 10% of segments. Probably not a translation. Aborting.");
                        deleteSNTfiles(sntFilenames);
                        return false;
                    }
                    continue;
                }

                //TODO: special handling of bpt/ept
                sntSource[sntLineIndex] = System.Net.WebUtility.HtmlDecode(sntSource[sntLineIndex]);
                sntTarget[sntLineIndex] = System.Net.WebUtility.HtmlDecode(sntTarget[sntLineIndex]);

                //throw away segments with tags
                if ((sntSource[sntLineIndex].Contains("<") && sntSource[sntLineIndex].Contains(">")) && (sntTarget[sntLineIndex].Contains("<") && sntTarget[sntLineIndex].Contains(">")))
                {
                    Logger.WriteLine(LogLevel.Debug, "Tagged segment. Segment skipped: {0}", sntSource[sntLineIndex].Substring(0, (60 < sntSource[sntLineIndex].Length) ? 60 : sntSource[sntLineIndex].Length));
                    ErrorTmx.TmxWriteSegment(sntSource[sntLineIndex], sntTarget[sntLineIndex], TmxSourceLanguage, TmxTargetLanguage, TmxWriter.TUError.tagging);
                    continue;
                }

                //Encode the remaining <>&
                sntSource[sntLineIndex] = System.Net.WebUtility.HtmlEncode(sntSource[sntLineIndex]);
                sntTarget[sntLineIndex] = System.Net.WebUtility.HtmlEncode(sntTarget[sntLineIndex]);

                int[] sourceSentLengths = TranslationServiceFacade.BreakSentences(sntSource[sntLineIndex], TM.sourceLangID);
                int[] targetSentLengths = TranslationServiceFacade.BreakSentences(sntTarget[sntLineIndex], TM.targetLangID);

                //unequal sentence count violation check
                if (sourceSentLengths.Length != targetSentLengths.Length)
                {
                    sntCountViolationCount++;
                    Logger.WriteLine(LogLevel.Debug, "Unequal number of sentences in segment. Segment skipped: {0}", sntSource[sntLineIndex].Substring(0, (60<sntSource[sntLineIndex].Length)?60:sntSource[sntLineIndex].Length));
                    ErrorTmx.TmxWriteSegment(sntSource[sntLineIndex], sntTarget[sntLineIndex], TmxSourceLanguage, TmxTargetLanguage, TmxWriter.TUError.sentencecountmismatch);

                    if ((sntCountViolationCount / sntSource.Length) > 0.10)
                    {
                        Logger.WriteLine(LogLevel.Error, "Unequal sentence count exceeded for 10% of segments. Probably not a translation. Aborting.");
                        deleteSNTfiles(sntFilenames);
                        return false;
                    }
                    continue;
                }

                //Split multiple sentences
                int startIndexSrc = 0;
                int startIndexTgt = 0;
                for (int j = 0; j < sourceSentLengths.Length; j++ )
                {
                    TranslationUnit TU = new TranslationUnit();
                    TU.strSource = sntSource[sntLineIndex].Substring(startIndexSrc, sourceSentLengths[j]);
                    TU.strTarget = sntTarget[sntLineIndex].Substring(startIndexTgt, targetSentLengths[j]);
                    startIndexSrc = sourceSentLengths[j];
                    startIndexTgt = targetSentLengths[j];
                    TU.rating = int.Parse(ratingvalue);
                    TU.user = uservalue.ToUpperInvariant();
                    TM.Add(TU);
                }

            }
            ErrorTmx.Dispose();

            //Add the whole TM list to CTF, if a CTF write was requested.

            if (boolWrite.ValueString.ToLowerInvariant() == "true")
            {
                int SentenceCount = 0;
                foreach (TranslationUnit TU in TM){
                    TranslationServiceFacade.AddTranslation(TU.strSource, TU.strTarget, TM.sourceLangID, TM.targetLangID, TU.rating, TU.user);
                    if ((SentenceCount % 10) == 0) Logger.WriteLine(LogLevel.Debug, "{0} of {1} sentences written. Continuing...", SentenceCount, sntSource.Length);
                    //Do not change the sleep time. This is slow and needs to be slow - the AddTranslation method is designed for interactive use.
                    Thread.Sleep(500);
                    SentenceCount++;
                }
                Logger.WriteLine(LogLevel.Msg, "{0} sentences written to CTF. Write complete. ", SentenceCount);
            }
            else
            {
                //Just list the entire TM on screen.
                foreach (TranslationUnit TU in TM)
                {
                    Logger.WriteLine(LogLevel.None, "{0} || {1}", TU.strSource, TU.strTarget);
                }
            }

            return true;
        }
예제 #19
0
        /// <summary>
        ///     The execute method.
        /// </summary>
        /// <returns>
        ///     The <see cref="bool" />.
        /// </returns>
        public override bool Execute()
        {
            string SntFileName = Path.GetTempPath() + "_TmxUpload.snt";
            string uservalue   = user.ValueString;

            if (uservalue == string.Empty)
            {
                uservalue = "TmxUpload";
            }
            string ratingvalue = rating.ValueString;

            if (ratingvalue == string.Empty)
            {
                ratingvalue = "6";
            }
            if (!File.Exists(TmxDocument.ValueString))
            {
                Logger.WriteLine(LogLevel.Error, "File {0} does not exist.", TmxDocument.ValueString);
                return(false);
            }

            TmxFile TmxIn = new TmxFile(this.TmxDocument.ValueString);

            string[] sntFilenames = TmxIn.WriteToSNTFiles(SntFileName);
            if (sntFilenames != null)
            {
                if (sntFilenames.Length != 2)
                {
                    Logger.WriteLine(LogLevel.Error, "More than 2 languages in the TMX file. Must have exactly 2.");
                    deleteSNTfiles(sntFilenames);
                    return(false);
                }
            }
            else
            {
                Logger.WriteLine(LogLevel.Error, "Not a TMX file. Aborting.");
                return(false);
            }
            TranslationMemory TM = new TranslationMemory();

            TM.sourceLangID = this.sourceLanguage.ValueString.ToLowerInvariant();
            TM.targetLangID = this.targetLanguage.ValueString.ToLowerInvariant();


            // Read language names from Tmx
            string TmxSourceLanguage = Path.GetFileNameWithoutExtension(sntFilenames[0]);

            TmxSourceLanguage = TmxSourceLanguage.Substring(TmxSourceLanguage.LastIndexOf('_') + 1).ToLowerInvariant();
            string TmxTargetLanguage = Path.GetFileNameWithoutExtension(sntFilenames[1]);

            TmxTargetLanguage = TmxTargetLanguage.Substring(TmxTargetLanguage.LastIndexOf('_') + 1).ToLowerInvariant();

            if (TmxSourceLanguage.Substring(0, 2) != TM.sourceLangID)
            {
                Logger.WriteLine(LogLevel.Error, "Source language mismatch between command line {0} and TMX language {1}. Please edit TmxLangMap.csv to fix. Aborting.", TM.sourceLangID, TmxSourceLanguage);
                deleteSNTfiles(sntFilenames);
                return(false);
            }

            if (TmxTargetLanguage.Substring(0, 2) != TM.targetLangID)
            {
                Logger.WriteLine(LogLevel.Error, "Target language mismatch between command line {0} and TMX language {1}. Please edit TmxLangMap.csv to fix. Aborting.", TM.targetLangID, TmxTargetLanguage);
                deleteSNTfiles(sntFilenames);
                return(false);
            }

            TranslationMemory TMErrors = new TranslationMemory();

            TMErrors.sourceLangID = this.sourceLanguage.ValueString.ToLowerInvariant();
            TMErrors.targetLangID = this.targetLanguage.ValueString.ToLowerInvariant();


            string[] sntSource = File.ReadAllLines(sntFilenames[0]);
            string[] sntTarget = File.ReadAllLines(sntFilenames[1]);
            if (sntSource.Length != sntTarget.Length)
            {
                Logger.WriteLine(LogLevel.Error, "Unequal number of segments. The TMX must have the same number of segments in the two given languages.");
                deleteSNTfiles(sntFilenames);
                return(false);
            }

            TmxWriter ErrorTmx = new TmxWriter(Path.GetFileNameWithoutExtension(this.TmxDocument.ValueString) + ".errors." + TmxSourceLanguage + "_" + TmxTargetLanguage + "." + DateTime.Now.ToString("yyyyMMddThhmmssZ") + ".tmx", TmxSourceLanguage, TmxTargetLanguage, false);

            //Load into TM without error checks. The AddTranslationSegments method performs error checks.
            for (int sntLineIndex = 0; sntLineIndex < sntSource.Length; sntLineIndex++)
            {
                TranslationUnit TU = new TranslationUnit(sntSource[sntLineIndex], sntTarget[sntLineIndex], Convert.ToInt16(ratingvalue), uservalue, "", TUStatus.good, "");
                TM.Add(TU);
            }

            Logger.WriteLine(LogLevel.None, "{0} translation units read.", sntSource.Length);


            bool AddToCTF = false;

            if (boolWrite.ValueString.ToLowerInvariant() == "true")
            {
                AddToCTF = true;
            }
            TMFunctions.AddTranslationSegmentsResponse ATSResponse = TMFunctions.AddTranslationSegments(TM, TMErrors, TM.sourceLangID, TM.targetLangID, Convert.ToInt16(ratingvalue), uservalue, AddToCTF);

            Logger.WriteLine(LogLevel.Msg, "Error segments: {0}", ATSResponse.errorsegments);

            if (AddToCTF)
            {
                Logger.WriteLine(LogLevel.Msg, "{0} sentences written to CTF. Write complete. ", ATSResponse.sentencesadded);
            }
            else
            {
                Logger.WriteLine(LogLevel.None, "Nothing written to CTF.");
            }


            return(true);
        }