commit 531e5403bf7b2eb40f216d909ed2a1b36cbe2c06 Author: Ahmed Siam Date: Mon Aug 21 06:58:27 2023 +0300 i18n patch 1 diff --git a/.gitignore b/.gitignore index d038cb6..a5b15a0 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,10 @@ config.log config.status .deps *.o + +/.vscode/ +/locales/Makefile +/locales/Makefile.in +*.res +*.dat +/configure~ diff --git a/Makefile.am b/Makefile.am index b3e66c6..90a3f69 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,9 +1,13 @@ pkgconfigdir = $(libdir)/pkgconfig dist_pkgconfig_DATA = apertium-anaphora.pc -SUBDIRS = src +SUBDIRS = src locales EXTRA_DIST=autogen.sh test: pushd $(abs_srcdir)/tests/ && bash test.sh $(abs_builddir)/src/apertium-anaphora && popd + +export LTTB_I18N_DATA=$(datadir)/lttoolbox/lttoolbox.dat +export LOCALES_DIR=$(datadir)/$(PACKAGE_NAME) +export APAN_I18N_DATA=$(LOCALES_DIR)/apan.dat diff --git a/README.md b/README.md deleted file mode 120000 index 100b938..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -README \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..da4b466 Binary files /dev/null and b/README.md differ diff --git a/configure.ac b/configure.ac index 16bc742..e6a4f82 100644 --- a/configure.ac +++ b/configure.ac @@ -23,6 +23,8 @@ PKG_CHECK_MODULES([ICU], [icu-i18n icu-io icu-uc]) AC_SUBST(ICU_CFLAGS) AC_SUBST(ICU_LIBS) +PKG_CHECK_MODULES(I18N, [i18n], CPPFLAGS="$CPPFLAGS $I18N_CFLAGS"; LIBS="$LIBS $I18N_LIBS") + AC_CHECK_HEADER([utf8cpp/utf8.h], [CPPFLAGS="-I/usr/include/utf8cpp/ $CPPFLAGS"], [ AC_CHECK_HEADER([utf8.h], [], [AC_MSG_ERROR([You don't have utfcpp installed.])]) ]) @@ -53,5 +55,6 @@ AC_CONFIG_FILES([ apertium-anaphora.pc Makefile src/Makefile + locales/Makefile ]) AC_OUTPUT diff --git a/locales/Makefile.am b/locales/Makefile.am new file mode 100644 index 0000000..1bbd224 --- /dev/null +++ b/locales/Makefile.am @@ -0,0 +1,7 @@ +apan.dat: root.txt en.txt + genrb -d . root.txt en.txt + echo root.res en.res > package_list.txt + pkgdata -p apan --mode archive -d . package_list.txt + +localesdir = $(LOCALES_DIR) +dist_locales_DATA = apan.dat diff --git a/locales/en.txt b/locales/en.txt new file mode 100644 index 0000000..0bd10e4 --- /dev/null +++ b/locales/en.txt @@ -0,0 +1,2 @@ +en{ +} \ No newline at end of file diff --git a/locales/package_list.txt b/locales/package_list.txt new file mode 100644 index 0000000..d5134dd --- /dev/null +++ b/locales/package_list.txt @@ -0,0 +1 @@ +root.res en.res diff --git a/locales/root.txt b/locales/root.txt new file mode 100644 index 0000000..3606a31 --- /dev/null +++ b/locales/root.txt @@ -0,0 +1,13 @@ +root{ + anaphora_desc{"USAGE: {program} arx_file [input [output]]\n" + " {program} -z arx_file [input [output]]\n" + " arx_file Anaphora Resolution rules file (apertium-xxx-yyy.xxx-yyy.arx)\n" + " -z null-flushing output on \\0\n" + " -h shows this message\n"} + + + APAN1000{"ERROR APAN1000: Unable to access \"{file_name}\"."} + APAN1001{"ERROR APAN1001: Document not parsed successfully."} + APAN1002{"ERROR APAN1002: Empty Document!"} + APAN1003{"ERROR APAN1003: Document of the wrong type! Root node should be ref."} +} diff --git a/src/Makefile.am b/src/Makefile.am index 6f047c8..7baf5e3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,6 @@ AM_LDFLAGS=$(LIBS) +AM_CPPFLAGS = -DAPAN_I18N_DATA='"$(APAN_I18N_DATA)"' -DLTTB_I18N_DATA='"$(LTTB_I18N_DATA)"' + bin_PROGRAMS = apertium-anaphora bin_SCRIPTS = apertium-validate-anaphora diff --git a/src/anaphora.cc b/src/anaphora.cc index 6c01b21..5666cb7 100644 --- a/src/anaphora.cc +++ b/src/anaphora.cc @@ -33,6 +33,8 @@ #include #include #include +#include +#include using namespace std; @@ -41,21 +43,14 @@ UFILE * open_output(string const &filename) UFILE *output = u_fopen(filename.c_str(), "w", NULL, NULL); if(!output) { - cerr << "Error: can't open output file '"; - cerr << filename.c_str() << "'." << endl; - exit(EXIT_FAILURE); + I18n(APAN_I18N_DATA, "apan").error("APAN1000", {"file"}, {filename.c_str()}, true); } return output; } void help_message(char *progname) { - cerr << "USAGE: " << basename(progname) << " arx_file [input [output]]" << endl; - cerr << " " << basename(progname) << " -z arx_file [input [output]]" << endl; - cerr << " arx_file Anaphora Resolution rules file (apertium-xxx-yyy.xxx-yyy.arx)" << endl; - cerr << " -z null-flushing output on \\0" << endl; - cerr << " -h shows this message" << endl; - + cerr << I18n(APAN_I18N_DATA, "apan").format("anaphora_desc", {"program"}, {basename(progname)}); exit(EXIT_FAILURE); } diff --git a/src/parse_arx.cc b/src/parse_arx.cc index 5636eda..cdb2675 100644 --- a/src/parse_arx.cc +++ b/src/parse_arx.cc @@ -22,6 +22,7 @@ #include #include #include +#include void print_tags(const vector& input) { @@ -186,7 +187,7 @@ int ParseArx::parseDoc(char *docname) if (curDoc == nullptr ) { - fprintf(stderr,"Document not parsed successfully. \n"); + I18n(APAN_I18N_DATA, "apan").error("APAN1001", {}, {}, false); return -1; } @@ -194,14 +195,14 @@ int ParseArx::parseDoc(char *docname) if (cur == NULL) { - fprintf(stderr,"Empty Document!\n"); + I18n(APAN_I18N_DATA, "apan").error("APAN1002", {}, {}, false); xmlFreeDoc(curDoc); return 1; } if (xmlStrcmp(cur->name, (const xmlChar *) "ref")) { - fprintf(stderr,"Document of the wrong type! Root node should be ref.\n"); + I18n(APAN_I18N_DATA, "apan").error("APAN1003", {}, {}, false); xmlFreeDoc(curDoc); return 2; }