about summary refs log tree commit diff
path: root/src/game/localization.cpp
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2009-06-13 17:18:06 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2009-06-13 17:18:06 +0000
commitbc20e9c433c1c7bd2a9516a936d1d7ffee1e90f2 (patch)
tree172eb47c01b26969ccda334006f83859f43abe90 /src/game/localization.cpp
parent6d9ccee95dd99fecda3a6ba62c2768b4d39f69e5 (diff)
downloadzcatch-bc20e9c433c1c7bd2a9516a936d1d7ffee1e90f2.tar.gz
zcatch-bc20e9c433c1c7bd2a9516a936d1d7ffee1e90f2.zip
localization update
Diffstat (limited to 'src/game/localization.cpp')
-rw-r--r--src/game/localization.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/game/localization.cpp b/src/game/localization.cpp
index cfc659f5..58ec539c 100644
--- a/src/game/localization.cpp
+++ b/src/game/localization.cpp
@@ -1,6 +1,10 @@
 
 #include "localization.hpp"
 
+extern "C" {
+#include <engine/e_linereader.h>
+}
+
 static unsigned str_hash(const char *str)
 {
 	unsigned hash = 5381;
@@ -43,8 +47,48 @@ void LOCALIZATIONDATABASE::add_string(const char *org_str, const char *new_str)
 	s.hash = str_hash(org_str);
 	s.replacement = new_str;
 	strings.add(s);
+}
+
+bool LOCALIZATIONDATABASE::load(const char *filename)
+{
+	LINEREADER lr;
+	IOHANDLE io = io_open(filename, IOFLAG_READ);
+	if(!io)
+		return false;
+	
 	
+	dbg_msg("localization", "loaded '%s'", filename);
+	strings.clear();
+	
+	linereader_init(&lr, io);
+	char *line;
+	while((line = linereader_get(&lr)))
+	{
+		if(!str_length(line))
+			continue;
+			
+		if(line[0] == '#') // skip comments
+			continue;
+			
+		char *replacement = linereader_get(&lr);
+		if(!replacement)
+		{
+			dbg_msg("", "unexpected end of file");
+			break;
+		}
+		
+		if(replacement[0] != '=' || replacement[1] != '=' || replacement[2] != ' ')
+		{
+			dbg_msg("", "malform replacement line for '%s'", line);
+			continue;
+		}
+
+		replacement += 3;
+		localization.add_string(line, replacement);
+	}
+		
 	current_version++;
+	return true;
 }
 
 const char *LOCALIZATIONDATABASE::find_string(unsigned hash)