예제 #1
0
        private void BgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            uint        pointerAddress = StringPointersBegin;
            StringEntry entry;

            /* For some reason, we have to reconnect and reattach here */
            PS3.ConnectTarget();
            PS3.AttachProcess();

            for (int i = 0; i < StringCountInput.Value; i++)
            {
                // Get string entry
                uint   dataAddress = PS3.Extension.ReadUInt32(pointerAddress);
                string str         = PS3.Extension.ReadString(dataAddress);
                entry = new StringEntry {
                    PointerAddress = pointerAddress,
                    DataAddress    = dataAddress,
                    Text           = str
                };

                StringsList.Add(entry);                                         // Add string to list
                pointerAddress += 4;                                            // Move address to pointer in memory
                worker.ReportProgress((int)(i / StringCountInput.Value * 100)); // Report precent progress
            }
        }
예제 #2
0
        /// <summary>
        /// Saves to database. If culture is present, Translation entry is saved
        /// </summary>
        /// <param name="session"></param>
        /// <param name="input"></param>
        private void SaveStringToDatabase(ISession session, StringEntry input, bool overwrite)
        {
            var translatableString =
                (from s in session.Linq <LocalizableStringRecord>()
                 where s.StringKey == input.Key &&
                 s.Context == input.Context
                 select s).FirstOrDefault();

            if (translatableString == null)
            {
                string path = input.Path;
                if (!path.Contains("{0}") && !string.IsNullOrEmpty(input.Culture))
                {
                    path = path.Replace(input.Culture, "{0}");
                }
                translatableString = new LocalizableStringRecord
                {
                    Path      = path,
                    Context   = input.Context,
                    StringKey = input.Key,
                    OriginalLanguageString = input.English
                };
                if (!translatableString.Path.Contains("{0}"))
                {
                    throw new Exception("Path should contain {0}, but doesn't.\n" + translatableString.Path);
                }
                session.SaveOrUpdate(translatableString);
            }
            else if (translatableString.OriginalLanguageString != input.English)
            {
                translatableString.OriginalLanguageString = input.English;
                session.SaveOrUpdate(translatableString);
            }

            if (!string.IsNullOrEmpty(input.Culture) && !string.IsNullOrEmpty(input.Translation))
            {
                var translation =
                    (from t in translatableString.Translations
                     where t.Culture.Equals(input.Culture)
                     select t).FirstOrDefault();

                if (translation == null)
                {
                    translation = new TranslationRecord
                    {
                        Culture = input.Culture,
                        Value   = input.Translation
                    };
                    translatableString.AddTranslation(translation);
                }
                else if (overwrite)
                {
                    translation.Value = input.Translation;
                }
                session.SaveOrUpdate(translatableString);
                session.SaveOrUpdate(translation);
            }

            SetCacheInvalid();
        }
