commit a1aa2b98068b6a0815df19836c3fe6f7d5eefb7f Author: Ahmed Siam Date: Sat Jun 17 12:13:35 2023 +0300 move test and make icuformat take data path argument diff --git a/locales/root.txt b/locales/root.txt index 727f17e..c683cf6 100644 --- a/locales/root.txt +++ b/locales/root.txt @@ -1,5 +1,2 @@ root:table { - hello_message:string { "Hello World" } - test_message:string { "Message for test" } - complex_message:string { "Hello {0}, you are in {1}!" } } diff --git a/src/Makefile.am b/src/Makefile.am index cee526f..d420f28 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,4 @@ -bin_PROGRAMS = icuformat test +bin_PROGRAMS = icuformat icuformat_SOURCES = icuformat.cpp i18n.cpp -test_SOURCES = test.cpp i18n.cpp AM_CPPFLAGS = -DLOCALES_DATA='"$(LOCALES_DATA)"' diff --git a/src/icuformat.cpp b/src/icuformat.cpp index 0ad6c4d..886b90e 100644 --- a/src/icuformat.cpp +++ b/src/icuformat.cpp @@ -4,18 +4,18 @@ int main(int argc, char* argv[]) { - if (argc < 2) { - std::cout << "USAGE: icuformat \n"; + if (argc < 3) { + std::cout << "USAGE: icuformat \n"; return 0; } - I18n i18n {LOCALES_DATA}; + I18n i18n {argv[1]}; std::vector arguments; - for (int i = 2; i < argc; i++) { + for (int i = 3; i < argc; i++) { arguments.push_back(argv[i]); } - std::cout << i18n.format(argv[1], arguments) << std::endl; + std::cout << i18n.format(argv[2], arguments) << std::endl; return 0; -} \ No newline at end of file +} diff --git a/src/test.cpp b/src/test.cpp deleted file mode 100644 index 7ddd4bb..0000000 --- a/src/test.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include "i18n.h" - - -int main() { - I18n i18n {LOCALES_DATA}; - - std::cout << i18n.format("test_message") << std::endl; - std::cout << i18n.format("complex_message", {"Ahmed", "Egypt"}) << std::endl; - return 0; -} \ No newline at end of file diff --git a/tests/locales/en.txt b/tests/locales/en.txt new file mode 100644 index 0000000..711a2ea --- /dev/null +++ b/tests/locales/en.txt @@ -0,0 +1,2 @@ +en:table { +} \ No newline at end of file diff --git a/tests/locales/package_list.txt b/tests/locales/package_list.txt new file mode 100644 index 0000000..d5134dd --- /dev/null +++ b/tests/locales/package_list.txt @@ -0,0 +1 @@ +root.res en.res diff --git a/tests/locales/root.txt b/tests/locales/root.txt new file mode 100644 index 0000000..6114b7d --- /dev/null +++ b/tests/locales/root.txt @@ -0,0 +1,4 @@ +root:table { + simple_message:string { "Hello World" } + complex_message:string { "Hello {0}, you are {1} years old!" } +} diff --git a/tests/test.sh b/tests/test.sh new file mode 100644 index 0000000..bcf57a3 --- /dev/null +++ b/tests/test.sh @@ -0,0 +1,12 @@ +#! /usr/bin/env bash + +cd $(dirname $0)/locales + +genrb -d . root.txt en.txt +echo root.res en.res > package_list.txt +pkgdata -p locales --mode archive -d . package_list.txt + +icuformat="./../../src/icuformat" + +$icuformat locales.dat simple_message +$icuformat locales.dat complex_message Ahmed 19