diff options
author | Patryk Obara <dreamer.tan@gmail.com> | 2020-12-13 19:00:19 +0300 |
---|---|---|
committer | Patryk Obara <dreamer.tan@gmail.com> | 2020-12-13 23:23:34 +0300 |
commit | 2d020a2f7c06037fc1e4259ba3fc2d05d1614d39 (patch) | |
tree | bedd1283e8359ef5709b89f81d23a72e3bcef591 | |
parent | fb3254ba04019f4ab66964e04f20d27f54af7642 (diff) |
WIP Initial integration of gettextpo/gettext-migration-1
- Convert few messages to new API
- Create template file (dosbox.pot)
- Create tiny translation file for polish (pl/dosbox.po)
- To test: compile dosbox.mo (using e.g. poedit), and place it in
./pl/LC_MESSAGES/dosbox.mo
then run:
LANGUAGE=pl ./src/dosbox
- TODO: gettext converts to US-ASCII (removes diacritics) (good!),
but dos can't show them - synchronize gettext conversion
with used codepage (e.g. 'keyb pl` loads codapage 852, so
so when recompiled with CP852 instead of US-ASCII, the polish
letters are perfect) - make it switch in runtime
-rw-r--r-- | include/dosbox.h | 14 | ||||
-rw-r--r-- | po/dosbox.pot | 28 | ||||
-rw-r--r-- | po/pl/dosbox.po | 29 | ||||
-rw-r--r-- | po/sources.txt | 1 | ||||
-rwxr-xr-x | scripts/extract-text.sh | 18 | ||||
-rw-r--r-- | src/gui/sdlmain.cpp | 15 | ||||
-rw-r--r-- | src/shell/shell.cpp | 3 | ||||
-rw-r--r-- | src/shell/shell_cmds.cpp | 5 |
8 files changed, 106 insertions, 7 deletions
diff --git a/include/dosbox.h b/include/dosbox.h index b3baa7c47..8f7ed50c2 100644 --- a/include/dosbox.h +++ b/include/dosbox.h @@ -23,11 +23,21 @@ #include "compiler.h" #include "types.h" +#include <libintl.h> +#include <locale.h> + [[noreturn]] void E_Exit(const char *message, ...) GCC_ATTRIBUTE(__format__(__printf__, 1, 2)); -void MSG_Add(const char*,const char*); //add messages to the internal languagefile -const char* MSG_Get(char const *); //get messages from the internal languagefile +#define _(STRING) gettext(STRING) + +// Add message to the internal languagefile +// DEPRECATED - use gettext instead +void MSG_Add(const char *, const char *); + +// Get messages from the internal languagefile +// DEPRECATED - use gettext instead +const char *MSG_Get(char const *); class Section; diff --git a/po/dosbox.pot b/po/dosbox.pot new file mode 100644 index 000000000..6b0a149de --- /dev/null +++ b/po/dosbox.pot @@ -0,0 +1,28 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the dosbox-staging package. +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: dosbox-staging\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-12-13 18:19+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" +"Language-Team: LANGUAGE <LL@li.org>\n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: src/shell/shell_cmds.cpp:839 +#, c-format +msgid "ls: cannot access '%s': No such file or directory\n" +msgstr "" + +#. l10n This message must not end in a newline +#: src/shell/shell_cmds.cpp:1312 +msgid "Press any key to continue..." +msgstr "" diff --git a/po/pl/dosbox.po b/po/pl/dosbox.po new file mode 100644 index 000000000..f56673455 --- /dev/null +++ b/po/pl/dosbox.po @@ -0,0 +1,29 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the dosbox-staging package. +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: dosbox-staging\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-12-13 18:19+0100\n" +"PO-Revision-Date: 2020-12-13 20:17+0100\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 2.4.2\n" +"Last-Translator: Patryk Obara <dreamer.tan@gmail.com>\n" +"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<12 || n%100>14) ? 1 : 2);\n" +"Language: pl\n" + +#: src/shell/shell_cmds.cpp:839 +#, c-format +msgid "ls: cannot access '%s': No such file or directory\n" +msgstr "ls: nie ma dostępu do '%s': Nie ma takiego pliku ani katalogu\n" + +#. l10n This message must not end in a newline +#: src/shell/shell_cmds.cpp:1312 +msgid "Press any key to continue..." +msgstr "Naciśnij dowolny klawisz, aby kontynuować..." diff --git a/po/sources.txt b/po/sources.txt new file mode 100644 index 000000000..4b4e4e39a --- /dev/null +++ b/po/sources.txt @@ -0,0 +1 @@ +src/shell/shell_cmds.cpp diff --git a/scripts/extract-text.sh b/scripts/extract-text.sh new file mode 100755 index 000000000..19050fd34 --- /dev/null +++ b/scripts/extract-text.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# SPDX-License-Identifier: GPL-2.0-or-later + +# Copyright (C) 2020 Patryk Obara <patryk.obara@gmail.com> + +# This script exists only to easily generate/update gettext translation +# template file (dosbox.pot). + +cd "$(git rev-parse --show-toplevel)" + +xgettext \ + --verbose \ + --keyword=_ \ + --add-comments=l10n \ + --package-name=dosbox-staging \ + --files-from=po/sources.txt \ + -o po/dosbox.pot diff --git a/src/gui/sdlmain.cpp b/src/gui/sdlmain.cpp index 528ff5473..e1c6f5c17 100644 --- a/src/gui/sdlmain.cpp +++ b/src/gui/sdlmain.cpp @@ -3203,6 +3203,20 @@ void OverrideWMClass() #endif } +void setup_i18n_env() +{ + setlocale(LC_ALL, ""); + // PWD -> ./pl/LC_MESSAGES/dosbox.mo + bindtextdomain("dosbox", getenv("PWD")); + textdomain("dosbox"); + + //const char *pl_code = "CP852"; // to test: `keyb pl` + const char *default_code = "US-ASCII"; + //const char *code = bind_textdomain_codeset("dosbox", pl_code); + const char *code = bind_textdomain_codeset("dosbox", default_code); + DEBUG_LOG_MSG("gettext encoding: %s", code); +} + //extern void UI_Init(void); int main(int argc, char* argv[]) { int rcode = 0; // assume good until proven otherwise @@ -3211,6 +3225,7 @@ int main(int argc, char* argv[]) { OverrideWMClass(); // Before SDL2 video subsystem is initialized CROSS_DetermineConfigPaths(); + setup_i18n_env(); CommandLine com_line(argc,argv); Config myconf(&com_line); diff --git a/src/shell/shell.cpp b/src/shell/shell.cpp index 1da6b3aa3..b922d1904 100644 --- a/src/shell/shell.cpp +++ b/src/shell/shell.cpp @@ -612,7 +612,6 @@ void SHELL_Init() { MSG_Add("SHELL_CMD_DIR_BYTES_FREE","%17d dir(s) %21s bytes free\n"); MSG_Add("SHELL_EXECUTE_DRIVE_NOT_FOUND","Drive %c does not exist!\nYou must \033[31mmount\033[0m it first. Type \033[1;33mintro\033[0m or \033[1;33mintro mount\033[0m for more information.\n"); MSG_Add("SHELL_EXECUTE_ILLEGAL_COMMAND","Illegal command: %s.\n"); - MSG_Add("SHELL_CMD_PAUSE","Press any key to continue..."); MSG_Add("SHELL_CMD_PAUSE_HELP","Waits for 1 keystroke to continue.\n"); MSG_Add("SHELL_CMD_COPY_FAILURE","Copy failure : %s.\n"); MSG_Add("SHELL_CMD_COPY_SUCCESS"," %d File(s) copied.\n"); @@ -713,8 +712,6 @@ void SHELL_Init() { MSG_Add("SHELL_CMD_LS_HELP", "List directory contents.\n"); MSG_Add("SHELL_CMD_LS_HELP_LONG", "ls [/?] [PATTERN]\n"); - MSG_Add("SHELL_CMD_LS_PATH_ERR", - "ls: cannot access '%s': No such file or directory\n"); MSG_Add("SHELL_CMD_CHOICE_HELP","Waits for a keypress and sets ERRORLEVEL.\n"); MSG_Add("SHELL_CMD_CHOICE_HELP_LONG","CHOICE [/C:choices] [/N] [/S] text\n" diff --git a/src/shell/shell_cmds.cpp b/src/shell/shell_cmds.cpp index 3258b0a8c..6a86a0548 100644 --- a/src/shell/shell_cmds.cpp +++ b/src/shell/shell_cmds.cpp @@ -836,7 +836,7 @@ void DOS_Shell::CMD_LS(char *args) const std::string pattern = to_search_pattern(args); if (!DOS_FindFirst(pattern.c_str(), 0xffff & ~DOS_ATTR_VOLUME)) { - WriteOut(MSG_Get("SHELL_CMD_LS_PATH_ERR"), trim(args)); + WriteOut(_("ls: cannot access '%s': No such file or directory\n"), trim(args)); dos.dta(original_dta); return; } @@ -1308,7 +1308,8 @@ void DOS_Shell::CMD_REM(char * args) { void DOS_Shell::CMD_PAUSE(char *args) { HELP("PAUSE"); - WriteOut(MSG_Get("SHELL_CMD_PAUSE")); + // l10n This message must not end in a newline + WriteOut(_("Press any key to continue...")); uint8_t c; uint16_t n = 1; DOS_ReadFile(STDIN, &c, &n); |