Template items are only used to keep track of the strings needing translation in any given project and for then updating the translations and translationItems with this data. You should never need to work with TemplateItem unless you work with finding nuggets and updating the template file.
Beispiel #1
0
		private void AddNewTemplateItem(
            string filePath, 
            int lineNumber, 
            Nugget nugget, 
            ConcurrentDictionary<string, TemplateItem> templateItems)
		{
			string reference = filePath + ":" + lineNumber.ToString();
            string msgid = nugget.MsgId.Replace("\r\n", "\n").Replace("\r", "\\n");
                // NB: In memory msgids are normalized so that LFs are converted to "\n" char sequence.
            string key = TemplateItem.KeyFromMsgidAndComment(msgid, nugget.Comment, _settings.MessageContextEnabledFromComment);
			List<string> tmpList;
           //
            templateItems.AddOrUpdate(
                key,
                // Add routine.
                k => {
			        TemplateItem item = new TemplateItem();
                    item.MsgKey = key;
			        item.MsgId = msgid;

			        tmpList = new List<string>();
			        tmpList.Add(reference);
			        item.References = tmpList;

			        if (nugget.Comment.IsSet()) {
                        tmpList = new List<string>();
                        tmpList.Add(nugget.Comment);
                        item.Comments = tmpList;
                    }

			        return item;
                },
                // Update routine.
                (k, v) => {

					tmpList = v.References.ToList();
					tmpList.Add(reference);
					v.References = tmpList;

			        if (nugget.Comment.IsSet()) {
					    tmpList = v.Comments != null ? v.Comments.ToList() : new List<string>();
					    tmpList.Add(nugget.Comment);
					    v.Comments = tmpList;
                    }

                    return v;
                });
		}
Beispiel #2
0
        private void AddNewTemplateItem(
            string fileName,
            ReferenceContext referenceContext,
            Nugget nugget, 
            ConcurrentDictionary<string, TemplateItem> templateItems)
        {
            string msgid = nugget.MsgId.Replace("\r\n", "\n").Replace("\r", "\\n");
                // NB: In memory msgids are normalized so that LFs are converted to "\n" char sequence.
            string key = TemplateItem.KeyFromMsgidAndComment(msgid, nugget.Comment, _settings.MessageContextEnabledFromComment);
            List<string> tmpList;
               //
            templateItems.AddOrUpdate(
                key,
                // Add routine.
                k => {
                    TemplateItem item = new TemplateItem();
                    item.MsgKey = key;
                    item.MsgId = msgid;
                    item.FileName = fileName;

                    item.References = new List<ReferenceContext> {referenceContext};

                    if (nugget.Comment.IsSet()) {
                        tmpList = new List<string>();
                        tmpList.Add(nugget.Comment);
                        item.Comments = tmpList;
                    }

                    return item;
                },
                // Update routine.
                (k, v) =>
                {
                    if (!_settings.DisableReferences)
                    {
                        var newReferences = new List<ReferenceContext>(v.References.ToList());
                        newReferences.Add(referenceContext);
                        v.References = newReferences;
                    }

                    if (nugget.Comment.IsSet()) {
                        tmpList = v.Comments != null ? v.Comments.ToList() : new List<string>();
                        if (!_settings.DisableReferences || !tmpList.Contains(nugget.Comment))
                            tmpList.Add(nugget.Comment);
                        v.Comments = tmpList;
                    }

                    return v;
                });
        }