예제 #3
0
파일: Factory.cs 프로젝트: mpvyard/Minotaur
        public static StringEntry[] CreateStringChunk(int count, DateTime?start = null, double percentOfFill = 1.0, int ticksIntervalMs = 100)
        {
            var data = new StringEntry[(int)(count * percentOfFill)];

            var ticks     = (start ?? DateTime.Now).Ticks;
            var ticksStep = TimeSpan.FromMilliseconds(ticksIntervalMs).Ticks;

            data[0].ticks = ticks;
            data[0].SetValue(Guid.NewGuid().ToString("D"));

            for (int i = 1, j = 1; i < count && j < data.Length; i++)
            {
                ticks += ticksStep;

                if (!(random.NextDouble() + percentOfFill >= 1.0))
                {
                    continue;
                }

                data[j].ticks = ticks;
                data[j].SetValue(Guid.NewGuid().ToString("D"));
                j++;
            }
            return(data);
        }
        private static bool WriteResourceString(StringEntryBuilder builder, string context, string comment, string value)
        {
            var translation = new StringEntry()
            {
                Usage = !string.IsNullOrEmpty(comment) && comment != value ?
                        "#. " + comment : string.Empty,
                Context     = "msgctxt " + EnsureStringIsWrappedInQuotes(context),
                Id          = "msgid " + value,
                Translation = "msgstr " + value
            };

            if (!builder.ContainsKey(translation))
            {
                builder.Add(translation);
                return(true);
            }
            translation = builder[translation.UniqueKey];
            var newComment = "#. " + comment;

            if (!translation.Usage.Contains(newComment))
            {
                translation.Usage += "\r\n" + newComment;
            }
            return(false);
        }
        private static void ReadTranslations(FileStream inStream, List <StringEntry> translations)
        {
            var currentEntry = new StringBuilder();
            var comparer     = new StringEntryEqualityComparer();

            using (var reader = new StreamReader(inStream)) {
                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();
                    if (!string.IsNullOrWhiteSpace(line))
                    {
                        currentEntry.AppendLine(line);
                    }
                    else
                    {
                        var translation = StringEntry.Parse(currentEntry.ToString());
                        if (!translations.Contains(translation, comparer))
                        {
                            translations.Add(translation);
                        }
                        currentEntry = new StringBuilder();
                    }
                }
            }
        }
 private new void Awake()
 {
     base.Awake();
     if (Application.isPlaying)
     {
         if (this.key != string.Empty)
         {
             StringKey   key         = new StringKey(this.key);
             StringEntry stringEntry = Strings.Get(key);
             text = stringEntry.String;
         }
         text = Localization.Fixup(text);
         base.isRightToLeftText = Localization.IsRightToLeft;
         SetTextStyleSetting setTextStyleSetting = base.gameObject.GetComponent <SetTextStyleSetting>();
         if ((Object)setTextStyleSetting == (Object)null)
         {
             setTextStyleSetting = base.gameObject.AddComponent <SetTextStyleSetting>();
         }
         if (!allowOverride)
         {
             setTextStyleSetting.SetStyle(textStyleSetting);
         }
         textLinkHandler = GetComponent <TextLinkHandler>();
     }
 }
예제 #7
0
 public void Add(string item, int orderNumber)
 {
     if (_hashSet.Add(item))
     {
         _list.Add(new StringEntry(item, orderNumber));
     }
     else if (orderNumber != 0)
     {
         // Make sure to have same number
         for (int i = 0; i < _list.Count; ++i)
         {
             if (_list[i].StringValue == item)
             {
                 if (_list[i].OrderNumber == 0)
                 {
                     _list[i] = new StringEntry(item, orderNumber);
                 }
                 else if (_list[i].OrderNumber != orderNumber)
                 {
                     throw new Error(
                               "Cannot specify 2 different non-zero order number for \"" +
                               item + "\": " + _list[i].OrderNumber + " and " + orderNumber);
                 }
             }
         }
     }
 }
예제 #8
0
        public void AddRange(OrderableStrings collection, int outerOrderNumber = 0, OrderResolve resolveMethod = OrderResolve.None)
        {
            List <StringEntry> existingEntriesToAdd = null;

            foreach (var entry in collection._list)
            {
                var newEntry = new StringEntry(entry.StringValue, entry.OrderNumber + outerOrderNumber);

                if (_hashSet.Add(entry.StringValue))
                {
                    _list.Add(newEntry);
                }
                else if (newEntry.OrderNumber != 0)  // make sure to have orderNumber
                {
                    if (existingEntriesToAdd == null)
                    {
                        existingEntriesToAdd = new List <StringEntry>();
                    }
                    existingEntriesToAdd.Add(newEntry);
                }
            }
            if (existingEntriesToAdd != null)
            {
                Dictionary <string, int> dict = GetStringToOrderNumberDictionary(existingEntriesToAdd);
                for (int i = 0; i < _list.Count; ++i)
                {
                    int orderNumber;
                    if (dict.TryGetValue(_list[i].StringValue, out orderNumber))
                    {
                        if (_list[i].OrderNumber == 0)
                        {
                            _list[i] = new StringEntry(_list[i].StringValue, orderNumber);
                        }
                        else if (_list[i].OrderNumber != orderNumber)
                        {
                            if (resolveMethod == OrderResolve.Less)
                            {
                                if (orderNumber < _list[i].OrderNumber)
                                {
                                    _list[i] = new StringEntry(_list[i].StringValue, orderNumber);
                                }
                            }
                            else if (resolveMethod == OrderResolve.Greater)
                            {
                                if (orderNumber > _list[i].OrderNumber)
                                {
                                    _list[i] = new StringEntry(_list[i].StringValue, orderNumber);
                                }
                            }
                            else
                            {
                                throw new Error(
                                          "Cannot specify 2 different non-zero order number for \"" +
                                          _list[i].StringValue + "\": " + _list[i].OrderNumber + " and " + orderNumber);
                            }
                        }
                    }
                }
            }
        }
