Example #1
0
        private static string GetGamepadSourceName(Gamepad gamepad, int index)
        {
            var baseName   = Tr._("Gamepad");
            var deviceName = gamepad.name ?? Tr._p("device name", "Unknown");

            return($"{baseName} '{deviceName}' ({index + 1})");
        }
Example #2
0
        private static bool CheckOptions([NotNull] Options options, [NotNull] out StringBuilder message)
        {
            message = new StringBuilder();
            try
            {
                if (options.InputFiles.Count == 0)
                {
                    // Add all supported formats
                    options.InputFiles.Add("*.cs");
                    options.InputFiles.Add("*.xaml");
                }
                if (options.InputDirs.Count == 0)
                {
                    options.InputDirs.Add(Environment.CurrentDirectory);
                }

                foreach (var dir in options.InputDirs)
                {
                    if (!Directory.Exists(dir))
                    {
                        message.AppendLine(string.Format(Tr._("Input directory '{0}' not found"), dir));
                        return(false);
                    }
                }
            }
            catch (Exception e)
            {
                message.Append(e.Message);
                return(false);
            }

            return(true);
        }
Example #3
0
 public void Save()
 {
     if (Options.Backup && File.Exists(Options.OutputFile))
     {
         var bakFileName = Options.OutputFile + ".bak";
         File.Copy(Options.OutputFile, bakFileName, true);
         File.Delete(Options.OutputFile);
         Log(Tr._("Created backup file '{0}'."), bakFileName);
     }
     Catalog.Save(Options.OutputFile);
     Log(Tr._("Exported messages to '{0}'."), Options.OutputFile);
 }
Example #4
0
        public static string GetErrorMessage(SessionError error, ServerErrorId?serverErrorId = null)
        {
            switch (error)
            {
            case SessionError.InternalError: return(Tr._("Internal error occured"));

            case SessionError.ConnectionError: return(Tr._("Connection lost"));

            case SessionError.ProtocolError: return(Tr._("Client protocol error"));

            case SessionError.ServerError:
                return(GetServerErrorMessage(serverErrorId));

            default: return(Tr._("Unknown error"));
            }
        }
Example #5
0
        private static string GetServerErrorMessage(ServerErrorId?serverErrorId)
        {
            switch (serverErrorId)
            {
            case ServerErrorId.InternalError: return(Tr._("Internal server error"));

            case ServerErrorId.ProtocolError: return(Tr._("Server protocol error"));

            case ServerErrorId.Incompatible: return(Tr._("Incompatible client version"));

            case ServerErrorId.ServerIsBusy: return(Tr._("Nickname is busy"));

            case ServerErrorId.NickIsBusy: return(Tr._("Nickname is busy"));

            case ServerErrorId.ConnectionError: return(Tr._("Server connection error"));

            default: return(Tr._("Unknown server error"));
            }
        }
Example #6
0
        private static string GetKeyboardSourceName(int layoutId)
        {
            var    baseName = Tr._("Keyboard");
            string layout;

            switch (layoutId)
            {
            case 0:
                layout = "W/S";
                break;

            case 1:
                layout = Tr._("Arrows");
                break;

            default: throw new IndexOutOfRangeException();
            }

            return($"{baseName} {layout}");
        }
