コード例 #1
0
ファイル: Program.cs プロジェクト: stjmonde/MuiDB
        public static void Configure(Args.ConfigureCommand cmd)
        {
            string dir = GetFullNormalizedDirectory(cmd.MuiDB);

            foreach (var file in GetMatchingFiles(dir, Path.GetFileName(cmd.MuiDB)))
            {
                var muidb    = new MuiDBFile(file);
                var modified = false;

                if (cmd.BaseName != null && cmd.BaseName != muidb.BaseName)
                {
                    muidb.BaseName = cmd.BaseName;
                    modified       = true;
                }

                if (cmd.CodeNamespace != null && cmd.CodeNamespace != muidb.CodeNamespace)
                {
                    muidb.CodeNamespace = cmd.CodeNamespace;
                    modified            = true;
                }

                if (cmd.ProjectTitle != null && cmd.ProjectTitle != muidb.ProjectTitle)
                {
                    muidb.ProjectTitle = cmd.ProjectTitle;
                    modified           = true;
                }

                if (modified)
                {
                    muidb.Save();
                }
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: stjmonde/MuiDB
        public static void Verify(Args.ValidateCommand cmd)
        {
            Verbose(cmd, $"Validating file '{cmd.MuiDB}' against MuiDB schema");
            var muidb = new MuiDBFile(cmd.MuiDB);

            muidb.Validate();
            if (cmd.ReFormat)
            {
                Verbose(cmd, $"Applying default format to '{cmd.MuiDB}'");
                muidb.Save();
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: stjmonde/MuiDB
        public static void Info(Args.InfoCommand cmd)
        {
            var muidb           = new MuiDBFile(cmd.MuiDB);
            var initialCount    = 0;
            var translatedCount = 0;
            var reviewedCount   = 0;
            var finalCount      = 0;
            var commentCount    = 0;
            var itemCount       = 0;
            var langs           = new HashSet <string>();

            foreach (var i in muidb.Items)
            {
                ++itemCount;
                commentCount += i.Comments.Count();

                foreach (var text in i.Texts)
                {
                    if (!langs.Contains(text.Key))
                    {
                        langs.Add(text.Key);
                    }

                    switch (text.Value.State)
                    {
                    case "translated": ++translatedCount; break;

                    case "initial": ++initialCount; break;

                    case "reviewed": ++reviewedCount; break;

                    case "final": ++finalCount; break;

                    default:
                        Console.Error.WriteLine($"Unknown state '{text.Value.State}' for item id={i.Id} and lang={text.Key}");
                        break;
                    }
                }
            }

            Console.WriteLine($"  items total : {itemCount}");
            Console.WriteLine($"  languages   : {langs.Count}");
            Console.WriteLine($"  # initial   : {initialCount}");
            Console.WriteLine($"  # translated: {translatedCount}");
            Console.WriteLine($"  # reviewed  : {reviewedCount}");
            Console.WriteLine($"  # final     : {finalCount}");

            Console.WriteLine("Configured output files:");
            foreach (var file in muidb.TargetFiles)
            {
                Console.WriteLine($" - {file.Name} (lang={file.Lang})");
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: stjmonde/MuiDB
        public static void ExportFile(Args.ExportFileCommand cmd)
        {
            var muidb = new MuiDBFile(cmd.MuiDB);

            switch (cmd.Type.ToLowerInvariant())
            {
            case "resx":
                var options = cmd.NoComments ? MuiDBFile.SaveOptions.SkipComments : MuiDBFile.SaveOptions.None;
                muidb.ExportResX(cmd.Out, cmd.Lang, options);
                Verbose(cmd, $"Exporting language '{cmd.Lang}' into file '{cmd.Out}'");
                break;

            case "xliff":
                throw new Exception("XLIFF export is not implemented, yet");

            default:
                throw new Exception($"Unknown format: {cmd.Type}");
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: stjmonde/MuiDB
        public static void Export(Args.ExportCommand cmd)
        {
            string dir = GetFullNormalizedDirectory(cmd.MuiDB);

            foreach (var file in GetMatchingFiles(dir, Path.GetFileName(cmd.MuiDB)))
            {
                var muidb = new MuiDBFile(file);
                if (!muidb.TargetFiles.Any())
                {
                    throw new InvalidOperationException($"'{file}' does not contain any files to export");
                }

                Verify(new Args.ValidateCommand()
                {
                    MuiDB = file, Verbose = cmd.Verbose, ReFormat = cmd.ReFormat
                });

                Verbose(cmd, $"Exporting from file '{file}'");

                foreach (var target in muidb.TargetFiles)
                {
                    var targetFile = Path.Combine(dir, target.Name);
                    Verbose(cmd, $"Exporting language '{target.Lang}' into file '{targetFile}'");
                    muidb.ExportResX(targetFile, target.Lang, MuiDBFile.SaveOptions.None);

                    var d = target.Designer;
                    if (d != null)
                    {
                        try
                        {
                            var codeNamespace = cmd.CodeNamespace ?? d.Namespace;
                            Verbose(cmd, $"Generating '{d.ClassName}.Designer.cs' from '{targetFile}' with namespace={codeNamespace} and internal={d.IsInternal}");
                            ResX.ResXFile.GenerateDesignerFile(targetFile, d.ClassName, codeNamespace, d.IsInternal);
                        }
                        catch (Exception e)
                        {
                            throw new Exception($"Generating designer file for '{file}' failed", e);
                        }
                    }
                }
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: stjmonde/MuiDB
        public static void ImportFile(Args.ImportFileCommand cmd)
        {
            var muidb = new MuiDBFile(cmd.Muidb, MuiDBFile.OpenMode.CreateIfMissing);

            switch (cmd.Type.ToLowerInvariant())
            {
            case "resx":
                var result = muidb.ImportResX(cmd.In, cmd.Lang);
                if (cmd.Verbose)
                {
                    foreach (var added in result.AddedItems)
                    {
                        Console.WriteLine($"Added resource '{added}'");
                    }

                    foreach (var updated in result.UpdatedItems)
                    {
                        Console.WriteLine($"Updated resource '{updated}'");
                    }
                }

                Console.WriteLine($"Added items: {result.AddedItems.Count}\nupdated items: {result.UpdatedItems.Count}");
                break;

            case "xliff":
                var doc  = new XliffParser.XlfDocument(cmd.In);
                var file = doc.Files.First();

                Verbose(cmd, $"Adding/updating resources for language '{cmd.Lang}...");

                foreach (var unit in file.TransUnits)
                {
                    var id = unit.Id;
                    if (string.Equals(id, "none"))
                    {
                        id = unit.Optional.Resname;
                    }

                    var comment = unit.Optional.Notes.Any() ? unit.Optional.Notes.First().Value : null;
                    Verbose(cmd, $"Adding/updating resource '{id}': text='{unit.Target}', state='{unit.Optional.TargetState}'");

                    string translatedState;
                    try
                    {
                        translatedState = StateConverter.ToMuiDB(unit.Optional.TargetState);
                    }
                    catch (Exception)
                    {
                        translatedState = StateConverter.MuiDbStates.New;
                        Console.Error.WriteLine($"Warning: state '{unit.Optional.TargetState}' of item '{id}' is unknown and will be mapped to '{translatedState}'");
                    }

                    muidb.AddOrUpdateString(id, cmd.Lang, unit.Target, translatedState, comment);
                }

                break;

            default:
                throw new Exception($"Unknown format: {cmd.Type}");
            }

            muidb.Save();
        }