예제 #9
0
        private void lstCliloc_DrawItem(object sender, DrawItemEventArgs e)
        {
            StringEntry stringEntry = (StringEntry)this.lstCliloc.Items[e.Index];

            e.DrawBackground();
            e.Graphics.DrawString(stringEntry.Number.ToString(), this.lstCliloc.Font, Brushes.Black, (float)e.Bounds.X, (float)e.Bounds.Top);
            e.Graphics.DrawString(stringEntry.Text.ToString(), this.lstCliloc.Font, Brushes.Black, (float)(e.Bounds.X + 100), (float)e.Bounds.Top);
        }
예제 #10
0
    public StringEntry Get(StringKey key0)
    {
        int         hash  = key0.Hash;
        StringEntry value = null;

        Entries.TryGetValue(hash, out value);
        return(value);
    }
예제 #11
0
        private void DeleteStringCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            StringEntry entry = GetSourceEntry(e.Source);

            if (entry != null)
            {
                ((IEditableCollectionView)_stringView).Remove(entry);
            }
        }
예제 #12
0
        private void GoToGroupCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            StringEntry entry = GetSourceEntry(e.Source);

            if (entry != null)
            {
                cbLocaleGroups.SelectedItem = _groups.FirstOrDefault(g => g.Base == entry.Group);
            }
        }
예제 #13
0
        private void StringsListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            StringEntry entry = StringsList[StringsListBox.SelectedIndex];

            PointerInput.Value        = entry.PointerAddress;
            DataInput.Value           = entry.DataAddress;
            StringTextInput.MaxLength = entry.Text.Length;
            StringTextInput.Text      = entry.Text;
        }
예제 #14
0
 public void InsertPrefixSuffix(string prefix, string suffix)
 {
     for (int i = 0; i < _list.Count; ++i)
     {
         _list[i] = new StringEntry(prefix + _list[i].StringValue + suffix, _list[i].OrderNumber);
     }
     _hashSet.Clear();
     _hashSet.UnionWith(from i in _list select i.StringValue);
 }
예제 #15
0
 public void ToLower()
 {
     for (int i = 0; i < _list.Count; ++i)
     {
         _list[i] = new StringEntry(_list[i].StringValue.ToLower(), _list[i].OrderNumber);
     }
     _hashSet.Clear();
     _hashSet.UnionWith(from i in _list select i.StringValue);
 }
예제 #16
0
        /// <summary>
        ///     Begins editing a string entry.
        /// </summary>
        /// <param name="entry">The entry to begin editing.</param>
        private void StartEditing(StringEntry entry)
        {
            var cell = new DataGridCellInfo(entry, stringIdColumn);

            lvLocales.ScrollIntoView(entry);
            lvLocales.Focus();
            lvLocales.CurrentCell = cell;
            lvLocales.BeginEdit();
        }
