QtLingo 1
QtLingo is an Application to make Qt Computer Translations easier
visitors::string_extractor_replacer Struct Reference

string extractor replacer. More...

#include <ts_model.h>

Public Member Functions

 string_extractor_replacer (map_hashQString &vqs, bool with_unfinished, bool with_vanished, bool unfinished_only)
 
void visit (const document_node *node)
 visit(const document_node *node). visit More...
 
void visit (const DTD_node *node)
 visit(const DTD_node *). visit More...
 
void visit (element_node *node)
 visit(element_node *node). visit More...
 

Detailed Description

string extractor replacer.

Definition at line 59 of file ts_model.h.

Constructor & Destructor Documentation

◆ string_extractor_replacer()

visitors::string_extractor_replacer::string_extractor_replacer ( map_hashQString vqs,
bool  with_unfinished,
bool  with_vanished,
bool  unfinished_only 
)
inline

Definition at line 61 of file ts_model.h.

62 : m_vqs(vqs), source(nullptr), translation(nullptr), m_state(st_WaitForMessage), m_with_unfinished(with_unfinished), m_with_vanished(with_vanished), m_unfinished_only(unfinished_only)
63 {}

Member Function Documentation

◆ visit() [1/3]

void string_extractor_replacer::visit ( const document_node node)

visit(const document_node *node). visit

Definition at line 43 of file ts_model.cpp.

44 {
45 std::for_each(node->m_childs.begin(), node->m_childs.end(), [this](const base_node::base_node_ptr node){ node->visit(*this); } );
46 }
std::shared_ptr< base_node > base_node_ptr
Definition: ts_model.h:116

◆ visit() [2/3]

void string_extractor_replacer::visit ( const DTD_node node)

visit(const DTD_node *). visit

Definition at line 51 of file ts_model.cpp.

51{ }

◆ visit() [3/3]

void string_extractor_replacer::visit ( element_node node)

visit(element_node *node). visit

Definition at line 56 of file ts_model.cpp.

57 {
58 if(st_WaitForMessage == m_state && element_node::ent_message == node->element_node_type())
59 {
60 m_state = st_WaitForSource | st_WaitForTranslation;
61 }
62 else if(st_WaitForSource & m_state && element_node::ent_source == node->element_node_type())
63 {
64 assert(!source);
65 source = node;
66 m_state &= ~st_WaitForSource;
67
68 if(!(m_state & st_WaitForTranslation))
69 {
70 m_state |= st_Complete;
71 }
72 else
73 {
74 return;
75 }
76 }
77 else if(st_WaitForTranslation & m_state && element_node::ent_translation == node->element_node_type())
78 {
79 assert(!translation);
80 translation = node;
81 m_state &= ~st_WaitForTranslation;
82
83 if(!(m_state & st_WaitForSource))
84 {
85 m_state |= st_Complete;
86 }
87 else
88 {
89 return;
90 }
91 }
92
93 if(st_Complete & m_state)
94 {
95 bool bSkipProcessing = false;
96
97 if(!m_with_unfinished || !m_with_vanished || !m_unfinished_only)
98 {
99 QString attr_type = translation->attributes().value("type").toString();
100 if(m_unfinished_only)
101 {
102 bSkipProcessing = "unfinished" != attr_type;
103 }
104 else
105 {
106 bSkipProcessing = ("unfinished" == attr_type && !m_with_unfinished)
107 || (("vanished" == attr_type || "obsolete" == attr_type) && !m_with_vanished);
108 }
109 }
110
111 if(!bSkipProcessing)
112 {
113 hash_t hash = 0;
114 QString text;
115
116 if(!translation->text().isEmpty())
117 {
118 text = translation->text();
119 }
120 else
121 {
122 text = source->text();
123 }
124
125 hash = efl_hash(text.toStdWString().c_str());
126 translation->set_text(QString("[[[%1]]]").arg(hash, 8, 16, QChar('0')).toUpper());
127 text = QString("%1 \"%2\"").arg(translation->text(), text);
128
129 text.replace("\n", "\\n");
130 text.replace("\r", "\\r");
131 text.replace("\t", "\\t");
132
133 m_vqs.insert(map_hashQString::value_type(hash, text));
134 }
135
136 source = translation = nullptr;
137 m_state = st_WaitForMessage;
138 }
139
140 std::for_each(node->m_childs.begin(), node->m_childs.end(), [this](const base_node::base_node_ptr node) { node->visit(*this); });
141 }
unsigned long hash_t
type of efl_hash.
Definition: efl_hash.h:7
hash_t efl_hash(const wchar_t *s)
do some fancy bitwanking on the string. efl_hash
Definition: efl_hash.h:12
const QString & text() const
Definition: ts_model.h:186
EElementNodeType element_node_type() const
Definition: ts_model.h:183
void set_text(const QString &text)
Definition: ts_model.h:185
const QXmlStreamAttributes & attributes() const
Definition: ts_model.h:189
@ ent_translation
Definition: ts_model.h:173

The documentation for this struct was generated from the following files: