コード例 #1
0
        public static string SaveToManifest(InternalFormat document)
        {
            if (document.Namespaces == null)
            {
                throw new ArgumentException("Can't save empty archieve");
            }

            var manifest = new UnrealNamespace <UnrealManifest>(ManifestVersion, ManifestNamespace);

            foreach (var internalNamespace in document.Namespaces)
            {
                var sns = CreateSubnamespace(internalNamespace.Name, manifest);

                foreach (var record in internalNamespace.Children)
                {
                    var child = CreateManifestChild(record.Source, sns);

                    var key = new UnrealKey();
                    key.Key  = record.Key;
                    key.Path = record.Path;

                    child.Keys.Add(key);
                }
            }

            return(JsonConvert.SerializeObject(manifest, Formatting.Indented));
        }
コード例 #2
0
        //
        // Save to Manifest
        //

        private static UnrealManifest CreateManifestChild(string Source, UnrealNamespace <UnrealManifest> Root)
        {
            if (Root.Children != null)
            {
                foreach (var child in Root.Children)
                {
                    if (child.Source.Text == Source)
                    {
                        return(child);
                    }
                }
            }

            if (Root.Children == null)
            {
                Root.Children = new List <UnrealManifest>();
            }

            var newChild = new UnrealManifest();

            newChild.Source      = new UnrealText();
            newChild.Source.Text = Source;
            newChild.Keys        = new List <UnrealKey>();
            Root.Children.Add(newChild);

            return(newChild);
        }
コード例 #3
0
        private static UnrealNamespace <T> CreateSubnamespace <T>(string FullName, UnrealNamespace <T> Root)
        {
            UnrealNamespace <T> result = Root;

            string[] splittedName = InternalNamespace.SplitName(FullName);

            if (splittedName.Length == 1 && splittedName[0] == "")
            {
                return(result);
            }

            foreach (var namespaceName in splittedName)
            {
                result = result.CreateSubnamespace(namespaceName);
            }

            return(result);
        }
コード例 #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);
                }
            }
        }
コード例 #5
0
        public UnrealNamespace <T> CreateSubnamespace(string SubnamespaceName)
        {
            if (Subnamespaces == null)
            {
                Subnamespaces = new List <UnrealNamespace <T> >();
            }

            foreach (var sns in Subnamespaces)
            {
                if (sns.Namespace == SubnamespaceName)
                {
                    return(sns);
                }
            }

            var nns = new UnrealNamespace <T>();

            nns.Namespace = SubnamespaceName;
            Subnamespaces.Add(nns);
            return(nns);
        }
コード例 #6
0
        public static string SaveToArchive(InternalFormat document, string Culture)
        {
            if (document.Cultures == null || document.Cultures.Contains(Culture) == false)
            {
                throw new ArgumentException("Culture not found: " + Culture);
            }

            if (document.Namespaces == null)
            {
                throw new ArgumentException("Can't save empty archieve");
            }

            var archive = new UnrealNamespace <UnrealArchive>(ArchiveVersion, ArchiveNamespace);

            foreach (var internalNamespace in document.Namespaces)
            {
                var sns = CreateSubnamespace(internalNamespace.Name, archive);

                foreach (var record in internalNamespace.Children)
                {
                    UnrealArchive child = new UnrealArchive();
                    child.Source           = new UnrealText();
                    child.Source.Text      = record.Source;
                    child.Translation      = new UnrealText();
                    child.Translation.Text = record[Culture];
                    child.Key = record.Key;

                    if (sns.Children == null)
                    {
                        sns.Children = new List <UnrealArchive>();
                    }
                    sns.Children.Add(child);
                }
            }

            return(JsonConvert.SerializeObject(archive, Formatting.Indented));
        }
コード例 #7
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);
                }
            }
        }