commit
babdb27570
10 changed files with 119 additions and 80 deletions
@ -0,0 +1,44 @@ |
||||
# Copyright 2016 The Meson development team |
||||
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
from .. import coredata, mesonlib, build |
||||
import sys |
||||
|
||||
class I18nModule: |
||||
|
||||
def gettext(self, state, args, kwargs): |
||||
if len(args) != 1: |
||||
raise coredata.MesonException('Gettext requires one positional argument (package name).') |
||||
packagename = args[0] |
||||
languages = mesonlib.stringlistify(kwargs.get('languages', [])) |
||||
if len(languages) == 0: |
||||
raise coredata.MesonException('List of languages empty.') |
||||
potargs = [state.environment.get_build_command(), '--internal', 'gettext', 'pot', packagename] |
||||
pottarget = build.RunTarget(packagename + '-pot', sys.executable, potargs, state.subdir) |
||||
gmoargs = [state.environment.get_build_command(), '--internal', 'gettext', 'gen_gmo'] + languages |
||||
gmotarget = build.RunTarget(packagename + '-gmo', sys.executable, gmoargs, state.subdir) |
||||
installcmd = [sys.executable, |
||||
state.environment.get_build_command(), |
||||
'--internal', |
||||
'gettext', |
||||
'install', |
||||
state.subdir, |
||||
packagename, |
||||
state.environment.coredata.get_builtin_option('localedir'), |
||||
] + languages |
||||
iscript = build.InstallScript(installcmd) |
||||
return [pottarget, gmotarget, iscript] |
||||
|
||||
def initialize(): |
||||
return I18nModule() |
@ -0,0 +1,65 @@ |
||||
#!/usr/bin/env python3 |
||||
|
||||
# Copyright 2016 The Meson development team |
||||
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
import os, subprocess, shutil |
||||
|
||||
def run_potgen(src_sub, pkgname, langs): |
||||
listfile = os.path.join(src_sub, 'POTFILES') |
||||
ofile = os.path.join(src_sub, pkgname + '.pot') |
||||
return subprocess.call(['xgettext', '--package-name=' + pkgname, '-p', src_sub, listfile, |
||||
'-D', os.environ['MESON_SOURCE_ROOT'], '-k_', '-o', ofile]) |
||||
|
||||
def gen_gmo(src_sub, bld_sub, langs): |
||||
for l in langs: |
||||
subprocess.check_call(['msgfmt', os.path.join(src_sub, l + '.po'), |
||||
'-o', os.path.join(bld_sub, l + '.gmo')]) |
||||
return 0 |
||||
|
||||
def do_install(src_sub, bld_sub, dest, pkgname, langs): |
||||
for l in langs: |
||||
srcfile = os.path.join(bld_sub, l + '.gmo') |
||||
outfile = os.path.join(dest, l, 'LC_MESSAGES', |
||||
pkgname + '.mo') |
||||
os.makedirs(os.path.split(outfile)[0], exist_ok=True) |
||||
shutil.copyfile(srcfile, outfile) |
||||
shutil.copystat(srcfile, outfile) |
||||
print('Installing %s to %s.' % (srcfile, outfile)) |
||||
return 0 |
||||
|
||||
def run(args): |
||||
subcmd = args[0] |
||||
if subcmd == 'pot': |
||||
src_sub = os.path.join(os.environ['MESON_SOURCE_ROOT'], os.environ['MESON_SUBDIR']) |
||||
bld_sub = os.path.join(os.environ['MESON_BUILD_ROOT'], os.environ['MESON_SUBDIR']) |
||||
return run_potgen(src_sub, args[1], args[2:]) |
||||
elif subcmd == 'gen_gmo': |
||||
src_sub = os.path.join(os.environ['MESON_SOURCE_ROOT'], os.environ['MESON_SUBDIR']) |
||||
bld_sub = os.path.join(os.environ['MESON_BUILD_ROOT'], os.environ['MESON_SUBDIR']) |
||||
return gen_gmo(src_sub, bld_sub, args[1:]) |
||||
elif subcmd == 'install': |
||||
subdir = args[1] |
||||
pkgname = args[2] |
||||
instsubdir = args[3] |
||||
langs = args[4:] |
||||
src_sub = os.path.join(os.environ['MESON_SOURCE_ROOT'], subdir) |
||||
bld_sub = os.path.join(os.environ['MESON_BUILD_ROOT'], subdir) |
||||
dest = os.environ.get('DESTDIR') + os.path.join(os.environ['MESON_INSTALL_PREFIX'], instsubdir) |
||||
if gen_gmo(src_sub, bld_sub, langs) != 0: |
||||
return 1 |
||||
do_install(src_sub, bld_sub, dest, pkgname, langs) |
||||
else: |
||||
print('Unknown subcommand.') |
||||
return 1 |
@ -1,4 +1,6 @@ |
||||
project('gettext example', 'c') |
||||
|
||||
i18n = import('i18n') |
||||
|
||||
subdir('po') |
||||
subdir('src') |
||||
|
@ -1,4 +1,3 @@ |
||||
langs = ['fi', 'de'] |
||||
|
||||
gettext('intltest', |
||||
languages : langs) |
||||
i18n.gettext('intltest', languages : langs) |
||||
|
Loading…
Reference in new issue