コード例 #1
0
        private void UpdateTransUnitComment(TMXTransUnit tu, LocalizingInfo locInfo)
        {
            if (locInfo.DiscoveredDynamically && (tu.GetPropValue(TMXLocalizedStringCache.kDiscoveredDynamically) != "true"))
            {
                tu.AddProp(TMXLocalizedStringCache.kDiscoveredDynamically, "true");
                _updated = true;
            }

            if ((locInfo.UpdateFields & UpdateFields.Comment) != UpdateFields.Comment)
            {
                return;
            }

            if ((tu.Notes.Count > 0) && (tu.Notes[0].Text == locInfo.Comment))
            {
                return;
            }

            tu.Notes.Clear();
            _updated = true;

            if (!string.IsNullOrEmpty(locInfo.Comment))
            {
                tu.AddNote(locInfo.Comment);
            }
        }
コード例 #2
0
        public void GetLocalizedObjectInfoTest()
        {
            Assert.AreEqual(0, m_extCtrls.Count);

            var lbl1 = new Label();

            lbl1.Text = "bananas";

            // Make sure calling GetLocalizedObjectInfo creates a LocalizingInfo object when
            // one doesn't exist for the label.
            var loi = ReflectionHelper.GetResult(m_extender, "GetLocalizedComponentInfo", new object[] { lbl1, true }) as LocalizingInfo;

            Assert.AreEqual(1, m_extCtrls.Count);
            Assert.AreEqual("bananas", loi.Text);

            // Make sure calling GetLocalizedObjectInfo does not create a LocalizingInfo object when
            // one already exists for the label.
            loi = ReflectionHelper.GetResult(m_extender, "GetLocalizedComponentInfo", new object[] { lbl1, true }) as LocalizingInfo;
            Assert.AreEqual(1, m_extCtrls.Count);
            Assert.AreEqual("bananas", loi.Text);

            // Create a new LocalizingInfo object for a different label, then poke it into the
            // extender's internal collection and make sure calling GetLocalizedObjectInfo returns
            // that LocalizingInfo for the object.
            var lbl2 = new Label();

            lbl2.Text        = "apples";
            loi              = new LocalizingInfo(lbl2, true);
            m_extCtrls[lbl2] = loi;
            Assert.AreEqual(2, m_extCtrls.Count);

            loi = ReflectionHelper.GetResult(m_extender, "GetLocalizedComponentInfo", new object[] { lbl2, true }) as LocalizingInfo;
            Assert.AreEqual(2, m_extCtrls.Count);
            Assert.AreEqual("apples", loi.Text);
        }
コード例 #3
0
        public void MakeIdTest_ForDataGridViewColumn()
        {
            var grid = new DataGridView {
                Name = "hippo"
            };

            var col = new DataGridViewTextBoxColumn {
                Name = "cheetah"
            };

            grid.Columns.Add(col);

            var loi = new LocalizingInfo(col, true);

            Assert.AreEqual("hippo.Colcheetah", loi.Id);

            var frm = new Form {
                Name = "jackal"
            };

            frm.Controls.Add(grid);

            loi = new LocalizingInfo(col, true);
            Assert.AreEqual("jackal.hippoColcheetah", loi.Id);
        }
コード例 #4
0
        /// ------------------------------------------------------------------------------------
        private LocalizingInfo GetInfoForCallToGetStringMethod(Module module,
                                                               int instrIndex, int paramsInMethodCall)
        {
            var parameters = GetParameters(module, instrIndex, paramsInMethodCall);

            if (parameters[0] == null || parameters[1] == null)
            {
                return(null);
            }

            var locInfo = new LocalizingInfo(parameters[0]);

            locInfo.Text = parameters[1];

            if (paramsInMethodCall >= 3 && parameters[2] != null)
            {
                locInfo.Comment = parameters[2];
            }

            if (paramsInMethodCall == 6)
            {
                if (parameters[3] != null)
                {
                    locInfo.ToolTipText = parameters[3];
                }
                if (parameters[4] != null)
                {
                    locInfo.ShortcutKeys = parameters[4];
                }
            }

            return(locInfo);
        }
コード例 #5
0
        public void MakeIdTest_ForControl()
        {
            var frm = new Form {
                Name = "racoon"
            };

            var btn = new Button {
                Name = "fox"
            };

            frm.Controls.Add(btn);

            var loi = new LocalizingInfo(btn, true);

            Assert.AreEqual("racoon.fox", loi.Id);

            var lbl = new Label {
                Name = "opossum"
            };
            var pnl1 = new Panel();
            var pnl2 = new Panel();

            pnl1.Controls.Add(pnl2);
            pnl2.Controls.Add(lbl);
            frm.Controls.Add(pnl1);
            loi = new LocalizingInfo(lbl, true);
            Assert.AreEqual("racoon.opossum", loi.Id);
        }
