| 1 | /* |
| 2 | * Extract translation strings |
| 3 | * |
| 4 | * Copyright 2008 by Robert Krawitz. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the Free |
| 8 | * Software Foundation; either version 2 of the License, or (at your option) |
| 9 | * any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * Include necessary headers... |
| 22 | */ |
| 23 | |
| 24 | #include <stdio.h> |
| 25 | #include <gutenprint/gutenprint.h> |
| 26 | #include <gutenprint/mxml.h> |
| 27 | #ifdef HAVE_CONFIG_H |
| 28 | #include "config.h" |
| 29 | #endif |
| 30 | |
| 31 | int |
| 32 | main(int argc, char **argv) |
| 33 | { |
| 34 | int status = 0; |
| 35 | argv++; |
| 36 | printf("/*\n"); |
| 37 | printf(" * TRANSLATORS:\n"); |
| 38 | printf(" * All strings in this file must be no more than 80 bytes in length.\n"); |
| 39 | printf(" * Please take into account expansion due to multi-byte characters,\n"); |
| 40 | printf(" * as the limit is *bytes*, not characters!\n"); |
| 41 | printf(" */\n"); |
| 42 | while (*argv) |
| 43 | { |
| 44 | stp_mxml_node_t *top = |
| 45 | stp_mxmlLoadFromFile(NULL, *argv, STP_MXML_NO_CALLBACK); |
| 46 | if (top) |
| 47 | { |
| 48 | stp_mxml_node_t *n = top; |
| 49 | stp_string_list_t *sl = stp_string_list_create(); |
| 50 | do |
| 51 | { |
| 52 | const char *attr = stp_mxmlElementGetAttr(n, "translate"); |
| 53 | if (attr) |
| 54 | { |
| 55 | const char *str = stp_mxmlElementGetAttr(n, attr); |
| 56 | if (! stp_string_list_is_present(sl, str)) |
| 57 | { |
| 58 | char *s; |
| 59 | stp_string_list_add_string_unsafe(sl, str, str); |
| 60 | stp_asprintf(&s, "N_(\"%s\");", str); |
| 61 | printf("%-40s /* %s */\n", s, *argv); |
| 62 | stp_free(s); |
| 63 | } |
| 64 | } |
| 65 | n = stp_mxmlWalkNext(n, top, STP_MXML_DESCEND); |
| 66 | } while (n); |
| 67 | stp_string_list_destroy(sl); |
| 68 | stp_mxmlDelete(top); |
| 69 | } |
| 70 | else |
| 71 | { |
| 72 | fprintf(stderr, "Cannot read %s: %s\n", *argv, strerror(errno)); |
| 73 | status = 1; |
| 74 | } |
| 75 | argv++; |
| 76 | } |
| 77 | return status; |
| 78 | } |