From 91d596159722b3d31b033e7dc1af24f4412db215 Mon Sep 17 00:00:00 2001 From: Artyom Beilis Date: Mon, 18 Jan 2016 21:49:40 +0000 Subject: [PATCH] Added domain test to views testing --- CMakeLists.txt | 4 ++-- bin/cppcms_tmpl_cc | 1 + tests/en/LC_MESSAGES/main.mo | Bin 0 -> 321 bytes tests/en/LC_MESSAGES/main.po | 16 ++++++++++++++ tests/en/LC_MESSAGES/plugin2.mo | Bin 0 -> 323 bytes tests/en/LC_MESSAGES/plugin2.po | 16 ++++++++++++++ tests/tc_plugin2.tmpl | 4 ++-- tests/tc_skin.tmpl | 2 +- tests/tc_test.cpp | 36 +++++++++++++++++++++++++++++--- 9 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 tests/en/LC_MESSAGES/main.mo create mode 100644 tests/en/LC_MESSAGES/main.po create mode 100644 tests/en/LC_MESSAGES/plugin2.mo create mode 100644 tests/en/LC_MESSAGES/plugin2.po diff --git a/CMakeLists.txt b/CMakeLists.txt index 49a6b6c0..d1cc5cd2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -856,8 +856,8 @@ add_test(copy_filter_test copy_filter_test) add_test(mount_point_test mount_point_test) add_test(file_buffer_test file_buffer_test) if(NOT DISABLE_SHARED) - add_test(tc_test_shared tc_test "--shared") - add_test(tc_test_separate tc_test "--separate") + add_test(tc_test_shared tc_test "--shared" "${CNF}") + add_test(tc_test_separate tc_test "--separate" "${CNF}") add_test(plugin_test plugin_test "${CMAKE_CURRENT_BINARY_DIR}") endif() diff --git a/bin/cppcms_tmpl_cc b/bin/cppcms_tmpl_cc index 3aba6a1a..d3bf3b65 100755 --- a/bin/cppcms_tmpl_cc +++ b/bin/cppcms_tmpl_cc @@ -142,6 +142,7 @@ class view_block: self.gettext_domain = spec_gettext; output_declaration( '\t\t_domain_id=cppcms::translation_domain_scope::domain_id(_s,"%s");' % self.gettext_domain) else: + output_declaration( '\t\t_domain_id=booster::locale::ios_info::get(_s).domain_id();') self.gettext_domain = None; output_declaration("\t}") diff --git a/tests/en/LC_MESSAGES/main.mo b/tests/en/LC_MESSAGES/main.mo new file mode 100644 index 0000000000000000000000000000000000000000..eb624658877900b7d60b3c7e645567a05e2351a2 GIT binary patch literal 321 zcmYMv!Ait15C-5VdI?_EvxnSu+@yk()FQal1xD##P{+Ed={rG z?Ed6~gv<=d@9EJuqa2bmazT#C4H;9D6Y@-c$QzlE=>cQ3b{YG(!DxKy3|g_V?8WvW zB2>w>E4Uk6f+lFe>!${0(Hd-nhkL5kB9rPGqym+T>`E(nE;A|lqw#Jqj_!H&P|e}h z#zZ|@s7uLb!K3vE%~wwaXg_hY@HFI(FPbH5C$);lfo_ZE5G m4bgP42yv6N@cs6f%B&Fo+tQb%x|LcLoK-YmG`lZWmi++|rBUJl literal 0 HcmV?d00001 diff --git a/tests/en/LC_MESSAGES/main.po b/tests/en/LC_MESSAGES/main.po new file mode 100644 index 00000000..2ea88276 --- /dev/null +++ b/tests/en/LC_MESSAGES/main.po @@ -0,0 +1,16 @@ +# Copyright (C) 2016 Artyom Beilis +# This file is distributed under the same license as the CppCMS package. +# +msgid "" +msgstr "" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-01-18 23:10+0200\n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=n==1?0:1;\n" + +msgid "translate me" +msgstr "Main Translate Me" + diff --git a/tests/en/LC_MESSAGES/plugin2.mo b/tests/en/LC_MESSAGES/plugin2.mo new file mode 100644 index 0000000000000000000000000000000000000000..e6248744f34bdad089358200eeb6636704650622 GIT binary patch literal 323 zcmYMv!Ab)$5C-5VdI_HN>LGU>o2(#9)Q6pM$Ul($93Ol!%04+I=j4!FlTBK3M4reuc_k-gvd0*$T{iRE zW@wW0OSm0ff-Y#m+s6*3(VFZ7!X0(BD5SaqsX&#YxYSCX$wEs0V9<@m(LHbOn;E>= zm}o`|bs_mQV78c{`y8l{?MI#rz42Iy#k+~g=6cL4DF1t#m#u7s87{)oqtl{%^O?8( m7)=lJ5Z6fy9Ja?)7nS(i)>zl-Mru`YMqTGobh}SBmi+>~w^Ggk literal 0 HcmV?d00001 diff --git a/tests/en/LC_MESSAGES/plugin2.po b/tests/en/LC_MESSAGES/plugin2.po new file mode 100644 index 00000000..f6121a2c --- /dev/null +++ b/tests/en/LC_MESSAGES/plugin2.po @@ -0,0 +1,16 @@ +# Copyright (C) 2016 Artyom Beilis +# This file is distributed under the same license as the CppCMS package. +# +msgid "" +msgstr "" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-01-18 23:10+0200\n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=n==1?0:1;\n" + +msgid "translate me" +msgstr "Plugin Translate Me" + diff --git a/tests/tc_plugin2.tmpl b/tests/tc_plugin2.tmpl index efe17635..a521334f 100644 --- a/tests/tc_plugin2.tmpl +++ b/tests/tc_plugin2.tmpl @@ -1,11 +1,11 @@ <% c++ #include "tc_sep_skin.h" %> -<% domain plugin %> +<% domain plugin2 %> <% skin plugin2 %> <% view master_plugin uses data::master extends tc_skin::master_api2 %> <% template call() %>Plugin2: <% include f1() %><% end %> <% end view %> -<% view msg uses data::helper extends tc_skin::message_base %> +<% view msg uses data::master extends tc_skin::message_base %> <% template render() %><% include f1() %>; <% gt "translate me" %>; <% include f1() %><% end %> <% end view %> diff --git a/tests/tc_skin.tmpl b/tests/tc_skin.tmpl index 16acb5ed..00ac100b 100644 --- a/tests/tc_skin.tmpl +++ b/tests/tc_skin.tmpl @@ -241,7 +241,7 @@ TBD <% template h1() %>skin::helper_plugin::h1 <%= x %><% end %> <% end view %> -<% view message_base uses data::helper %> +<% view message_base uses data::master %> <% template f1() %><% gt "translate me" %><% end %> <% template render() %><% include f1() %><% end %> <% end view %> diff --git a/tests/tc_test.cpp b/tests/tc_test.cpp index f3612b5d..f9c6d44c 100644 --- a/tests/tc_test.cpp +++ b/tests/tc_test.cpp @@ -512,6 +512,29 @@ class test_app : public cppcms::application { "plugin::helper_plugin::h1 13\n" //from skin1,name1 include h1() ""); } + void test_domain() + { + std::cout <<"- Testing gettext domains" << std::endl; + response().out() << booster::locale::translate("translate me")<<";"; + { + cppcms::translation_domain_scope scope(response().out(),"plugin2"); + response().out() << booster::locale::translate("translate me")<<";"; + } + response().out() << booster::locale::translate("translate me")<<";"; + compare_strings(str(),"Main Translate Me;Plugin Translate Me;Main Translate Me;"); + + data::master c; + std::cout <<"-- main" << std::endl; + render("message_base",c); + compare_strings(str(),"Main Translate Me"); + std::cout <<"-- plugin" << std::endl; + render("plugin2","msg",c); + compare_strings(str(),"Main Translate Me; Plugin Translate Me; Main Translate Me"); + std::cout <<"-- undefined main" << std::endl; + response().out() << booster::locale::as::domain("plugin2"); + render("plugin2","msg",c); + compare_strings(str(),"Plugin Translate Me; Plugin Translate Me; Plugin Translate Me"); + } private: @@ -523,14 +546,19 @@ class test_app : public cppcms::application { int main(int argc,char **argv) { std::string type; - if(argc!=2 || ((type=argv[1])!="--separate" && type!="--shared")) { - std::cerr << "Usage (--separate|--shared)" << std::endl; + if(argc!=3 || ((type=argv[1])!="--separate" && type!="--shared")) { + std::cerr << "Usage (--separate|--shared) /path/to/tests/dir" << std::endl; return 1; } bool separate = type == "--separate"; try { cppcms::json::value cfg; cfg["views"]["paths"][0]="./"; + cfg["localization"]["locales"][0]="en_US.UTF-8"; + cfg["localization"]["messages"]["paths"][0]=std::string(argv[2]); + cfg["localization"]["messages"]["domains"][0]="main"; + cfg["localization"]["messages"]["domains"][1]="plugin2"; + if(separate) { std::cout << "Using separate header/body" << std::endl; cfg["views"]["skins"][0]="tc_sep_skin_a"; @@ -567,8 +595,10 @@ int main(int argc,char **argv) app.test_cache(); app.test_using_render(); app.test_gettext(); - if(separate) + if(separate) { app.test_using_from(); + app.test_domain(); + } } catch(std::exception const &e) {