Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/markdown/i18n-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ argument which is the name of the gettext module.

* `args`: list of extra arguments to pass to `xgettext` when
generating the pot file
* `msgfmt_args`: (*Added 1.11.0*) list of extra arguments to pass to `msgfmt` when
building the translations
* `data_dirs`: (*Added 0.36.0*) list of directories to be set for
`GETTEXTDATADIRS` env var (Requires gettext 0.19.8+), used for local
its files
Expand Down
12 changes: 12 additions & 0 deletions docs/markdown/snippets/i18n_msgfmt_args.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Added `msgfmt_args` arg to `i18n.gettext`

`i18n.gettext` now supports the `msgfmt_args` argument.
This argument can be used to pass additional arguments to
`msgfmt` when building the translations.

```meson
i18n = import('i18n')
i18n.gettext('mycatalog',
args : ['-k_', '-kN_'],
msgfmt_args : ['--use-fuzzy'])
```
15 changes: 14 additions & 1 deletion mesonbuild/modules/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class MergeFile(TypedDict):
class Gettext(TypedDict):

args: T.List[str]
msgfmt_args: T.List[str]
data_dirs: T.List[str]
install: bool
install_dir: T.Optional[str]
Expand Down Expand Up @@ -85,6 +86,14 @@ class XgettextProgramT(TypedDict):
listify=True,
)

_MSGFMT_ARGS: KwargInfo[T.List[str]] = KwargInfo(
'msgfmt_args',
ContainerTypeInfo(list, str),
default=[],
listify=True,
since='1.11.0',
)

_DATA_DIRS: KwargInfo[T.List[str]] = KwargInfo(
'data_dirs',
ContainerTypeInfo(list, str),
Expand Down Expand Up @@ -349,6 +358,7 @@ def merge_file(self, state: 'ModuleState', args: T.List['TYPE_var'], kwargs: 'Me
@typed_kwargs(
'i18n.gettext',
_ARGS,
_MSGFMT_ARGS,
_DATA_DIRS.evolve(since='0.36.0'),
INSTALL_KW.evolve(default=True),
INSTALL_DIR_KW.evolve(since='0.50.0'),
Expand Down Expand Up @@ -418,12 +428,15 @@ def gettext(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'Gettext') -
for l in languages:
po_file = mesonlib.File.from_source_file(state.environment.source_dir,
state.subdir, l+'.po')

gmobasecmd: T.List[T.Union[str, Program]] = [self.tools['msgfmt'], '-o', '@OUTPUT@', '@INPUT@']

gmotarget = build.CustomTarget(
f'{packagename}-{l}.mo',
path.join(state.subdir, l, 'LC_MESSAGES'),
state.subproject,
state.environment,
[self.tools['msgfmt'], '-o', '@OUTPUT@', '@INPUT@'],
gmobasecmd + T.cast(T.List[T.Union[str, 'Program']], kwargs['msgfmt_args']),
[po_file],
[f'{packagename}.mo'],
install=install,
Expand Down
2 changes: 1 addition & 1 deletion test cases/frameworks/6 gettext/po/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
langs = ['fi', 'de', 'ru']

gettext_targets = i18n.gettext('intltest', languages : langs)
gettext_targets = i18n.gettext('intltest', languages : langs, msgfmt_args : ['--use-fuzzy'])
mo_targets = gettext_targets[0]
Loading