コード例 #6
0
ファイル: LocalizeItemDlg.cs プロジェクト: gmartin7/l10nsharp
        /// ------------------------------------------------------------------------------------
        private void HandleGridCellValuePushed(object sender, DataGridViewCellValueEventArgs e)
        {
            if (_viewModel.AllLeafNodesShowingInGrid == null || e.RowIndex >= _viewModel.AllLeafNodesShowingInGrid.Count)
            {
                return;
            }

            var locInfo = new LocalizingInfo(_viewModel.CurrentNode.Id);

            locInfo.UpdateFields = UpdateFields.None;
            switch (e.ColumnIndex)
            {
            case 2:
                locInfo.Text         = (e.Value as string) ?? string.Empty;
                locInfo.UpdateFields = UpdateFields.Text;
                break;

            case 4:
                locInfo.ToolTipText  = (e.Value as string) ?? string.Empty;
                locInfo.UpdateFields = UpdateFields.ToolTip;
                break;

            case 5:
                locInfo.Comment      = (e.Value as string) ?? string.Empty;
                locInfo.UpdateFields = UpdateFields.Comment;
                break;

            default: return;
            }

            _viewModel.SaveChangesInMemory(locInfo);
            UpdateViewAfterSavingChange();
        }
コード例 #7
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Updates the localized info. in the cache with the info. from the specified
 /// LocalizedObjectInfo.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public void UpdateLocalizedInfo(LocalizingInfo locInfo)
 {
     if (_tuUpdater.Update(locInfo) && !IsDirty)
     {
         IsDirty = true;
     }
 }
コード例 #8
0
        private void UpdateTransUnitComment(XLiffDocument xliffTarget, XLiffTransUnit tu,
                                            LocalizingInfo locInfo)
        {
            if (tu == null)
            {
                return;
            }

            if (locInfo.DiscoveredDynamically && !tu.Dynamic)
            {
                tu.Dynamic = true;
                _updated   = true;
            }

            if ((locInfo.UpdateFields & UpdateFields.Comment) != UpdateFields.Comment)
            {
                return;
            }
            if (tu.Notes.Count == 0 && string.IsNullOrEmpty(locInfo.Comment))
            {
                return;                 // empty comment and already no comment in XLiffTransUnit
            }
            if (tu.NotesContain(locInfo.Comment))
            {
                return;                 // exactly the same comment already exists in XLiffTransUnit
            }
            _updated = true;
            tu.Notes.Clear();
            tu.AddNote("ID: " + tu.Id);
            if (!string.IsNullOrEmpty(locInfo.Comment))
            {
                tu.AddNote(locInfo.Comment);
            }
        }
コード例 #9
0
        /// ------------------------------------------------------------------------------------
        private void HandleGridColumnAdded(object sender, DataGridViewColumnEventArgs e)
        {
            var locInfo = new LocalizingInfo(e.Column, true);

            _manager.RegisterComponentForLocalizing(locInfo,
                                                    (lm, info) => lm.ApplyLocalization(info.Component));
        }
コード例 #10
0
        /// <summary>
        /// Allows the BetterToolTip to give L10NSharp the information it needs to put strings
        /// into the localization UI to be localized.
        /// </summary>
        /// <returns>A list of LocalizingInfo objects</returns>
        public IEnumerable <LocalizingInfo> GetAllLocalizingInfoObjects(L10NSharpExtender extender)
        {
            var result = new List <LocalizingInfo>();

            foreach (var ctrl in m_allControlsHavingToolTips)
            {
                var idPrefix  = extender.GetLocalizingId(ctrl);
                var normalTip = GetToolTip(ctrl);
                if (!string.IsNullOrEmpty(normalTip))
                {
                    var liNormal = new LocalizingInfo(ctrl, idPrefix + NORMAL_TIP)
                    {
                        Text = normalTip, Category = LocalizationCategory.LocalizableComponent
                    };
                    result.Add(liNormal);
                }
                var disabledTip = GetToolTipWhenDisabled(ctrl);
                if (!string.IsNullOrEmpty(disabledTip))
                {
                    var liDisabled = new LocalizingInfo(ctrl, idPrefix + DISABLED_TIP)
                    {
                        Text = disabledTip, Category = LocalizationCategory.LocalizableComponent
                    };
                    result.Add(liDisabled);
                }
            }
            return(result);
        }