예제 #17
0
        /*public void InitScripts()
         * {
         *      if (ScriptDefs.Exports.ContainsKey("strings"))
         *      {
         *              List<dynamic> export = ScriptDefs.Exports["strings"];
         *
         *              foreach (dynamic dyn in export)
         *              {
         *                      MenuItem item = new MenuItem
         *                      {
         *                              Header = dyn.label,
         *                              Tag = dyn,
         *                      };
         *                      item.Click += exportClick;
         *                      this.menuExport.Items.Add(item);
         *              }
         *      }
         *
         *      if (ScriptDefs.Imports.ContainsKey("strings"))
         *      {
         *              List<dynamic> import = ScriptDefs.Imports["strings"];
         *
         *              foreach (dynamic dyn in import)
         *              {
         *                      MenuItem item = new MenuItem
         *                      {
         *                              Header = dyn.label,
         *                              Tag = dyn,
         *                      };
         *                      item.Click += importClick;
         *                      this.menuImport.Items.Add(item);
         *              }
         *      }
         * }
         *
         * private void exportClick(object sender, RoutedEventArgs e)
         * {
         *      MenuItem item = sender as MenuItem;
         *
         *      dynamic dyn = item.Tag as dynamic;
         *
         *      SaveFileDialog dlg = new SaveFileDialog {
         *              ValidateNames = true,
         *              Filter = dyn.filter
         *      };
         *      bool res = (bool)dlg.ShowDialog();
         *
         *      if (res)
         *      {
         *              dyn.execute(dlg.FileName, this.Strings);
         *      }
         *
         * }
         *
         * private void importClick(object sender, RoutedEventArgs e)
         * {
         *      MenuItem item = sender as MenuItem;
         *
         *      dynamic dyn = item.Tag as dynamic;
         *
         *      if (dyn.needHash && this.Hashes == null)
         *      {
         *              MessageBox.Show("A HashList is required to import this type, Please select a Bundle Database", "Extra Action needed!", MessageBoxButton.OK);
         *
         *              OpenFileDialog dbdlg = new OpenFileDialog {
         *                      Multiselect = false,
         *                      Filter = "Bundle Database|*.blb",
         *                      CheckPathExists = true,
         *                      CheckFileExists = true
         *              };
         *
         *              bool dbres = (bool)dbdlg.ShowDialog();
         *
         *              if (dbres)
         *              {
         *                      this.UpdateHashes(dbdlg.FileName);
         *              }
         *      }
         *
         *      OpenFileDialog dlg = new OpenFileDialog {
         *              Multiselect = false,
         *              Filter = dyn.filter,
         *              CheckPathExists = true,
         *              CheckFileExists = true
         *      };
         *
         *      bool res = (bool)dlg.ShowDialog();
         *
         *      if (res)
         *      {
         *              this.Strings = (StringsFile)dyn.execute(dlg.FileName, this.Hashes);
         *      }
         * }*/

        private void lstStrings_SelectionChanged(object sender, EventArgs e)
        {
            StringEntry strEntry = this.grdStrings.SelectedItem as StringEntry;

            if (strEntry != null)
            {
                this.txtID.Text   = (strEntry.ID.HasUnHashed ? "" : "0x") + strEntry.ID.ToString();
                this.txtText.Text = strEntry.Text;
            }
        }
예제 #18
0
    public static StringEntry Get(StringKey key0)
    {
        StringEntry stringEntry = RootTable.Get(key0);

        if (stringEntry == null)
        {
            stringEntry = GetInvalidString(key0);
        }
        return(stringEntry);
    }
예제 #19
0
 /// <summary>
 ///     Wraps the strings in a <see cref="LocalizedStringList" />.
 /// </summary>
 /// <param name="list">The list to wrap.</param>
 /// <returns>The wrapped strings.</returns>
 private IEnumerable <StringEntry> WrapStrings(LocalizedStringList list)
 {
     return(list.Strings.Select(s =>
     {
         string stringIdName = _cache.StringIDs.GetString(s.Key) ?? s.Key.ToString();
         string adjustedStr = ReplaceSymbols(s.Value);
         var entry = new StringEntry(stringIdName, adjustedStr, list, s);
         return entry;
     }));
 }
예제 #20
0
            /// <summary>
            ///     Starts an add transaction and returns the pending new item.
            /// </summary>
            /// <returns>
            ///     The pending new item.
            /// </returns>
            object IEditableCollectionView.AddNew()
            {
                if (CurrentGroup == null)
                {
                    throw new InvalidOperationException("CurrentGroup is null");
                }

                var result = new StringEntry("", "", CurrentGroup, null);

                return(AddNewItem(result));
            }
예제 #21
0
파일: Languages.cs 프로젝트: mozkandemir/RE
        internal static string GetCliloc(int num)
        {
            if (m_CliLoc == null)
            {
                return(String.Empty);
            }

            StringEntry se = m_CliLoc.GetEntry(num);

            return(se != null?se.Format() : string.Empty);
        }
