aboutsummaryrefslogtreecommitdiff
path: root/core/io/translation_loader_po.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/io/translation_loader_po.cpp')
-rw-r--r--core/io/translation_loader_po.cpp125
1 files changed, 59 insertions, 66 deletions
diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp
index bee38e037..4da661e67 100644
--- a/core/io/translation_loader_po.cpp
+++ b/core/io/translation_loader_po.cpp
@@ -30,7 +30,6 @@
#include "os/file_access.h"
#include "translation.h"
-
RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const String &p_path) {
enum Status {
@@ -40,175 +39,169 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error, const S
STATUS_READING_STRING,
};
- Status status=STATUS_NONE;
+ Status status = STATUS_NONE;
String msg_id;
String msg_str;
String config;
if (r_error)
- *r_error=ERR_FILE_CORRUPT;
+ *r_error = ERR_FILE_CORRUPT;
- Ref<Translation> translation = Ref<Translation>( memnew( Translation ));
+ Ref<Translation> translation = Ref<Translation>(memnew(Translation));
int line = 1;
- while(true) {
+ while (true) {
String l = f->get_line();
if (f->eof_reached()) {
- if ( status == STATUS_READING_STRING) {
+ if (status == STATUS_READING_STRING) {
- if (msg_id!="")
- translation->add_message(msg_id,msg_str);
- else if (config=="")
- config=msg_str;
+ if (msg_id != "")
+ translation->add_message(msg_id, msg_str);
+ else if (config == "")
+ config = msg_str;
break;
- } else if ( status==STATUS_NONE)
+ } else if (status == STATUS_NONE)
break;
memdelete(f);
- ERR_EXPLAIN(p_path+":"+itos(line)+" Unexpected EOF while reading 'msgid' at file: ");
+ ERR_EXPLAIN(p_path + ":" + itos(line) + " Unexpected EOF while reading 'msgid' at file: ");
ERR_FAIL_V(RES());
}
- l=l.strip_edges();
+ l = l.strip_edges();
if (l.begins_with("msgid")) {
- if (status==STATUS_READING_ID) {
+ if (status == STATUS_READING_ID) {
memdelete(f);
- ERR_EXPLAIN(p_path+":"+itos(line)+" Unexpected 'msgid', was expecting 'msgstr' while parsing: ");
+ ERR_EXPLAIN(p_path + ":" + itos(line) + " Unexpected 'msgid', was expecting 'msgstr' while parsing: ");
ERR_FAIL_V(RES());
}
- if (msg_id!="")
- translation->add_message(msg_id,msg_str);
- else if (config=="")
- config=msg_str;
+ if (msg_id != "")
+ translation->add_message(msg_id, msg_str);
+ else if (config == "")
+ config = msg_str;
- l=l.substr(5,l.length()).strip_edges();
- status=STATUS_READING_ID;
- msg_id="";
- msg_str="";
+ l = l.substr(5, l.length()).strip_edges();
+ status = STATUS_READING_ID;
+ msg_id = "";
+ msg_str = "";
}
if (l.begins_with("msgstr")) {
- if (status!=STATUS_READING_ID) {
+ if (status != STATUS_READING_ID) {
memdelete(f);
- ERR_EXPLAIN(p_path+":"+itos(line)+" Unexpected 'msgstr', was expecting 'msgid' while parsing: ");
+ ERR_EXPLAIN(p_path + ":" + itos(line) + " Unexpected 'msgstr', was expecting 'msgid' while parsing: ");
ERR_FAIL_V(RES());
}
- l=l.substr(6,l.length()).strip_edges();
- status=STATUS_READING_STRING;
+ l = l.substr(6, l.length()).strip_edges();
+ status = STATUS_READING_STRING;
}
- if (l=="" || l.begins_with("#")) {
+ if (l == "" || l.begins_with("#")) {
line++;
continue; //nothing to read or comment
}
- if (!l.begins_with("\"") || status==STATUS_NONE) {
+ if (!l.begins_with("\"") || status == STATUS_NONE) {
//not a string? failure!
- ERR_EXPLAIN(p_path+":"+itos(line)+" Invalid line '"+l+"' while parsing: ");
+ ERR_EXPLAIN(p_path + ":" + itos(line) + " Invalid line '" + l + "' while parsing: ");
ERR_FAIL_V(RES());
-
}
- l=l.substr(1,l.length());
+ l = l.substr(1, l.length());
//find final quote
- int end_pos=-1;
- for(int i=0;i<l.length();i++) {
+ int end_pos = -1;
+ for (int i = 0; i < l.length(); i++) {
- if (l[i]=='"' && (i==0 || l[i-1]!='\\')) {
- end_pos=i;
+ if (l[i] == '"' && (i == 0 || l[i - 1] != '\\')) {
+ end_pos = i;
break;
}
}
- if (end_pos==-1) {
- ERR_EXPLAIN(p_path+":"+itos(line)+" Expected '\"' at end of message while parsing file: ");
+ if (end_pos == -1) {
+ ERR_EXPLAIN(p_path + ":" + itos(line) + " Expected '\"' at end of message while parsing file: ");
ERR_FAIL_V(RES());
}
- l=l.substr(0,end_pos);
- l=l.c_unescape();
-
+ l = l.substr(0, end_pos);
+ l = l.c_unescape();
- if (status==STATUS_READING_ID)
- msg_id+=l;
+ if (status == STATUS_READING_ID)
+ msg_id += l;
else
- msg_str+=l;
+ msg_str += l;
line++;
}
-
f->close();
memdelete(f);
- if (config=="") {
- ERR_EXPLAIN("No config found in file: "+p_path);
+ if (config == "") {
+ ERR_EXPLAIN("No config found in file: " + p_path);
ERR_FAIL_V(RES());
}
Vector<String> configs = config.split("\n");
- for(int i=0;i<configs.size();i++) {
+ for (int i = 0; i < configs.size(); i++) {
String c = configs[i].strip_edges();
int p = c.find(":");
- if (p==-1)
+ if (p == -1)
continue;
- String prop = c.substr(0,p).strip_edges();
- String value = c.substr(p+1,c.length()).strip_edges();
+ String prop = c.substr(0, p).strip_edges();
+ String value = c.substr(p + 1, c.length()).strip_edges();
- if (prop=="X-Language") {
+ if (prop == "X-Language") {
translation->set_locale(value);
}
}
if (r_error)
- *r_error=OK;
+ *r_error = OK;
return translation;
}
-RES TranslationLoaderPO::load(const String &p_path, const String& p_original_path, Error *r_error) {
+RES TranslationLoaderPO::load(const String &p_path, const String &p_original_path, Error *r_error) {
if (r_error)
- *r_error=ERR_CANT_OPEN;
-
- FileAccess *f=FileAccess::open(p_path,FileAccess::READ);
- ERR_FAIL_COND_V(!f,RES());
-
+ *r_error = ERR_CANT_OPEN;
- return load_translation(f,r_error);
+ FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
+ ERR_FAIL_COND_V(!f, RES());
+ return load_translation(f, r_error);
}
-void TranslationLoaderPO::get_recognized_extensions(List<String> *p_extensions) const{
+void TranslationLoaderPO::get_recognized_extensions(List<String> *p_extensions) const {
p_extensions->push_back("po");
//p_extensions->push_back("mo"); //mo in the future...
}
-bool TranslationLoaderPO::handles_type(const String& p_type) const{
+bool TranslationLoaderPO::handles_type(const String &p_type) const {
- return (p_type=="Translation");
+ return (p_type == "Translation");
}
String TranslationLoaderPO::get_resource_type(const String &p_path) const {
- if (p_path.get_extension().to_lower()=="po")
+ if (p_path.get_extension().to_lower() == "po")
return "Translation";
return "";
}
-TranslationLoaderPO::TranslationLoaderPO()
-{
+TranslationLoaderPO::TranslationLoaderPO() {
}