コード例 #11
0
        void UpdateValueAndComment(XLiffDocument xliffTarget, XLiffTransUnit tuSource,
                                   string newText, LocalizingInfo locInfo, string tuId)
        {
            var tuTarget = UpdateValue(xliffTarget, tuSource, newText, locInfo, tuId);

            UpdateTransUnitComment(xliffTarget, tuSource, locInfo);
            UpdateTransUnitComment(xliffTarget, tuTarget, locInfo);
        }
コード例 #12
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Saves localization changes.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void SaveChangesInMemory(LocalizingInfo locInfo)
        {
            if (locInfo?.Id == null || locInfo.UpdateFields == UpdateFields.None)
            {
                return;
            }

            SaveChangesInMemory(CurrentNode, locInfo);
        }
コード例 #13
0
        public void MakeIdTest_ForForm()
        {
            Form frm = new Form {
                Name = "hamster"
            };
            var loi = new LocalizingInfo(frm, true);

            Assert.AreEqual("hamster.WindowTitle", loi.Id);
        }
コード例 #14
0
ファイル: L10NExtender.cs プロジェクト: vkarthim/l10nsharp
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the localized object info. for the specified component.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private LocalizingInfo GetLocalizedComponentInfo(IComponent component, bool initTextFromCompIfNewlyCreated)
        {
            LocalizingInfo loi;

            if (m_extendedCtrls.TryGetValue(component, out loi))             // && !string.IsNullOrEmpty(loi.Id) && loi.Priority != LocalizationPriority.NotLocalizable)
            {
                return(loi);
            }

            loi = new LocalizingInfo((IComponent)component, initTextFromCompIfNewlyCreated);
            m_extendedCtrls[component] = loi;
            return(loi);
        }
コード例 #15
0
        /// ------------------------------------------------------------------------------------
        private LocalizingInfo GetLocInfoForField(string className, string fieldName)
        {
            var key = GetLocalizingKey(className, fieldName);

            if (_extenderInfo.TryGetValue(key, out var locInfo))
            {
                return(locInfo);
            }

            locInfo = new LocalizingInfo(null)
            {
                Priority = LocalizationPriority.Medium
            };
            _extenderInfo[key] = locInfo;
            return(locInfo);
        }
コード例 #16
0
        /// <summary>
        /// This is special because, as an extension method the 1st parameter in "hello".Localize("myapp.greeting") will be the string ("hello") itself,
        /// which is backwards from the convention used in the GetString(id, theString, etc.)
        /// </summary>
        private LocalizingInfo GetInfoForCallToLocalizeExtension(Module module, int instrIndex, int paramsInMethodCall)
        {
            var parameters = GetParameters(module, instrIndex, paramsInMethodCall);

            //begin part that differes from GetInfoForCallToLocalizationMethod (for now)

            if (parameters[0] == null)
            {
                return(null);
            }

            string id;

            if (String.IsNullOrEmpty(parameters[1]))
            {
                id = parameters[0];
            }
            else
            {
                id = parameters[1];
            }

            var locInfo = new LocalizingInfo(id);

            locInfo.Text = parameters[0];

            //end part that differes from GetInfoForCallToLocalizationMethod

            if (paramsInMethodCall >= 3 && parameters[2] != null)
            {
                locInfo.Comment = parameters[2];
            }

            if (paramsInMethodCall == 6)
            {
                if (parameters[3] != null)
                {
                    locInfo.ToolTipText = parameters[3];
                }
                if (parameters[4] != null)
                {
                    locInfo.ShortcutKeys = parameters[4];
                }
            }

            return(locInfo);
        }
コード例 #17
0
        /// ------------------------------------------------------------------------------------
        public void SaveChangesInMemory(LocTreeNode node, LocalizingInfo locInfo)
        {
            if (locInfo == null || locInfo.Id == null ||
                locInfo.UpdateFields == UpdateFields.None || _tgtLangId == _srcLangId)
            {
                return;
            }

            if (locInfo.Text == (node.GetText(_tgtLangId) ?? string.Empty) &&
                locInfo.ToolTipText == (node.GetToolTip(_tgtLangId) ?? string.Empty) &&
                locInfo.ShortcutKeys == (node.GetShortcutKeys(_tgtLangId) ?? string.Empty))
            {
                return;
            }

            locInfo.LangId = _tgtLangId;
            _modifiedLanguages.Add(_tgtLangId);

            if (!node.SavedTranslationInfo.ContainsKey(_tgtLangId))
            {
                node.SavedTranslationInfo[_tgtLangId] = locInfo;
            }
            else
            {
                if ((locInfo.UpdateFields & UpdateFields.Text) == UpdateFields.Text)
                {
                    node.SavedTranslationInfo[_tgtLangId].Text = (locInfo.Text == string.Empty ? null : locInfo.Text);
                }

                if ((locInfo.UpdateFields & UpdateFields.ToolTip) == UpdateFields.ToolTip)
                {
                    node.SavedTranslationInfo[_tgtLangId].ToolTipText = (locInfo.ToolTipText == string.Empty ? null : locInfo.ToolTipText);
                }

                if ((locInfo.UpdateFields & UpdateFields.ShortcutKeys) == UpdateFields.ShortcutKeys)
                {
                    node.SavedTranslationInfo[_tgtLangId].ShortcutKeys = (locInfo.ShortcutKeys == string.Empty ? null : locInfo.ShortcutKeys);
                }

                if ((locInfo.UpdateFields & UpdateFields.Comment) == UpdateFields.Comment)
                {
                    node.SavedComment = (locInfo.Comment == string.Empty ? null : locInfo.Comment);
                }

                node.SavedTranslationInfo[_tgtLangId].UpdateFields |= locInfo.UpdateFields;
            }
        }
コード例 #18
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Updates the value for the specified translation unit with the specified new value.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private TMXTransUnit UpdateValue(TMXTransUnit tu, string newValue, LocalizingInfo locInfo, string tuId)
        {
            newValue = newValue ?? string.Empty;

            // Get rid of the variant we are about to set if it is present.
            // If no variants remain get rid of the whole thing.
            // Later we will create whatever we need.
            if (tu != null)
            {
                var tuv = tu.GetVariantForLang(locInfo.LangId);
                if (tuv != null)
                {
                    // don't need to update if the value hasn't changed
                    if (tuv.Value == newValue)
                    {
                        return(tu);
                    }

                    _updated = true;
                    tu.RemoveVariant(tuv);
                    if (tu.Variants.Count == 0)
                    {
                        _tmxDoc.RemoveTransUnit(tu);
                        tu = null;                         // so we will make a new one if needed.
                    }
                }
            }

            if (newValue == string.Empty)
            {
                return(tu);
            }

            // Create a new entry if needed.
            if (tu == null)
            {
                tu    = new TMXTransUnit();
                tu.Id = tuId;
                _tmxDoc.AddTransUnit(tu);
            }

            tu.AddOrReplaceVariant(locInfo.LangId, newValue);
            _updated = true;
            return(tu);
        }
コード例 #19
0
ファイル: LocalizeItemDlg.cs プロジェクト: gmartin7/l10nsharp
        /// ------------------------------------------------------------------------------------
        private void SaveChangesFromSingleItemView()
        {
            var node = _viewModel.CurrentNode;

            if (_grid.Visible || node == null)
            {
                return;
            }

            var locInfo = new LocalizingInfo(node.Id);

            locInfo.Text         = _textBoxTgtTranslation.Text.Trim();
            locInfo.ToolTipText  = _textBoxTgtToolTip.Text.Trim();
            locInfo.ShortcutKeys = _shortcutKeysDropDown.Text.Trim();
            locInfo.Comment      = _textBoxComment.Text.Trim();

            _viewModel.SaveChangesInMemory(locInfo);
            UpdateViewAfterSavingChange();
        }
コード例 #20
0
        /// ------------------------------------------------------------------------------------
        private void HandleTanslateItems(object sender, DoWorkEventArgs e)
        {
            var worker           = sender as BackgroundWorker;
            var nodesToTranslate = e.Argument as IDictionary <int, LocTreeNode <T> >;
            int i = 0;

            foreach (var kvp in nodesToTranslate)
            {
                var node    = kvp.Value;
                var locInfo = new LocalizingInfo(node.Id);
                locInfo.UpdateFields = UpdateFields.None;
                locInfo.LangId       = TgtLangId;

                var text = node.GetText(SrcLangId);
                if (!string.IsNullOrEmpty(text))
                {
                    text = (BingTranslator.TranslateText(text) ?? string.Empty).Trim();
                    if (text != string.Empty)
                    {
                        locInfo.Text          = text;
                        locInfo.UpdateFields |= UpdateFields.Text;
                    }
                }

                text = node.GetToolTip(SrcLangId);
                if (!string.IsNullOrEmpty(text))
                {
                    text = (BingTranslator.TranslateText(text) ?? string.Empty).Trim();
                    if (text != string.Empty)
                    {
                        locInfo.ToolTipText   = text;
                        locInfo.UpdateFields |= UpdateFields.ToolTip;
                    }
                }

                if (locInfo.UpdateFields != UpdateFields.None)
                {
                    SaveChangesInMemory(node, locInfo);
                    worker.ReportProgress(++i, kvp.Key);
                }
            }
        }
