Skip to content

Commit 764f7c9

Browse files
committed
quick little CSV exporter for translations
1 parent da1722f commit 764f7c9

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

tools/translation.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include "util/pofile.h"
2+
#include "util/strings.h"
3+
4+
#include <stb_ds.h>
5+
6+
#include <stdlib.h>
7+
#include <stdio.h>
8+
#include <string.h>
9+
10+
typedef struct keyval_t {
11+
char * key;
12+
char * value;
13+
} keyval_t;
14+
15+
const char *filter_ctx = NULL;
16+
17+
static int add_po_string(const char *msgid, const char *msgstr, const char *msgctx, void *data)
18+
{
19+
if (!filter_ctx || (msgctx && strcmp(filter_ctx, msgctx) == 0))
20+
{
21+
keyval_t **hash_ref = (keyval_t**)data;
22+
keyval_t *hash = *hash_ref;
23+
shput(hash, str_strdup(msgid), strdup(msgstr));
24+
*hash_ref = hash;
25+
}
26+
return 0;
27+
}
28+
29+
int main(int argc, char **argv)
30+
{
31+
keyval_t *hm_de = NULL;
32+
keyval_t *hm_en = NULL;
33+
ptrdiff_t i;
34+
if (argc >= 1) {
35+
filter_ctx = argv[1];
36+
}
37+
pofile_read("res/translations/strings.de.po", add_po_string, &hm_de);
38+
pofile_read("res/translations/strings.en.po", add_po_string, &hm_en);
39+
for (i=shlen(hm_de);i != 0; --i) {
40+
keyval_t *de = hm_de + i - 1;
41+
keyval_t *en = shgetp_null(hm_en, de->key);
42+
if (en) {
43+
printf("\"%s\";\"%s\"\n", de->value, en->value);
44+
}
45+
}
46+
hmfree(hm_en);
47+
hmfree(hm_de);
48+
return EXIT_SUCCESS;
49+
}

0 commit comments

Comments
 (0)