コード例 #1
0
        /// <summary>
        /// Parses the translation file.
        /// </summary>
        /// <returns>An array containing TranslationItems.</returns>
        internal TranslationCollection ParseTranslations()
        {
            TranslationItemList controls = new TranslationItemList();
            TranslationItemList constants = new TranslationItemList();

            // For debug purposes, we add the first letter of the translation file to
            // the line.
            string suffix = "";
            #if DEBUG
            FileInfo info = new FileInfo(Filename);
            suffix = " (" + info.Name[0] + ")";
            #endif

            string owner = Translation.GlobalId;
            // Run through contents, finding [Owner] and parsing other lines

            foreach (string currentLine in fileContents)
            {
                string trimmedLine = currentLine.Trim();
                if (trimmedLine.StartsWith("#"))     // Comment, ignore
                    continue;
                if (trimmedLine.Equals(""))          // Empty line, ignore
                    continue;

                if (trimmedLine.StartsWith("[") && trimmedLine.EndsWith("]"))
                {
                    // Owner specification, eg: [frmWizard]
                    owner = trimmedLine.Substring(1, trimmedLine.Length - 2);
                }
                else if (trimmedLine.StartsWith("!"))
                {
                    // Constant, eg: !Name = Value
                    try
                    {
                        TranslationItem constant =
                            TranslationItem.Parse(owner, currentLine + suffix);
                        constants.Add(constant.Key, constant);
                    }
                    catch(Exception ex)
                    {
                        // Ignore
                        System.Diagnostics.Debug.Assert(false, "Constant error: " + ex.Message);
                    }
                } /* else if (trimmedLine.StartsWith("!")) */
                else
                {
                    // Standard line, parse it
                    try
                    {
                        TranslationItem translationItem
                            = TranslationItem.Parse(owner, currentLine + suffix);
                        controls.Add(translationItem.Key, translationItem);
                    }
                    catch(Exception ex)
                    {
                        // Ignore errors
                        System.Diagnostics.Debug.Assert(false, "Constant error: " + ex.Message);
                    }
                } /* else */
            } /* foreach (string currentLine... */

            return new TranslationCollection(constants, controls);
        }
コード例 #2
0
 /// <summary>
 /// Creates a new instance of the TranslationCollection class.
 /// </summary>
 public TranslationCollection(TranslationItemList ConstantsList,
     TranslationItemList ControlsList)
 {
     Constants = ConstantsList;
     Controls = ControlsList;
 }