コード例 #21
0
        public void MakeIdTest_ForColumnHeader()
        {
            var lv = new ListView();

            lv.Name = "fish";

            var hdr = new ColumnHeader();

            hdr.Name = "monkey";
            lv.Columns.Add(hdr);

            var loi = new LocalizingInfo(hdr, true);

            Assert.AreEqual("fish.Colmonkey", loi.Id);

            Form frm = new Form();

            frm.Name = "wolf";
            frm.Controls.Add(lv);
            loi = new LocalizingInfo(hdr, true);
            Assert.AreEqual("wolf.fishColmonkey", loi.Id);
        }
コード例 #22
0
        public void PrepareDataGridViewColumnsTests()
        {
            Form frm = new Form();

            frm.Name = "TestDlg";

            DataGridView grid = new DataGridView();

            grid.Name = "colors";
            grid.Columns.Add("red", "redtext");
            grid.Columns.Add("blue", "bluetext");
            grid.Columns.Add("orange", "orangetext");
            frm.Controls.Add(grid);

            ReflectionHelper.CallMethod(m_extender, "GetLocalizedObjectInfo", new object[] { grid, true });
            Assert.AreEqual(1, m_extCtrls.Count);
            Assert.IsTrue(m_extCtrls.ContainsKey(grid));

            ReflectionHelper.CallMethod(m_extender, "FinalizationForDataGridViewColumns", null);

            Assert.AreEqual(3, m_extCtrls.Count);
            Assert.IsTrue(m_extCtrls.ContainsKey(grid.Columns["red"]));
            Assert.IsTrue(m_extCtrls.ContainsKey(grid.Columns["blue"]));
            Assert.IsTrue(m_extCtrls.ContainsKey(grid.Columns["orange"]));

            LocalizingInfo loi = m_extCtrls[grid.Columns["red"]];

            Assert.AreEqual("TestDlg.colorsColred", loi.Id);
            Assert.AreEqual("redtext", loi.Text);

            loi = m_extCtrls[grid.Columns["blue"]];
            Assert.AreEqual("TestDlg.colorsColblue", loi.Id);
            Assert.AreEqual("bluetext", loi.Text);

            loi = m_extCtrls[grid.Columns["orange"]];
            Assert.AreEqual("TestDlg.colorsColorange", loi.Id);
            Assert.AreEqual("orangetext", loi.Text);
        }
コード例 #23
0
        public void PrepareListViewColumnHeadersTests()
        {
            Form frm = new Form();

            frm.Name = "TestDlg";

            var lv = new ListView();

            lv.Name = "meat";
            lv.Columns.Add("ham", "hamtext");
            lv.Columns.Add("steak", "steaktext");
            lv.Columns.Add("venison", "venisontext");
            frm.Controls.Add(lv);

            ReflectionHelper.CallMethod(m_extender, "GetLocalizedObjectInfo", new object[] { lv, true });
            Assert.AreEqual(1, m_extCtrls.Count);
            Assert.IsTrue(m_extCtrls.ContainsKey(lv));

            ReflectionHelper.CallMethod(m_extender, "FinalizationForListViewColumnHeaders", null);

            Assert.AreEqual(3, m_extCtrls.Count);
            Assert.IsTrue(m_extCtrls.ContainsKey(lv.Columns["ham"]));
            Assert.IsTrue(m_extCtrls.ContainsKey(lv.Columns["steak"]));
            Assert.IsTrue(m_extCtrls.ContainsKey(lv.Columns["venison"]));

            LocalizingInfo loi = m_extCtrls[lv.Columns["ham"]];

            Assert.AreEqual("TestDlg.meatColham", loi.Id);
            Assert.AreEqual("hamtext", loi.Text);

            loi = m_extCtrls[lv.Columns["steak"]];
            Assert.AreEqual("TestDlg.meatColsteak", loi.Id);
            Assert.AreEqual("steaktext", loi.Text);

            loi = m_extCtrls[lv.Columns["venison"]];
            Assert.AreEqual("TestDlg.meatColvenison", loi.Id);
            Assert.AreEqual("venisontext", loi.Text);
        }
