예제 #1
0
        public void LoadFromManifest(string InFileName, string FileText)
        {
            Clear();

            LocaleManifest manifest = JsonConvert.DeserializeObject <LocaleManifest>(FileText);

            if (ManifestVersion != manifest.FormatVersion)
            {
                throw new FormatException("Invalid Manifest::FormatVersion.");
            }

            if (ManifestNamespace != manifest.Namespace)
            {
                throw new FormatException("Invalid Manifest::Namespace. Must be empty.");
            }

            // Move "Children" to "Subnamespace" without name
            if (manifest.Children != null && manifest.Children.Count > 0)
            {
                LocaleManifestNamespace emptyNS = new LocaleManifestNamespace();
                emptyNS.Namespace = "";
                emptyNS.Children  = manifest.Children;
                manifest.Subnamespaces.Insert(0, emptyNS);
            }

            Subnamespaces = new List <InternalNamespace>();
            foreach (var ns in manifest.Subnamespaces)
            {
                InternalNamespace ins = new InternalNamespace();
                ins.Name     = ns.Namespace;
                ins.Children = new List <InternalRecord>(ns.Children.Count);

                foreach (var child in ns.Children)
                {
                    InternalRecord record = new InternalRecord();
                    record.Source = child.Source.Text;
                    record.Keys   = new List <InternalKey>(child.Keys.Count);

                    foreach (var key in child.Keys)
                    {
                        InternalKey ikey = new InternalKey();
                        ikey.Key          = key.Key;
                        ikey.Path         = key.Path;
                        ikey.Translations = new List <InternalText>();
                        ikey.parent       = record;
                        record.Keys.Add(ikey);
                    }

                    ins.Children.Add(record);
                }

                Subnamespaces.Add(ins);
            }

            Cultures = new List <string>();
        }
예제 #2
0
        public string SaveToManifest()
        {
            if (Subnamespaces != null && Subnamespaces.Count > 0)
            {
                LocaleManifest manifest = new LocaleManifest();
                manifest.FormatVersion = ManifestVersion;
                manifest.Namespace     = ManifestNamespace;
                manifest.Subnamespaces = new List <LocaleManifestNamespace>();

                foreach (var ins in Subnamespaces)
                {
                    LocaleManifestNamespace ns = new LocaleManifestNamespace();
                    ns.Namespace = ins.Name;

                    if (ins.Children != null && ins.Children.Count > 0)
                    {
                        ns.Children = new List <LocaleManifestChild>(ins.Children.Count);
                        foreach (var rec in ins.Children)
                        {
                            LocaleManifestChild child = new LocaleManifestChild();
                            child.Source      = new LocaleSource();
                            child.Source.Text = rec.Source;
                            child.Keys        = new List <LocaleKey>(rec.Keys.Count);
                            foreach (var ikey in rec.Keys)
                            {
                                LocaleKey key = new LocaleKey();
                                key.Key  = ikey.Key;
                                key.Path = ikey.Path;
                                child.Keys.Add(key);
                            }
                            ns.Children.Add(child);
                        }
                    }

                    if (ns.Namespace == "")
                    {
                        manifest.Children = ns.Children;
                    }
                    else
                    {
                        manifest.Subnamespaces.Add(ns);
                    }
                }

                return(JsonConvert.SerializeObject(manifest, Formatting.Indented));
            }

            return("");
        }