예제 #22
0
파일: Languages.cs 프로젝트: mozkandemir/RE
        internal static string ClilocFormat(int num, string argstr)
        {
            if (m_CliLoc == null)
            {
                return(String.Empty);
            }

            StringEntry se = m_CliLoc.GetEntry(num);

            return(se != null?se.SplitFormat(argstr) : string.Empty);
        }
예제 #23
0
파일: Languages.cs 프로젝트: mozkandemir/RE
        internal static string ClilocFormat(int num, params object[] args)
        {
            if (m_CliLoc == null)
            {
                return(String.Empty);
            }

            StringEntry se = m_CliLoc.GetEntry(num);

            return(se != null?se.Format(args) : string.Empty);
        }
예제 #24
0
        public void Read(Stream stream)
        {
            Header.Read(stream);

            //the string entries
            while (Entries.Count < Header.EntryCount)
            {
                StringEntry ent = new StringEntry(stream);
                Entries.Add(ent.Key, ent);
            }
        }
예제 #25
0
    public static StringEntry Get(string key)
    {
        StringKey   stringKey   = new StringKey(key);
        StringEntry stringEntry = RootTable.Get(stringKey);

        if (stringEntry == null)
        {
            stringEntry = GetInvalidString(stringKey);
        }
        return(stringEntry);
    }
예제 #26
0
 public void SetString(string key, string value)
 {
     if (!entries.ContainsKey(key))
     {
         entries.Add(key, new StringEntry(key, value));
     }
     else
     {
         entries[key] = new StringEntry(key, value);
     }
 }
예제 #27
0
 private static Exception GetExceptionFromConstructor(string id, string value, out StringEntry result)
 {
     try {
         result = new StringEntry(id, value);
     } catch (Exception e) {
         result = null;
         return(e);
     }
     // Constructor succeeded
     return(null);
 }
예제 #28
0
 private static Exception GetExceptionFromConstructor(string json, out StringEntry result)
 {
     try {
         result = new StringEntry(JToken.Parse(json));
     } catch (Exception e) {
         result = null;
         return(e);
     }
     // Constructor succeeded
     return(null);
 }
예제 #29
0
파일: StringDb.cs 프로젝트: elitak/NoxTools
        public void Read(Stream stream)
        {
            Header.Read(stream);

            //the string entries
            while (Entries.Count < Header.EntryCount)
            {
                StringEntry ent = new StringEntry(stream);
                Entries.Add(ent.Key, ent);
            }
        }
 internal void SwapFont(TMP_FontAsset font, bool isRightToLeft)
 {
     base.font = font;
     if (this.key != string.Empty)
     {
         StringKey   key         = new StringKey(this.key);
         StringEntry stringEntry = Strings.Get(key);
         text = stringEntry.String;
     }
     text = Localization.Fixup(text);
     base.isRightToLeftText = isRightToLeft;
 }
예제 #31
0
        private void btnAddNew_Click_1(object sender, RoutedEventArgs e)
        {
            if (_currentGroup == null)
            {
                MetroMessageBox.Show("Language Pack Editor",
                                     "You must select a specific string list first in order to add a new string.");
                return;
            }

            StringEntry entry = NewEntry();

            StartEditing(entry);
        }
 private static void ReadTranslations(FileStream inStream, List<StringEntry> translations) {
     var translation = new StringEntry();
     var comparer = new StringEntryEqualityComparer();
     using (var reader = new StreamReader(inStream)) {
         while (!reader.EndOfStream) {
             var line = reader.ReadLine();
             if (line != null) {
                 if (line.StartsWith("#: ")) {
                     translation.Context = line;
                 }
                 if (line.StartsWith("msgctxt ")) {
                     translation.Context = line;
                 }
                 else if (line.StartsWith("#| msgid ")) {
                     translation.Key = line;
                 }
                 else if (line.StartsWith("msgid ")) {
                     translation.English = line;
                 }
                 else if (line.StartsWith("msgstr ")) {
                     translation.Translation = line;
                     if (!translations.Contains(translation, comparer)) {
                         translations.Add(translation);
                     }
                     translation = new StringEntry();
                 }
             }
         }
     }
 }
        private static bool WriteResourceString(StringEntryBuilder builder, string context, string comment, string value) {
            var translation = new StringEntry()
            {
                Usage = !string.IsNullOrEmpty(comment) && comment != value ?
                    "#. " + comment : string.Empty,
                Context = "msgctxt " + context,
                Id = "msgid " + value,
                Translation = "msgstr " + value
            };

            if (!builder.ContainsKey(translation)) {
                builder.Add(translation);
                return true;
            }
            translation = builder[translation.UniqueKey];
            var newComment = "#. " + comment;
            if (!translation.Usage.Contains(newComment))
                translation.Usage += "\r\n" + newComment;
            return false;
        }