コード例 #24
0
        /// ------------------------------------------------------------------------------------
        public void FindExtenderCalls(MethodBase caller)
        {
            var module = caller.Module;

            for (int i = 1; i < _instructions.Count; i++)
            {
                string text = null;

                if (_instructions[i].opCode == OpCodes.Ldstr)
                {
                    text = module.ResolveString((int)_instructions[i].operand);
                    if (text.StartsWith(LocalizationManager.kL10NPrefix))
                    {
                        var locInfo = GetLocInfoForField(caller.ReflectedType.Name, text);
                        locInfo.Id   = LocalizingInfo.GetIdFromText(text);
                        locInfo.Text = LocalizationManager.StripOffLocalizationInfoFromText(text);
                        continue;
                    }
                }

                if (_instructions[i].opCode != OpCodes.Callvirt &&
                    _instructions[i].opCode != OpCodes.Calli &&
                    _instructions[i].opCode != OpCodes.Call)
                {
                    continue;
                }

                if (_instructions[i - 1].opCode == OpCodes.Ldnull)
                {
                    continue;
                }

                Type[] genericMethodArguments = null;
                var    genericTypeArguments   = caller.DeclaringType.GetGenericArguments();

                if ((!caller.IsConstructor) && (!caller.Name.Equals(".cctor")))
                {
                    genericMethodArguments = caller.GetGenericArguments();
                }

                string fldName = null;

                MethodBase mi = null;
                try
                {
                    mi = module.ResolveMethod((int)_instructions[i].operand,
                                              genericTypeArguments, genericMethodArguments);
                }
                catch (Exception)
                {
                    //We started getting this with Palaso.ClearShare.LicenseInfo.Token, which is abstract. Could not determine just what causes it, could not reproduce in a test.
                    //So it's not worth stopping the train over....
                    continue;
                }

                if (mi.Name.Equals("SetLocalizationPriority", StringComparison.Ordinal))
                {
                    var priority = (LocalizationPriority)(_instructions[i - 1].opCode.Value - 22);
                    fldName = GetFieldName(module, _instructions[i - 2]);
                    GetLocInfoForField(caller.ReflectedType.Name, fldName).Priority = priority;
                    continue;
                }

                text = (i > 1 && _instructions[i - 1].opCode == OpCodes.Ldstr ?
                        module.ResolveString((int)_instructions[i - 1].operand) : null);

                if (text == null)
                {
                    continue;
                }

                if (mi.Name.Equals("SetLocalizingId", StringComparison.Ordinal))
                {
                    fldName = GetFieldName(module, _instructions[i - 2]);
                    GetLocInfoForField(caller.ReflectedType.Name, fldName).Id = text;
                }
                else if (mi.Name.Equals("SetLocalizationComment", StringComparison.Ordinal))
                {
                    fldName = GetFieldName(module, _instructions[i - 2]);
                    GetLocInfoForField(caller.ReflectedType.Name, fldName).Comment = text;
                }
                else if (mi.Name.Equals("SetLocalizableToolTip", StringComparison.Ordinal))
                {
                    fldName = GetFieldName(module, _instructions[i - 2]);
                    GetLocInfoForField(caller.ReflectedType.Name, fldName).ToolTipText = text;
                }
                else if (mi.Name.Equals("set_Text", StringComparison.Ordinal))
                {
                    fldName = GetFieldName(module, _instructions[i - 2]);
                    GetLocInfoForField(caller.ReflectedType.Name, fldName).Text = text;
                }
            }
        }
コード例 #25
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Updates the localized info. in the cache with the info. from the specified
        /// LocalizedObjectInfo.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        internal bool Update(LocalizingInfo locInfo)
        {
            _updated = false;

            // Can't do anything without a language id.
            if (string.IsNullOrEmpty(locInfo.LangId))
            {
                return(_updated);
            }

            var tuText = _tmxDoc.GetTransUnitForId(locInfo.Id);

            var tuToolTip      = _tmxDoc.GetTransUnitForId(locInfo.Id + kToolTipSuffix);
            var tuShortcutKeys = _tmxDoc.GetTransUnitForId(locInfo.Id + kShortcutSuffix);

            if (locInfo.Priority == LocalizationPriority.NotLocalizable)
            {
                _updated = (tuText != null || tuToolTip != null || tuShortcutKeys != null);
                _tmxDoc.RemoveTransUnit(tuText);
                _tmxDoc.RemoveTransUnit(tuToolTip);
                _tmxDoc.RemoveTransUnit(tuShortcutKeys);
                return(_updated);
            }

            // Save the shortcut keys
            if ((locInfo.UpdateFields & UpdateFields.ShortcutKeys) == UpdateFields.ShortcutKeys)
            {
                tuShortcutKeys = UpdateValue(tuShortcutKeys, locInfo.ShortcutKeys, locInfo, locInfo.Id + kShortcutSuffix);
            }

            // Save the tooltips
            if ((locInfo.UpdateFields & UpdateFields.ToolTip) == UpdateFields.ToolTip)
            {
                tuToolTip = UpdateValue(tuToolTip, locInfo.ToolTipText, locInfo, locInfo.Id + kToolTipSuffix);
            }

            // Save the text
            if ((locInfo.UpdateFields & UpdateFields.Text) == UpdateFields.Text)
            {
                var text = locInfo.Text ?? string.Empty;
                // first because Environment.Newline might be one part of it. We include this explicitly
                // in case some Windows data somehow finds its way to Linux.
                text   = text.Replace("\r\n", _literalNewline);
                text   = text.Replace(Environment.NewLine, _literalNewline);
                text   = text.Replace(_literalNewline, "@#$");
                text   = text.Replace(kOSRealNewline, _literalNewline);
                text   = text.Replace("@#$", _literalNewline);
                tuText = UpdateValue(tuText, text, locInfo, locInfo.Id);
            }

            if (tuText != null)
            {
                UpdateTransUnitComment(tuText, locInfo);
            }

            if (tuToolTip != null)
            {
                UpdateTransUnitComment(tuToolTip, locInfo);
            }

            if (tuShortcutKeys != null)
            {
                UpdateTransUnitComment(tuShortcutKeys, locInfo);
            }

            return(_updated);
        }
