mirror of https://github.com/kiwix/libkiwix.git
Merge pull request #763 from kiwix/i18n_resource_discovery
This commit is contained in:
commit
55149407d2
|
@ -86,22 +86,12 @@ extern const size_t langCount = $LANG_COUNT;
|
||||||
'''
|
'''
|
||||||
|
|
||||||
class Resource:
|
class Resource:
|
||||||
def __init__(self, base_dirs, filename):
|
def __init__(self, filename):
|
||||||
filename = filename.strip()
|
filename = filename.strip()
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
self.lang_code = lang_code(filename)
|
self.lang_code = lang_code(filename)
|
||||||
found = False
|
with open(filename, 'r') as f:
|
||||||
for base_dir in base_dirs:
|
self.data = f.read()
|
||||||
try:
|
|
||||||
with open(os.path.join(base_dir, filename), 'r') as f:
|
|
||||||
self.data = f.read()
|
|
||||||
found = True
|
|
||||||
break
|
|
||||||
except FileNotFoundError:
|
|
||||||
continue
|
|
||||||
if not found:
|
|
||||||
raise Exception("Impossible to find {}".format(filename))
|
|
||||||
|
|
||||||
|
|
||||||
def get_string_table_name(self):
|
def get_string_table_name(self):
|
||||||
return "string_table_for_" + self.lang_code
|
return "string_table_for_" + self.lang_code
|
||||||
|
@ -147,14 +137,11 @@ if __name__ == "__main__":
|
||||||
parser.add_argument('--cxxfile',
|
parser.add_argument('--cxxfile',
|
||||||
required=True,
|
required=True,
|
||||||
help='The Cpp file name to generate')
|
help='The Cpp file name to generate')
|
||||||
parser.add_argument('i18n_resource_file',
|
parser.add_argument('i18n_resource_files', nargs='+',
|
||||||
help='The list of resources to compile.')
|
help='The list of resources to compile.')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
base_dir = os.path.dirname(os.path.realpath(args.i18n_resource_file))
|
resources = [Resource(filename) for filename in args.i18n_resource_files]
|
||||||
with open(args.i18n_resource_file, 'r') as f:
|
|
||||||
resources = [Resource([base_dir], filename)
|
|
||||||
for filename in f.readlines()]
|
|
||||||
|
|
||||||
with open(args.cxxfile, 'w') as f:
|
with open(args.cxxfile, 'w') as f:
|
||||||
f.write(gen_c_file(resources))
|
f.write(gen_c_file(resources))
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
.SH NAME
|
.SH NAME
|
||||||
kiwix-compile-i18n \- helper to compile Kiwix i18n (internationalization) data
|
kiwix-compile-i18n \- helper to compile Kiwix i18n (internationalization) data
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
\fBkiwix\-compile\-i18n\fR [\-h] \-\-cxxfile CXXFILE i18n_resource_file\fR
|
\fBkiwix\-compile\-i18n\fR [\-h] \-\-cxxfile CXXFILE i18n_resource_files ...\fR
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
.TP
|
.TP
|
||||||
i18n_resource_file
|
i18n_resource_files ...
|
||||||
The list of i18n resources to compile.
|
The list of i18n resources to compile.
|
||||||
.TP
|
.TP
|
||||||
\fB\-h\fR, \fB\-\-help\fR
|
\fB\-h\fR, \fB\-\-help\fR
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
i18n/en.json
|
|
||||||
i18n/hy.json
|
|
|
@ -24,17 +24,29 @@ lib_resources = custom_target('resources',
|
||||||
depends: preprocessed_resources
|
depends: preprocessed_resources
|
||||||
)
|
)
|
||||||
|
|
||||||
i18n_resource_files = run_command(find_program('python3'),
|
i18n_resource_listing_script = '''import glob
|
||||||
'-c',
|
import os
|
||||||
'import sys; f=open(sys.argv[1]); print(f.read())',
|
import sys
|
||||||
files('i18n_resources_list.txt')
|
qqq = sys.argv[1]
|
||||||
).stdout().strip().split('\n')
|
d = os.path.dirname(qqq)
|
||||||
|
r = glob.glob(d + "/*.json")
|
||||||
|
r.remove(qqq)
|
||||||
|
for f in r: print(f)
|
||||||
|
'''
|
||||||
|
|
||||||
|
i18n_resource_listing_cmd = [
|
||||||
|
find_program('python3'),
|
||||||
|
'-c',
|
||||||
|
i18n_resource_listing_script,
|
||||||
|
files('i18n/qqq.json')
|
||||||
|
]
|
||||||
|
|
||||||
|
i18n_resource_files = run_command(i18n_resource_listing_cmd).stdout().strip().split('\n')
|
||||||
|
|
||||||
i18n_resources = custom_target('i18n_resources',
|
i18n_resources = custom_target('i18n_resources',
|
||||||
input: 'i18n_resources_list.txt',
|
input: i18n_resource_files,
|
||||||
output: ['libkiwix-i18n-resources.cpp'],
|
output: ['libkiwix-i18n-resources.cpp'],
|
||||||
command:[i18n_compiler,
|
command:[i18n_compiler,
|
||||||
'--cxxfile', '@OUTPUT0@',
|
'--cxxfile', '@OUTPUT0@',
|
||||||
'@INPUT@'],
|
'@INPUT@'],
|
||||||
depend_files: i18n_resource_files
|
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue