i18n: Add preset kwarg

Many frameworks, such as glib, provide translation functions and
functions that take format strings. As such every application using
these must duplicate the gettext arguments to function properly.

This reduces that duplication and improves correctness so they are
not left out.

Fixes #1123
pull/1124/head
Patrick Griffis 8 years ago committed by Jussi Pakkanen
parent 7d68715297
commit acb0a38aac
  1. 34
      mesonbuild/modules/i18n.py

@ -17,6 +17,32 @@ from .. import coredata, mesonlib, build
from ..mesonlib import MesonException
import sys
PRESET_ARGS = {
'glib': [
'--from-code=UTF-8',
'--add-comments',
# https://developer.gnome.org/glib/stable/glib-I18N.html
'--keyword=_',
'--keyword=N_',
'--keyword=C_:1c,2',
'--keyword=NC_:1c,2',
'--keyword=g_dcgettext:2',
'--keyword=g_dngettext:2,3',
'--keyword=g_dpgettext2:2c,3',
'--flag=N_:1:pass-c-format',
'--flag=C_:2:pass-c-format',
'--flag=NC_:2:pass-c-format',
'--flag=g_dngettext:2:pass-c-format',
'--flag=g_strdup_printf:1:c-format',
'--flag=g_string_printf:2:c-format',
'--flag=g_string_append_printf:2:c-format',
'--flag=g_error_new:3:c-format',
'--flag=g_set_error:4:c-format',
]
}
class I18nModule:
def merge_file(self, state, args, kwargs):
@ -53,6 +79,14 @@ class I18nModule:
datadirs = mesonlib.stringlistify(kwargs.get('data_dirs', []))
extra_args = mesonlib.stringlistify(kwargs.get('args', []))
preset = kwargs.pop('preset', None)
if preset:
preset_args = PRESET_ARGS.get(preset)
if not preset_args:
raise coredata.MesonException('i18n: Preset "{}" is not one of the valid options: {}'.format(
preset, list(PRESET_ARGS.keys())))
extra_args = set(preset_args + extra_args)
pkg_arg = '--pkgname=' + packagename
lang_arg = '--langs=' + '@@'.join(languages)
datadirs = '--datadirs=' + ':'.join(datadirs) if datadirs else None

Loading…
Cancel
Save