Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 2
0
        //
        // Utilites
        //

        public void SetRowTranslation(DataGridViewRow row, string text)
        {
            InternalRecord record = (InternalRecord)row.Tag;

            if (record != null)
            {
                string culture = cultureCombo.SelectedItem.ToString();
                row.Cells[4].Value = text;
                record[culture]    = text;
            }
        }
Ejemplo n.º 3
0
 private void UpdateLocaleListTranslation()
 {
     dataGrid.SuspendLayout();
     if (document != null)
     {
         string culture = cultureCombo.Text;
         foreach (DataGridViewRow item in dataGrid.Rows)
         {
             InternalRecord record = (InternalRecord)item.Tag;
             item.Cells[4].Value = record[culture];
         }
     }
     dataGrid.ResumeLayout();
 }
Ejemplo n.º 4
0
        //
        // Load from Manifest
        //

        private static void AppendNamespaceFromManifest(InternalFormat document,
                                                        string parentNamespaceName, UnrealNamespace <UnrealManifest> sourceNamespace)
        {
            InternalNamespace resultNamespace = new InternalNamespace();

            // generate namespace name

            resultNamespace.Name = InternalNamespace.MakeName(parentNamespaceName, sourceNamespace.Namespace);

            // fill from all Childrens records

            resultNamespace.Children = new List <InternalRecord>();
            if (sourceNamespace.Children != null)
            {
                foreach (var child in sourceNamespace.Children)
                {
                    foreach (var key in child.Keys)
                    {
                        InternalRecord record = new InternalRecord();
                        record.Source       = child.Source.Text;
                        record.Key          = key.Key;
                        record.Translations = new List <InternalText>();
                        record.Path         = key.Path;
                        resultNamespace.Children.Add(record);
                    }
                }
            }

            // add this namespace to List

            document.Namespaces.Add(resultNamespace);

            // recursive add all subnamespaces

            if (sourceNamespace.Subnamespaces != null)
            {
                foreach (var subnamespace in sourceNamespace.Subnamespaces)
                {
                    AppendNamespaceFromManifest(document, resultNamespace.Name, subnamespace);
                }
            }
        }
Ejemplo n.º 5
0
 private void OnSelectedIndexChanged(object sender, EventArgs e)
 {
     if (dataGrid.SelectedRows.Count > 0)
     {
         DataGridViewRow row    = dataGrid.SelectedRows[0];
         InternalRecord  record = (InternalRecord)row.Tag;
         if (record != null)
         {
             namespaceEdit.Text   = (row.Cells[1].Value != null) ? row.Cells[1].Value.ToString() : "";
             keyEdit.Text         = record.Key;
             pathEdit.Text        = record.Path;
             translationEdit.Text = (row.Cells[4].Value != null) ? row.Cells[4].Value.ToString() : "";
         }
     }
     else
     {
         namespaceEdit.Text   = "";
         keyEdit.Text         = "";
         pathEdit.Text        = "";
         translationEdit.Text = "";
     }
 }
Ejemplo n.º 6
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);
        }