コード例 #26
0
 /// <summary>
 /// Allows the BetterToolTip to give L10NSharp the information it needs to put strings
 /// into the localization UI to be localized.
 /// </summary>
 /// <returns>A list of LocalizingInfo objects</returns>
 public IEnumerable<LocalizingInfo> GetAllLocalizingInfoObjects(L10NSharpExtender extender)
 {
     var result = new List<LocalizingInfo>();
     foreach (var ctrl in _allControlsHavingToolTips)
     {
         var idPrefix = extender.GetLocalizingId(ctrl);
         var normalTip = GetToolTip(ctrl);
         if (!string.IsNullOrEmpty(normalTip))
         {
             var liNormal = new LocalizingInfo(ctrl, idPrefix + NORMAL_TIP)
                 { Text = normalTip, Category = LocalizationCategory.LocalizableComponent };
             result.Add(liNormal);
         }
         var disabledTip = GetToolTipWhenDisabled(ctrl);
         if (!string.IsNullOrEmpty(disabledTip))
         {
             var liDisabled = new LocalizingInfo(ctrl, idPrefix + DISABLED_TIP)
                 { Text = disabledTip, Category = LocalizationCategory.LocalizableComponent };
             result.Add(liDisabled);
         }
     }
     return result;
 }
コード例 #27
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Updates the value for the specified translation unit with the specified new value.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private XLiffTransUnit UpdateValue(XLiffDocument xliffTarget, XLiffTransUnit tuSource,
                                           string newValue, LocalizingInfo locInfo,
                                           string tuId)
        {
            // One would think there would be a source XLiffTransUnit, but that isn't necessarily true
            // with users editing interactively and adding tooltips or shortcuts.
            Debug.Assert(tuSource == null || tuId == tuSource.Id);
            Debug.Assert(tuId.StartsWith(locInfo.Id));
            var tuTarget = xliffTarget.GetTransUnitForId(tuId);

            // If the XLiffTransUnit exists in the target language, check whether we're removing the translation
            // instead of adding or changing it.
            if (tuTarget != null)
            {
                var tuvTarg = tuTarget.GetVariantForLang(locInfo.LangId);
                if (tuvTarg != null)
                {
                    // don't need to update if the value hasn't changed
                    if (tuvTarg.Value == newValue)
                    {
                        return(tuTarget);
                    }

                    if (string.IsNullOrEmpty(newValue))
                    {
                        _updated = true;
                        tuTarget.RemoveVariant(tuvTarg);
                        if ((tuTarget.Source == null ||
                             string.IsNullOrEmpty(tuTarget.Source.Value)) &&
                            (tuTarget.Target == null ||
                             string.IsNullOrEmpty(tuTarget.Target.Value)))
                        {
                            xliffTarget.RemoveTransUnit(tuTarget);
                            tuTarget = null;
                        }
                    }
                }
            }

            // If we're removing an existing translation, we can quit now.
            if (string.IsNullOrEmpty(newValue))
            {
                xliffTarget.File.Body.TranslationsById.TryRemove(tuId, out _);
                return(tuTarget);
            }

            // If the XLiffTransUnit does not exist in the target language yet, create it and fill in the
            // source language value (if any).
            if (tuTarget == null)
            {
                tuTarget         = new XLiffTransUnit();
                tuTarget.Id      = tuId;
                tuTarget.Dynamic = locInfo.DiscoveredDynamically;
                xliffTarget.AddTransUnit(tuTarget);
                if (tuSource != null && locInfo.LangId != _defaultLang)
                {
                    var tuvSrc = tuSource.GetVariantForLang(_defaultLang);
                    if (tuvSrc != null && !string.IsNullOrEmpty(tuvSrc.Value))
                    {
                        tuTarget.AddOrReplaceVariant(_defaultLang, tuvSrc.Value);
                    }
                }

                tuTarget.AddNote("ID: " + tuId);
            }

            tuTarget.AddOrReplaceVariant(locInfo.LangId, newValue);
            xliffTarget.File.Body.TranslationsById[tuId] = newValue;
            _updated = true;
            return(tuTarget);
        }
