i18n module: provide targets as return value for gettext()

Users may wish to make use of these files for their own purposes.

For example, the -pot and -update-po pseudo targets could be reused in
an alias_target(), and at least one person wanted to reuse the built .mo
files as custom_target input.

Fixes #6227
pull/9174/head
Eli Schwartz 3 years ago
parent bd691b847c
commit 2fc7592e13
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 5
      docs/markdown/i18n-module.md
  2. 6
      docs/markdown/snippets/i18n-return.md
  3. 4
      mesonbuild/modules/i18n.py

@ -38,6 +38,11 @@ This function also defines targets for maintainers to use:
* `<project_id>-update-po`: regenerates the `.po` files from current `.pot` file * `<project_id>-update-po`: regenerates the `.po` files from current `.pot` file
* `<project_id>-gmo`: builds the translations without installing * `<project_id>-gmo`: builds the translations without installing
(*since 0.60.0*) Returns a list containing:
* a list of built `.mo` files
* the maintainer `-pot` target
* the maintainer `-update-po` target
### i18n.merge_file() ### i18n.merge_file()
This merges translations into a text file using `msgfmt`. See This merges translations into a text file using `msgfmt`. See

@ -0,0 +1,6 @@
## i18n module now returns gettext targets
`r = i18n.gettext('mydomain')` will now provide access to:
- a list of built .mo files
- the mydomain-pot maintainer target which updates .pot files
- the mydomain-update-po maintainer target which updates .po files

@ -143,6 +143,7 @@ class I18nModule(ExtensionModule):
datadirs = self._get_data_dirs(state, mesonlib.stringlistify(kwargs.get('data_dirs', []))) datadirs = self._get_data_dirs(state, mesonlib.stringlistify(kwargs.get('data_dirs', [])))
extra_args = mesonlib.stringlistify(kwargs.get('args', [])) extra_args = mesonlib.stringlistify(kwargs.get('args', []))
targets = [] targets = []
gmotargets = []
preset = kwargs.pop('preset', None) preset = kwargs.pop('preset', None)
if preset: if preset:
@ -185,6 +186,7 @@ class I18nModule(ExtensionModule):
} }
gmotarget = build.CustomTarget(l+'.mo', path.join(state.subdir, l, 'LC_MESSAGES'), state.subproject, gmo_kwargs) gmotarget = build.CustomTarget(l+'.mo', path.join(state.subdir, l, 'LC_MESSAGES'), state.subproject, gmo_kwargs)
targets.append(gmotarget) targets.append(gmotarget)
gmotargets.append(gmotarget)
updatepoargs = state.environment.get_build_command() + ['--internal', 'gettext', 'update_po', pkg_arg] updatepoargs = state.environment.get_build_command() + ['--internal', 'gettext', 'update_po', pkg_arg]
if lang_arg: if lang_arg:
@ -196,7 +198,7 @@ class I18nModule(ExtensionModule):
updatepotarget = build.RunTarget(packagename + '-update-po', updatepoargs, [], state.subdir, state.subproject) updatepotarget = build.RunTarget(packagename + '-update-po', updatepoargs, [], state.subdir, state.subproject)
targets.append(updatepotarget) targets.append(updatepotarget)
return ModuleReturnValue(None, targets) return ModuleReturnValue([gmotargets, pottarget, updatepotarget], targets)
def initialize(*args, **kwargs): def initialize(*args, **kwargs):
return I18nModule(*args, **kwargs) return I18nModule(*args, **kwargs)

Loading…
Cancel
Save