예제 #34
0
            public static Entry CreateEntry( string name, object value, string defaultNamespace, string defaultDeclaringClass )
            {
                string stringValue = value as string;
                System.Drawing.Bitmap bitmapValue = value as System.Drawing.Bitmap;
                byte[] rawValue = value as byte[];
                Entry entry = null;

                if(stringValue != null)
                {
                    entry = new StringEntry( name, stringValue );
                }
                else if(bitmapValue != null)
                {
                    entry = new BitmapEntry( name, bitmapValue );
                }
                if(rawValue != null)
                {
                    entry = TinyResourcesEntry.TryCreateTinyResourcesEntry( name, rawValue );

                    if(entry == null)
                    {
                        entry = new BinaryEntry( name, rawValue );
                    }
                }

                if(entry == null)
                {
                    throw new Exception();
                }

                if(entry.Namespace.Length == 0)
                {
                    entry.Namespace = defaultNamespace;
                }

                if(entry.ClassName.Length == 0)
                {
                    ResourceTypeDescription typeDescription = ResourceTypeDescriptionFromResourceType( entry.ResourceType );
                    entry.ClassName = typeDescription.defaultEnum;

                    if(!string.IsNullOrEmpty( defaultDeclaringClass ))
                    {
                        entry.ClassName = string.Format( "{0}+{1}", defaultDeclaringClass, entry.ClassName );
                    }
                }

                return entry;
            }
예제 #35
0
	public StringMatcher()
		{
		strings = new StringEntry[0];
		maxLen = 0;
		}
예제 #36
0
	// Register the given string with this matcher.  The info parameter will
	// be returned from our Match method when this string is detected.
	// 
	// If isIdentifier is true, then we only match this string when it is
	// followed by a non-identifier character (or the end of the stream).
	public void AddString(string theString, int info, bool isIdentifier)
		{
		int tempLen = (isIdentifier) ? theString.Length+1 : theString.Length;
		if (maxLen < tempLen)
			maxLen = tempLen;
		
		// If necessary, extend the major axis of our strings table to
		// accomodate theString's first character.  We extend the array
		// by more than strictly necessary, to avoid an excessive number
		// of small extensions.
		char initialChar = theString[0];
		if (initialChar >= strings.Length)
			{
			StringEntry[] newStrings = new StringEntry[(initialChar+1)*2];
			Array.Copy(strings, 0, newStrings, 0, strings.Length);
			strings = newStrings;
			}
		
		// Create a StringEntry for this string, and store it in our
		// strings table.  Make sure to preserve the "decreasing length"
		// rule.
		StringEntry entry = new StringEntry();
		entry.headlessString = theString.ToCharArray(1, theString.Length-1);
		entry.isIdentifier = isIdentifier;
		entry.info = info;
		
		if ( strings[initialChar] == null ||
			 entry.headlessString.Length >= strings[initialChar].headlessString.Length )
			{
			entry.next = strings[initialChar];
			strings[initialChar] = entry;
			}
		else
			{
			StringEntry predecessor = strings[initialChar];
			while ( predecessor.next != null &&
					entry.headlessString.Length < predecessor.next.headlessString.Length )
				predecessor = predecessor.next;
			
			entry.next = predecessor.next;
			predecessor.next = entry;
			}
		
		} // AddString
        /// <summary>
        /// Saves to database. If culture is present, Translation entry is saved
        /// </summary>
        /// <param name="session"></param>
        /// <param name="input"></param>
        private void SaveStringToDatabase(ISession session, StringEntry input, bool overwrite)
        {
            var translatableString =
              (from s in session.Linq<LocalizableStringRecord>()
               where s.StringKey == input.Key
              && s.Context == input.Context
               select s).FirstOrDefault();
              if (translatableString == null)
              {
            string path = input.Path;
            if (!path.Contains("{0}") && !string.IsNullOrEmpty(input.Culture))
              path = path.Replace(input.Culture, "{0}");
            translatableString = new LocalizableStringRecord
            {
              Path = path,
              Context = input.Context,
              StringKey = input.Key,
              OriginalLanguageString = input.English
            };
            if (!translatableString.Path.Contains("{0}"))
              throw new Exception("Path should contain {0}, but doesn't.\n" + translatableString.Path);
            session.SaveOrUpdate(translatableString);
              }
              else if (translatableString.OriginalLanguageString != input.English)
              {
            translatableString.OriginalLanguageString = input.English;
            session.SaveOrUpdate(translatableString);
              }

              if (!string.IsNullOrEmpty(input.Culture) && !string.IsNullOrEmpty(input.Translation))
              {
            var translation =
            (from t in translatableString.Translations
             where t.Culture.Equals(input.Culture)
             select t).FirstOrDefault();

            if (translation == null)
            {
              translation = new TranslationRecord
            {
              Culture = input.Culture,
              Value = input.Translation
            };
              translatableString.AddTranslation(translation);
            }
            else if (overwrite)
            {
              translation.Value = input.Translation;
            }
            session.SaveOrUpdate(translatableString);
            session.SaveOrUpdate(translation);
              }

              SetCacheInvalid();
        }
예제 #38
0
		/// <summary>
		///     Wraps the strings in a <see cref="LocalizedStringList" />.
		/// </summary>
		/// <param name="list">The list to wrap.</param>
		/// <returns>The wrapped strings.</returns>
		private IEnumerable<StringEntry> WrapStrings(LocalizedStringList list)
		{
			return list.Strings.Select(s =>
			{
				string stringIdName = _cache.StringIDs.GetString(s.Key) ?? s.Key.ToString();
				string adjustedStr = ReplaceSymbols(s.Value);
				var entry = new StringEntry(stringIdName, adjustedStr, list, s);
				return entry;
			});
		}
예제 #39
0
		/// <summary>
		///     Resolves the stringID for a string entry, creating a new stringID if it doesn't exist.
		/// </summary>
		/// <param name="entry">The entry to resolve a stringID for.</param>
		/// <returns>The resolved stringID.</returns>
		private StringID ResolveStringID(StringEntry entry)
		{
			if (entry.StringID == "")
			{
				return StringID.Null;
			}
			if (entry.Base != null)
			{
				// If the stringID didn't change, then re-use it
				string oldKeyStr = _cache.StringIDs.GetString(entry.Base.Key);
				if (oldKeyStr == entry.StringID)
					return entry.Base.Key;
			}
			if (StringIDTrie.Contains(entry.StringID))
			{
				// String already exists in the cache file
				return _cache.StringIDs.FindStringID(entry.StringID);
			}
			// Create a new string
			StringIDTrie.Add(entry.StringID);
			return _cache.StringIDs.AddString(entry.StringID);
		}
예제 #40
0
		/// <summary>
		///     Begins editing a string entry.
		/// </summary>
		/// <param name="entry">The entry to begin editing.</param>
		private void StartEditing(StringEntry entry)
		{
			var cell = new DataGridCellInfo(entry, stringIdColumn);
			lvLocales.ScrollIntoView(entry);
			lvLocales.Focus();
			lvLocales.CurrentCell = cell;
			lvLocales.BeginEdit();
		}
예제 #41
0
			/// <summary>
			///     Starts an add transaction and returns the pending new item.
			/// </summary>
			/// <returns>
			///     The pending new item.
			/// </returns>
			object IEditableCollectionView.AddNew()
			{
				if (CurrentGroup == null)
					throw new InvalidOperationException("CurrentGroup is null");

				var result = new StringEntry("", "", CurrentGroup, null);
				return AddNewItem(result);
			}