Example #7
0
        private static int Main([NotNull] string[] args)
        {
#if DEBUG
            // Allow to attach debugger
            Console.ReadLine();
#endif // DEBUG
            if (args.Length == 0)
            {
                ShowUsage();
                return(-1);
            }

            if (!ParseOptions(args, out var options, out var message))
            {
                Console.WriteLine(message.ToString());
                return(-1);
            }

            if (options.ShowUsage)
            {
                ShowUsage();
                return(0);
            }

            if (!CheckOptions(options, out message))
            {
                Console.WriteLine(message.ToString());
                return(-1);
            }

            try
            {
                // Initialize translation
                TranslationManager.Instance.RegisterProvider(new GettextTranslationProvider());

                // Compute the list of input files
                ISet <UFile> inputFiles = new HashSet <UFile>();
                var          re         = options.Excludes.Count > 0 ? new Regex(string.Join("|", options.Excludes.Select(x => Regex.Escape(x).Replace(@"\*", @".*")))) : null;
                foreach (var path in options.InputDirs)
                {
                    foreach (var searchPattern in options.InputFiles)
                    {
                        var files = Directory.EnumerateFiles(path, searchPattern, options.Recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
                                    .Where(f => !re?.IsMatch(f) ?? true);
                        foreach (var fileName in files)
                        {
                            inputFiles.Add(new UFile(fileName));
                        }
                    }
                }
                // Extract all messages from the input files
                var messages = new List <Message>();
                messages.AddRange(new CSharpExtractor(inputFiles).ExtractMessages());
                messages.AddRange(new XamlExtractor(inputFiles).ExtractMessages());
                if (options.Verbose)
                {
                    Console.WriteLine(Tr._n("Found {0} message.", "Found {0} messages.", messages.Count), messages.Count);
                }
                // Export/merge messages
                var exporter = new POExporter(options);
                exporter.Merge(messages);
                exporter.Save();
            }
            catch (Exception ex)
            {
                Console.WriteLine(Tr._("Error during execution: {0}"), ex.Message);
                return(1);
            }

            return(0);
        }
Example #8
0
        private static bool ParseOptions([NotNull] string[] args, [NotNull] out Options options, [NotNull] out StringBuilder message)
        {
            options = new Options();
            message = new StringBuilder();

            try
            {
                var getopt = new Getopt(Assembly.GetExecutingAssembly().GetName().Name, args, SOpts, LOpts)
                {
                    Opterr = false
                };
                int option;
                while ((option = getopt.getopt()) != -1)
                {
                    switch (option)
                    {
                    case 1:
                        options.InputFiles.Add(getopt.Optarg);
                        break;

                    case 'D':
                        options.InputDirs.Add(getopt.Optarg);
                        break;

                    case 'r':
                        options.Recursive = true;
                        break;

                    case 'x':
                        options.Excludes.Add(getopt.Optarg);
                        break;

                    case 'd':
                        options.OutputFile = $"{getopt.Optarg}.pot";
                        break;

                    case 'b':
                        options.Backup = true;
                        break;

                    case 'o':
                        options.OutputFile = getopt.Optarg;
                        break;

                    case 'm':
                        options.Overwrite = false;
                        break;

                    case 'C':
                        options.PreserveComments = true;
                        break;

                    case 'v':
                        options.Verbose = true;
                        break;

                    case 'h':
                        options.ShowUsage = true;
                        return(true);

                    case ':':
                        message.AppendLine(string.Format(Tr._("Option '{0}' requires an argument"), getopt.OptoptStr));
                        return(false);

                    case '?':
                        message.AppendLine(string.Format(Tr._("Invalid option '{0}'"), getopt.OptoptStr));
                        return(false);

                    default:
                        ShowUsage();
                        return(false);
                    }
                }

                if (getopt.Opterr)
                {
                    message.AppendLine();
                    message.Append(Tr._("Error in the command line options. Use -h to display the options usage."));
                    return(false);
                }
            }
            catch (Exception e)
            {
                message.Append(e.Message);
                return(false);
            }

            return(true);
        }
Example #9
0
 public MessageBox CreateErrorBox(bool visible, string message)
 {
     return(CreateMessageBox(visible, Tr._("Error"), message, Tr._("OK")));
 }
Example #10
0
 public MessageBox CreateInfoBox(bool visible, string message)
 {
     return(CreateMessageBox(visible, Tr._("Information"), message, Tr._("OK")));
 }
Example #11
0
 public void SetJoinedState(bool joined)
 {
     _message.text = joined ? Tr._("Waiting for other player...") : Tr._("Connecting to server...");
 }