checker is going to use locales, fix them up, too.

This commit is contained in:
Enno Rehling 2018-10-06 20:47:23 +02:00
parent 9a1bdf4444
commit 4f8dd4cb0f
9 changed files with 42 additions and 24 deletions

View File

@ -186,6 +186,7 @@ endif()
add_library(version STATIC ${VERSION_SRC}) add_library(version STATIC ${VERSION_SRC})
add_library(parser ${PARSER_SRC}) add_library(parser ${PARSER_SRC})
target_link_libraries(parser target_link_libraries(parser
${CLIBS_LIBRARIES}
${CRYPTO_LIBRARIES} ${CRYPTO_LIBRARIES}
) )
@ -205,7 +206,6 @@ target_link_libraries(eressea
${TOLUA_LIBRARIES} ${TOLUA_LIBRARIES}
${LUA_LIBRARIES} ${LUA_LIBRARIES}
${STORAGE_LIBRARIES} ${STORAGE_LIBRARIES}
${CLIBS_LIBRARIES}
${CJSON_LIBRARIES} ${CJSON_LIBRARIES}
${INIPARSER_LIBRARIES} ${INIPARSER_LIBRARIES}
) )

View File

@ -22,7 +22,7 @@
void eressea_free_game(void) { void eressea_free_game(void) {
free_gamedata(); free_gamedata();
init_resources(); init_resources();
init_locales(); init_locales(init_locale);
} }
int eressea_read_game(const char * filename) { int eressea_read_game(const char * filename) {

View File

@ -3,9 +3,14 @@
#endif #endif
#include "util/order_parser.h" #include "util/order_parser.h"
#include "util/keyword.h"
#include "util/language.h"
#include "util/path.h"
#include "util/pofile.h"
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
typedef struct parser_state { typedef struct parser_state {
FILE * F; FILE * F;
@ -47,6 +52,26 @@ int parsefile(FILE *F) {
return err; return err;
} }
static int handle_po(const char *msgid, const char *msgstr, const char *msgctxt, void *data) {
struct locale *lang = (struct locale *)data;
if (msgctxt) {
if (strcmp(msgctxt, "keyword") == 0) {
keyword_t kwd = findkeyword(msgid);
init_keyword(lang, kwd, msgstr);
locale_setstring(lang, mkname("keyword", keywords[kwd]), msgstr);
}
}
return 0;
}
static void read_config(const char *respath) {
char path[PATH_MAX];
struct locale *lang;
lang = get_or_create_locale("de");
path_join(respath, "translations/strings.de.po", path, sizeof(path));
pofile_read(path, handle_po, lang);
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
FILE * F = stdin; FILE * F = stdin;
if (argc > 1) { if (argc > 1) {
@ -57,6 +82,7 @@ int main(int argc, char **argv) {
return -1; return -1;
} }
} }
read_config("../git");
parsefile(F); parsefile(F);
if (F != stdin) { if (F != stdin) {
fclose(F); fclose(F);

View File

@ -239,6 +239,7 @@ static void init_magic(struct locale *lang)
free(sstr); free(sstr);
} }
} }
void init_locale(struct locale *lang) void init_locale(struct locale *lang)
{ {
init_magic(lang); init_magic(lang);

View File

@ -4,8 +4,6 @@
#define _LP64 0 /* fix a warning in pdcurses 3.4 */ #define _LP64 0 /* fix a warning in pdcurses 3.4 */
#endif #endif
#ifdef _MSC_VER
/* @see https://developercommunity.visualstudio.com/content/problem/69874/warning-c4001-in-standard-library-stringh-header.html */ /* @see https://developercommunity.visualstudio.com/content/problem/69874/warning-c4001-in-standard-library-stringh-header.html */
#if _MSC_VER >= 1900 #if _MSC_VER >= 1900
#pragma warning(disable: 4710 4820 4001) #pragma warning(disable: 4710 4820 4001)
@ -17,10 +15,5 @@
#pragma warning(disable: 4214) // bit field types other than int #pragma warning(disable: 4214) // bit field types other than int
#endif #endif
/* @see https://insanecoding.blogspot.no/2007/11/pathmax-simply-isnt.html */
#define PATH_MAX 260
#endif
#define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) > (b)) ? (a) : (b)) #define MAX(a, b) (((a) > (b)) ? (a) : (b))

View File

@ -353,29 +353,20 @@ void *get_translation(const struct locale *lang, const char *str, int index) {
return NULL; return NULL;
} }
void locale_foreach(void(*callback)(const struct locale *, const char *)) {
const locale * lang;
for (lang = locales; lang; lang = lang->next) {
callback(lang, lang->name);
}
}
const char *localenames[] = { const char *localenames[] = {
"de", "en", "de", "en",
NULL NULL
}; };
extern void init_locale(struct locale *lang);
static int locale_init = 0; static int locale_init = 0;
void init_locales(void) void init_locales(locale_handler init)
{ {
locale * lang; locale * lang;
if (locale_init) return; if (locale_init) return;
assert(locales); assert(locales);
for (lang = locales; lang; lang = lang->next) { for (lang = locales; lang; lang = nextlocale(lang)) {
init_locale(lang); init(lang);
} }
locale_init = 1; locale_init = 1;
} }

View File

@ -39,7 +39,8 @@ extern "C" {
/** managing multiple locales: **/ /** managing multiple locales: **/
struct locale *get_locale(const char *name); struct locale *get_locale(const char *name);
struct locale *get_or_create_locale(const char *key); struct locale *get_or_create_locale(const char *key);
void init_locales(void); typedef void(*locale_handler)(struct locale *lang);
void init_locales(locale_handler callback);
void free_locales(void); void free_locales(void);
void reset_locales(void); void reset_locales(void);
@ -57,7 +58,6 @@ extern "C" {
void make_locales(const char *str); void make_locales(const char *str);
void locale_foreach(void(*callback)(const struct locale *lang, const char *name));
void po_write_msg(FILE *F, const char *id, const char *str, const char *ctxt); void po_write_msg(FILE *F, const char *id, const char *str, const char *ctxt);
#define LOC(lang, s) (lang?locale_string(lang, s, true):s) #define LOC(lang, s) (lang?locale_string(lang, s, true):s)

View File

@ -12,8 +12,9 @@ without prior permission by the authors of Eressea.
#include <platform.h> #include <platform.h>
#include "log.h" #include "log.h"
#include "unicode.h" #include "path.h"
#include "strings.h" #include "strings.h"
#include "unicode.h"
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>

View File

@ -1,4 +1,10 @@
#pragma once
#include <stddef.h> #include <stddef.h>
#ifdef _MSC_VER
/* @see https://insanecoding.blogspot.no/2007/11/pathmax-simply-isnt.html */
#define PATH_MAX 260
#endif
char * path_join(const char *p1, const char *p2, char *dst, size_t len); char * path_join(const char *p1, const char *p2, char *dst, size_t len);