summaryrefslogtreecommitdiff
path: root/tools/eos-json-extractor/eos-json-extractor.in
blob: fd61d4b0be7e5b9f5ad78450ae1fa378313b9a1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env gjs
// Copyright 2013 Endless Mobile, Inc.

const Format = imports.format;
const System = imports.system;

const Gio = imports.gi.Gio;
const Json = imports.gi.Json;

String.prototype.format = Format.format;

// Other constants, available from subcommands' code
const programVersion = "@PACKAGE_VERSION@";

/**
 * usage:
 *
 * Print command-line help message.
 */
function usage() {
    print('Extracts translatable strings fron JSON configuration file.\n');
    print('Usage: %s [Options | <INPUT-FILE> <TOP-SRCDIR>]\n'.format(
        System.programInvocationName));
    print('Options:');
    print('  --help     Print this help message');
    print('  --version  Print version and exit');
    System.exit(0);
}

/**
 * version:
 *
 * Print command-line version output.
 */
function version() {
    print('%s %s - Discover unit tests in a source tree'.format(
        System.programInvocationName, programVersion));
    System.exit(0);
}

if(ARGV.indexOf('--version') != -1)
    version();
if((ARGV.indexOf('--help') != -1) || (ARGV.length != 2)) {
    usage();
}

try {
		let parser = new Json.Parser();
		let input_file = Gio.File.new_for_path(ARGV[0]);
		let top_srcdir = Gio.File.new_for_path(ARGV[1]);
		let full_path = top_srcdir.get_relative_path(input_file);

		parser.connect('object-member', function(parser, object, member_name) {
		    if(!member_name.endsWith('_'))
		        return;
		    print('#line %d "%s"'.format(parser.get_current_line(), full_path));
		    print('_("%s");'.format(object.get_string_member(member_name)));
		});
		parser.load_from_file(input_file.get_path());

} catch (e) {
    printerr('%s: %s'.format(System.programInvocationName, e.message));
    System.exit(1);
}