i18n: Add merge_file function
This is a repeated task that we can simplify Closes #1120
This commit is contained in:
parent
8be0df1443
commit
7d68715297
|
@ -14,10 +14,26 @@
|
|||
|
||||
from os import path
|
||||
from .. import coredata, mesonlib, build
|
||||
from ..mesonlib import MesonException
|
||||
import sys
|
||||
|
||||
class I18nModule:
|
||||
|
||||
def merge_file(self, state, args, kwargs):
|
||||
podir = kwargs.pop('po_dir', None)
|
||||
if not podir:
|
||||
raise MesonException('i18n: po_dir is a required kwarg')
|
||||
podir = path.join(state.build_to_src, state.subdir, podir)
|
||||
|
||||
file_type = kwargs.pop('type', 'xml')
|
||||
VALID_TYPES = ('xml', 'desktop')
|
||||
if not file_type in VALID_TYPES:
|
||||
raise MesonException('i18n: "{}" is not a valid type {}'.format(file_type, VALID_TYPES))
|
||||
|
||||
kwargs['command'] = ['msgfmt', '--' + file_type,
|
||||
'--template', '@INPUT@', '-d', podir, '-o', '@OUTPUT@']
|
||||
return build.CustomTarget(kwargs['output'] + '_merge', state.subdir, kwargs)
|
||||
|
||||
@staticmethod
|
||||
def _read_linguas(state):
|
||||
linguas = path.join(state.environment.get_source_dir(), state.subdir, 'LINGUAS')
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
i18n.merge_file(
|
||||
input: 'test.desktop.in',
|
||||
output: 'test.desktop',
|
||||
type: 'desktop',
|
||||
po_dir: '../po',
|
||||
install: true,
|
||||
install_dir: join_paths(get_option('datadir'), 'applications')
|
||||
)
|
|
@ -0,0 +1,6 @@
|
|||
[Desktop Entry]
|
||||
Name=Test
|
||||
GenericName=Application
|
||||
Comment=Test Application
|
||||
Type=Application
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
usr/bin/intlprog
|
||||
usr/share/locale/de/LC_MESSAGES/intltest.mo
|
||||
usr/share/locale/fi/LC_MESSAGES/intltest.mo
|
||||
usr/share/applications/test.desktop
|
||||
|
|
|
@ -4,3 +4,4 @@ i18n = import('i18n')
|
|||
|
||||
subdir('po')
|
||||
subdir('src')
|
||||
subdir('data')
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
de
|
||||
fi
|
|
@ -1 +1,2 @@
|
|||
src/intlmain.c
|
||||
data/test.desktop
|
||||
|
|
Loading…
Reference in New Issue