コード例 #1
0
        //
        // Load from Archive
        //

        private static void FillNamespaceFromArchieve(InternalFormat document, string Culture, string parentNamespaceName, UnrealNamespace <UnrealArchive> sourceArchieve)
        {
            // find namespace

            string resultNamespaceName = InternalNamespace.MakeName(parentNamespaceName, sourceArchieve.Namespace);

            InternalNamespace resultNamespace = null;

            foreach (var ns in document.Namespaces)
            {
                if (ns.Name == resultNamespaceName)
                {
                    resultNamespace = ns;
                    break;
                }
            }

            if (resultNamespace == null)
            {
                throw new FormatException("Can't find namespace for parent: '" + parentNamespaceName +
                                          "' and source '" + sourceArchieve.Namespace + "'");
            }

            // fill namespace from childs

            if (sourceArchieve.Children != null)
            {
                foreach (var child in sourceArchieve.Children)
                {
                    InternalText   text   = new InternalText();
                    InternalRecord record = resultNamespace[child.Key];

                    text.Culture = Culture;
                    if (record.Source != child.Source.Text)
                    {
                        text.Text = "";
                    }
                    else
                    {
                        text.Text = child.Translation.Text;
                    }

                    record.Translations.Add(text);
                }
            }

            // recursively repeat for all Subnamespaces

            if (sourceArchieve.Subnamespaces != null)
            {
                foreach (var subnamespace in sourceArchieve.Subnamespaces)
                {
                    FillNamespaceFromArchieve(document, Culture, resultNamespaceName, subnamespace);
                }
            }
        }
コード例 #2
0
        public static InternalFormat Import(string FileName)
        {
            var data = new InternalFormat();

            var fileInfo  = new FileInfo(FileName);
            var Package   = new ExcelPackage(fileInfo);
            var Worksheet = Package.Workbook.Worksheets[1];

            // read document data
            int rowCount    = Worksheet.Dimension.End.Row;
            int columnCount = Worksheet.Dimension.End.Column;
            var Cells       = Worksheet.Cells;

            // read native and other cultures
            data.Cultures = new List <string>();
            for (int col = 3; col <= columnCount; col++)
            {
                if (Cells[1, col] != null)
                {
                    // third column is NativeCulture
                    if (col == 3)
                    {
                        data.NativeCulture = Cells[1, col].Text;
                    }
                    data.Cultures.Add(Cells[1, col].Text);
                }
            }

            int index        = 2;
            int cultureCount = data.Cultures.Count;
            List <InternalRecord> records = new List <InternalRecord>(rowCount / 2);

            // read all translation keys
            for (; Cells[index, 1].Text != serviceData; index++)
            {
                InternalRecord record = new InternalRecord();
                record.Key          = GetKey(Cells[index, 2].Text);
                record.Translations = new List <InternalText>(cultureCount);
                for (int culture = 0; culture < cultureCount; culture++)
                {
                    InternalText translation = new InternalText();
                    translation.Culture = data.Cultures[culture];
                    translation.Text    = SafeMultilineText(Cells[index, culture + 3].Text);
                    record.Translations.Add(translation);
                }
                records.Add(record);
            }

            int indexOfServiceData = index;

            data.Namespaces = new List <InternalNamespace>();
            InternalNamespace lastNS = null;

            index++;
            for (; index < rowCount + 1; index++)
            {
                string source = Cells[index, 1].Text;
                string ns     = Cells[index, 2].Text;
                string key    = Cells[index, 3].Text;
                string path   = Cells[index, 4].Text;

                if (lastNS == null || lastNS.Name != ns)
                {
                    lastNS          = new InternalNamespace();
                    lastNS.Name     = ns;
                    lastNS.Children = new List <InternalRecord>();
                    data.Namespaces.Add(lastNS);
                }

                InternalRecord record = records[index - indexOfServiceData - 1];
                if (record.Key != key)
                {
                    throw new FormatException("Unexpected key: " + key + "!");
                }

                record.Source = SafeMultilineText(source);
                record.Path   = path;
                lastNS.Children.Add(record);
            }

            return(data);
        }