コード例 #28
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Updates the localized info. in the cache with the info. from the specified
        /// LocalizedObjectInfo.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        internal bool Update(LocalizingInfo locInfo)
        {
            _updated = false;

            // Can't do anything without a language id.
            if (string.IsNullOrEmpty(locInfo.LangId))
            {
                return(_updated);
            }

            var xliffSource = _stringCache.GetDocument(_defaultLang);

            Debug.Assert(xliffSource != null);

            XLiffDocument xliffTarget;

            if (!_stringCache.TryGetDocument(locInfo.LangId, out xliffTarget))
            {
                xliffTarget = new XLiffDocument();
                xliffTarget.File.AmpersandReplacement     = xliffSource.File.AmpersandReplacement;
                xliffTarget.File.DataType                 = xliffSource.File.DataType;
                xliffTarget.File.HardLineBreakReplacement =
                    xliffSource.File.HardLineBreakReplacement;
                xliffTarget.File.Original       = xliffSource.File.Original;
                xliffTarget.File.ProductVersion = xliffSource.File.ProductVersion;
                xliffTarget.File.SourceLang     = xliffSource.File.SourceLang;
                xliffTarget.File.TargetLang     = locInfo.LangId;
                xliffTarget.IsDirty             = true;
                _updated = true;
                _stringCache.AddDocument(locInfo.LangId, xliffTarget);
            }

            var tuSourceText         = xliffSource.GetTransUnitForId(locInfo.Id);
            var tuSourceToolTip      = xliffSource.GetTransUnitForId(locInfo.Id + kToolTipSuffix);
            var tuSourceShortcutKeys =
                xliffSource.GetTransUnitForId(locInfo.Id + kShortcutSuffix);

            if (locInfo.Priority == LocalizationPriority.NotLocalizable)
            {
                _updated = (tuSourceText != null || tuSourceToolTip != null ||
                            tuSourceShortcutKeys != null);
                xliffSource.RemoveTransUnit(tuSourceText);
                xliffSource.RemoveTransUnit(tuSourceToolTip);
                xliffSource.RemoveTransUnit(tuSourceShortcutKeys);
                if (_defaultLang != locInfo.LangId)
                {
                    xliffTarget.RemoveTransUnit(tuSourceText);
                    xliffTarget.RemoveTransUnit(tuSourceToolTip);
                    xliffTarget.RemoveTransUnit(tuSourceShortcutKeys);
                }

                return(_updated);
            }

            // Save the shortcut keys
            var shortcutId = locInfo.Id + kShortcutSuffix;

            if ((locInfo.UpdateFields & UpdateFields.ShortcutKeys) == UpdateFields.ShortcutKeys)
            {
                UpdateValueAndComment(xliffTarget, tuSourceShortcutKeys, locInfo.ShortcutKeys,
                                      locInfo, shortcutId);
            }

            // Save the tooltips
            var tooltipId = locInfo.Id + kToolTipSuffix;

            if ((locInfo.UpdateFields & UpdateFields.ToolTip) == UpdateFields.ToolTip)
            {
                UpdateValueAndComment(xliffTarget, tuSourceToolTip, locInfo.ToolTipText, locInfo,
                                      tooltipId);
            }

            // Save the text
            if ((locInfo.UpdateFields & UpdateFields.Text) == UpdateFields.Text)
            {
                var text = locInfo.Text ?? string.Empty;
                // first because Environment.Newline might be one part of it. We include this explicitly
                // in case some Windows data somehow finds its way to Linux.
                text = text.Replace("\r\n", _literalNewline);
                text = text.Replace(Environment.NewLine, _literalNewline);
                text = text.Replace(_literalNewline, "@#$");
                text = text.Replace(kOSRealNewline, _literalNewline);
                text = text.Replace("@#$", _literalNewline);
                UpdateValueAndComment(xliffTarget, tuSourceText, text, locInfo, locInfo.Id);
            }

            if (_updated)
            {
                xliffTarget.IsDirty = true;
            }
            return(_updated);
        }