Browse Source

Added context support to gettext commands

master
Artyom Beilis 8 years ago
parent
commit
849b479b75
3 changed files with 38 additions and 8 deletions
  1. +8
    -8
      bin/cppcms_tmpl_cc
  2. +11
    -0
      tests/tc_skin.tmpl
  3. +19
    -0
      tests/tc_test.cpp

+ 8
- 8
bin/cppcms_tmpl_cc View File

@@ -828,17 +828,17 @@ class trigger_block:


class ngettext_block:
pattern=r'^<%\s*ngt\s*('+str_match+')\s*,\s*('+str_match+')\s*,\s*('+variable_match+')\s*(using(.*))?\s*%>$'
pattern=r'^<%\s*ngt\s*((?:' + str_match + '\s*,\s*)?'+str_match+')\s*,\s*('+str_match+')\s*,\s*('+variable_match+')\s*(using(.*))?\s*%>$'
basic_pattern = 'ngt'
basic_name = 'ngt'
def use(self,m):
global output_template
s1=m.group(1)
s2=m.group(3)
idt=make_ident(m.group(5))
s2=m.group(4)
idt=make_ident(m.group(6))
params=[]
if m.group(11):
params=make_format_params(m.group(12))
if m.group(12):
params=make_format_params(m.group(13))
if not params:
output_template( "out()<<cppcms::locale::translate(%s,%s,%s);" % (s1,s2,idt))
else:
@@ -846,15 +846,15 @@ class ngettext_block:

class gettext_block:
pattern=r'^<%\s*gt\s*('+str_match+')\s*(using(.*))?\s*%>$'
pattern=r'^<%\s*gt\s*((?:' + str_match + '\s*,\s*)?' +str_match+')\s*(using(.*))?\s*%>$'
basic_pattern = 'gt'
basic_name = 'gt'
def use(self,m):
global output_template
s=m.group(1)
params=[]
if m.group(3):
params=make_format_params(m.group(4))
if m.group(4):
params=make_format_params(m.group(5))
if not params:
output_template( "out()<<cppcms::locale::translate(%s);" % s)
else:


+ 11
- 0
tests/tc_skin.tmpl View File

@@ -89,6 +89,17 @@ TBD
<% end %>
<% end view %>

<% view gt_text uses data::master %>
<% template render() %>
<% gt "No text" %>
<% gt "It is text: {1}" using text %>
<% gt "Context", "No text" %>
<% gt "Context", "It is text: {1}" using text %>
<% ngt "I have 1 file in {2}", "I have {1} files in {2}", integer using integer, text %>
<% ngt "Context","I have 1 file in {2}", "I have {1} files in {2}", integer using integer, text %>
<% end template %>
<% end view %>

<% view master_block_filter uses data::master %>
<% template render () %>
<%= text %>|<% gt "{1}" using text %>|<% url "/" using text %>


+ 19
- 0
tests/tc_test.cpp View File

@@ -329,6 +329,24 @@ public:

}
void test_gettext()
{
std::cout << "- Gettext" << std::endl;
data::master m;
m.integer = 5;
m.text = "Hello";
render("gt_text",m);
compare_strings(str(),
"\n" // <% template render() %>
"No text\n" // <% gt "No text" %>
"It is text: Hello\n" // <% gt "It is text: {1}" using text %>
"No text\n" // <% gt "Context", "No text" %>
"It is text: Hello\n" // <% gt "Context", "It is text: {1}" using text %>
"I have 5 files in Hello\n" // <% ngt "I have 1 file in {2}", "I have {1} files in 2" using number, text %>
"I have 5 files in Hello\n" // <% ngt "Context","I have 1 file in {2}", "I have {1} files in 2" using number, text %>
"" // <% end template %>
);
}
void test_format()
{
std::cout << "- Testing formatting" << std::endl;
@@ -513,6 +531,7 @@ int main(int argc,char **argv)
app.test_block_filter();
app.test_cache();
app.test_using_render();
app.test_gettext();
}
catch(std::exception const &e)
{


Loading…
Cancel
Save