summaryrefslogtreecommitdiff
path: root/mesonbuild/modules/i18n.py
AgeCommit message (Collapse)Author
2025-12-16review get_subdir vs get_builddirPaolo Bonzini
Comparing the implementation of build_subdir with https://github.com/mesonbuild/meson/pull/12258, both of them introduced a similar separation between srcdir and builddir. There were some differences in the choices of srcdir vs builddir; this commit tries to identify which are bugs in which implementation, and get the best of both worlds.
2025-10-15revert local_program()Eli Schwartz
This reverts https://github.com/mesonbuild/meson/pull/15107 Explicit objections regarding the design were raised and not answered, so it shouldn't have been merged. It needs to be discussed and revisited.
2025-10-15Replace OverrideExecutable and OverrideProgram with LocalProgramXavier Claessens
2025-10-15Add support for LocalProgram to override_find_program()Xavier Claessens
2025-10-14Make use of build TypeAliasesDylan Baker
There are a lot of spelled out unions for these types, lets reduce that number
2025-10-01Allow CustomTarget source for i18n.xgettextCharles Brunet
Fixes #15054
2025-04-09New xgettext method for i18n moduleCharles Brunet
This method call xgettext to extract translatable string from source files into a .pot translation template. It differs from a plain CustomTarget in three ways: - It accepts build targets as sources, and automatically resolves source files from those build targets; - It detects command lines that are too long, and writes, at config time, the list of source files into a text file to be consumed by the xgettext command; - It detects dependencies between pot extraction targets, based on the dependencies between source targets.
2025-03-10coredata: replace get_option with optstore.get_value_forDylan Baker
This is an old method, that is now just a wrapper around the OptionStore method, that doesn't add any value. It's also an option related method attached to the CoreData instead of the OptionStore, so useless and a layering violation.
2024-07-11Move OptionKey in the option source file.Jussi Pakkanen
2024-02-22modules/i18n: CustomTargets must have `install_dir` if installingDylan Baker
Since they do not implement a default install dir like BuildTargets do. Fixes: #12843
2023-12-13Use SPDX-License-Identifier consistentlyDylan Baker
This replaces all of the Apache blurbs at the start of each file with an `# SPDX-License-Identifier: Apache-2.0` string. It also fixes existing uses to be consistent in capitalization, and to be placed above any copyright notices. This removes nearly 3000 lines of boilerplate from the project (only python files), which no developer cares to look at. SPDX is in common use, particularly in the Linux kernel, and is the recommended format for Meson's own `project(license: )` field
2023-10-26i18n module: Invoke itstool with the full command lineChun-wei Fan
Certain envs may not support invoking itstool by itself directly as a script as shebang lines are not supported, such as under cmd.exe shells on Windows, that are normally used for Visual Studio (and the like, such as clang-cl) builds. This will call the corresponding interpreter to invoke itstool when needed, so that itstool can be properly run, even if shebang lines are not supported by the env. This will fix building appstream on Windows using clang-cl, for instance.
2023-08-18Add more descriptive description to CustomTargetCharles Brunet
Allow modules using CustomTarget to modify the command description used by ninja backend. This result in more precise logs when building a project.
2023-05-22i18n module: check for a good enough msgfmt before permitting merge_fileEli Schwartz
The concept of merge_file intrinsically requires some GNU-specific functionality, so let's emit a useful error message during configuration, when we don't have that. The relevant GNU gettext versions date back to around 2015 so *probably* anyone has that too, but we may as well verify that while we are here.
2023-05-22i18n module: be broadly supportive of portable gettext toolsEli Schwartz
There are a number of implementations for msgfmt, supporting various options. The simplest, and most common, use case is to compile .po files into .mo files, and this should be able to work on gettext implementations other than the GNU one. The problem is that we were passing some pretty portable arguments in an unportable manner. The `-o` option-argument and its associated argument came after the input file operand, which violates the POSIX Utility Syntax Guidelines, and happens to not be supported by Solaris gettext. The GNU gettext doesn't care; GNU invented GNU argument permutation. Switch the order around so that our use respects the POSIX style.
2023-03-16modules/i18n: fix typo in gettext decoratorCorentin Noël
2023-01-10modules/i18n: fix type annotationsDylan Baker
Again, state.find_program is wrong
2022-12-11fix broken fs.copyfile function that crashed if you tried to use itEli Schwartz
At least, if you tried to use it when passing an install_dir. Because T.Sequence is horrible and we should never use it, and the annotations are a lie that produces bugs. So, fix the annotations on CustomTarget to never allow this to happen again, and also fix the function too. Move some definitions elsewhere inline to satisfy the linter. Fixes #11157
2022-09-12i18n: Fix source root in Gettext targets for subprojectsDavid Ward
Gettext should search for input files relative to the (sub)project source root, not the global source root. This change exposes a root_subdir member in ModuleState.
2022-08-17modules: use module level information about new and deprecationDylan Baker
Instead of using FeatureNew/FeatureDeprecated in the module. The goal here is to be able to handle information about modules in a single place, instead of having to handle it separately. Each module simply defines some metadata, and then the interpreter handles the rest.
2022-06-10flake8: remove no longer used importsEli Schwartz
2022-06-01interpreter: use a shared KwargInfo for install_dirDylan Baker
CustomTarget allows multiple install dirs, while basically everything else allows only one. So this provides a shared instance for that.
2022-05-31fix bug in i18n merge_file/itstool_join revealed by previous commitEli Schwartz
Logically, i18n.merge_file cannot ever take a MULTI_OUTPUT_KW, but it does take a CT_OUTPUT_KW-like interface. Actually trying to pass multiple merge_file outputs causes the msgfmthelper script to be entirely malformed in the arguments it accepts, and treat the broken one like a --flag, then exit with argparse errors. Even if we somehow assumed that somehow it was designed to actually allow this, msgfmt doesn't support conceptually passing multiple outputs so that would be a msgfmt error instead of an error inside the guts of `meson --internal msgfmthelper`. Same logic applies again for the itstool command and the itstool internal helper. Catch this error at configuration time by using the single-output kwarg form. Likewise, it's totally nonsense to accept multiple install_dir or install_tags, and ever since commit 11f96380351a88059ec55f1070fdebc1b1033117 the CustomTarget itself won't even check this.
2022-05-31rename a badly named KwargInfoEli Schwartz
CT_OUTPUT_KW is the same OUTPUT_KW we use in lots of places. The most distinctive thing about it is not that it's part of custom_target (basically any other function that uses such a kwarg follows the same rules due to using CustomTarget under the hood), but the fact that it takes multiple outputs.
2022-05-29i18n: be build-compatible (but not developer-compatible) with gettext-tinyEli Schwartz
For maintainer targets, we need some more tools that gettext-tiny doesn't implement. It's a shame to cause NLS to be completely disabled in such environments, so instead just issue a warning and continue. Before 0.62.0 these were never checked for, and would simply fail at runtime, probably. In theory, the user might install the tools in between configuring and building, and then the maintainer targets would begin to work. Return to that behavior -- we still create the targets, which will *probably* fail, but might not -- and for existing integrations, failing at `ninja foo-update-po` with "error, program msgmerge not found" is a bit more discoverable than ninja saying "what do you mean, there's no such target". We still have the 0.62.0 preferred behavior of trying to find the programs, succeeding in all cases other than gettext-tiny, and guaranteeing that their paths are set up in a machine-file-respecting manner.
2022-05-29i18n: fix bug where disabling gettext() broke merge_file()Eli Schwartz
In the former case, the presence of tools is optional, but triggers a warning and then no-ops the target. In the latter case, the presence of the tools is mandatory. But if it was already looked up and discovered to be missing, we did not actually check that it is found before trying to use it. In the case that it isn't found, check again, so that we explicitly error out with a relevant error message due to setting the required flag. Fixes #10320
2022-05-29gettext: explicitly pass source root / subdir as cli argsEli Schwartz
Because this is a wrapper script and we could/should do this, we even have half the infra for it.
2022-03-31i18n: don't let our maintainer targets run via wrapped envEli Schwartz
They are RunTargets because they are one-shot commands without outputs. But we implement them purely via our internal wrapper for gettext, so there is no reason to wrap them *again* in our internal wrapper for meson_exe and set a bunch of environment variables we know we absolutely do not need, use, or want. This avoids the ugly "wrapped due to env" status, and allows users to directly see the command being run without going into despair at obscure pickled nonsense. It also offers a tiny defense against upgrading Meson without reconfiguring. People should not do that, and we error out about this in a bunch of places, but `--internal gettext` has a perfectly stable interface just like most build tools that aren't part of Meson internals, since it uses command line arguments instead of pickling.
2022-03-29Pass environment down to base Target classXavier Claessens
2022-03-06i18n.merge_file: do not disable in the absence of gettext toolsEli Schwartz
Disabling targets because the tools used to build them aren't available is a pretty suspicious thing to do. Users who want this are probably, in general, advised to check themselves whether it is possible to build those targets with find_program(..., required: false) The i18n.gettext() invocation is a bit unusual because the product of running it is non-critical files, specifically, translation catalogs. If users don't have the tools needed to build them, they may not be able to use them either, because perhaps they have NLS disabled on their platform or it's difficult to put it in the bootstrap path. So, for this reason, it was made non-fatal and the message catalogs are just not created, and the resulting build is still perfectly usable *unless* you want to use it in another language, at which point it "works" but the text is all inscrutable to the end user, and that's a feature of the target platform. That's an acceptable tradeoff for translation catalogs. It is NOT an acceptable tradeoff for merge_file, which produces desktop files or MIME database catalogs or other files which have crucial roles to perform, without which the software in question simply doesn't work at all. In such cases, this just fails to install crucial files, users report bugs to the project in question, and the project adds `find_program('xgettext')` to guarantee the hard error due to lack of confidence in Meson. Fixes #6165 Fixes #8436
2022-03-06i18n module: report initial call site when disabling translation supportEli Schwartz
2022-03-06i18n module: detect gettext tools at configure timeEli Schwartz
Use this instead of shutil.which to detect whether they will be available, and pass the ExternalProgram object to CustomTarget invocations, or else make use of the new functionality to specify the correct program path in wrapper scripts. Drop duplicate reporting for itstool missing. Since we use find_program in required mode, its absence is already fatal, and already has a really good error description.
2022-03-06i18n module: fix bug that made msgfmthelper die on combinations of argsEli Schwartz
Due to misuse of argparse in commit 82492f5d765b70cc87385fb887008df89fac878e it was impossible to use both --datadirs and extra args passed directly to msgfmt at the same time. I'm not sure anyone actually knows how argparse works, so misusing it is easy. What is definitely known is that argparse is NOT a POSIX compliant parser and doesn't behave the way you'd expect a standards based parser to handle options. Instead it caters to the easy use case, and hopes and prays you don't need to do anything too complicated "with the wrong kind of complicated". Apparently, this particular type of complicated is when you have mixed option_arguments and operands while simultaneously passing some operands as nargs after a --. It totally breaks, and interprets --datadirs, which is supposed to be an option_argument, as an operand, eats it up as a msgfmt wrapped argument, and breaks. But if you don't pass additional arguments with -- then it interprets --datadirs after operands as an option_argument. This is what we were doing. Instead pass option_arguments before all operands (including the ones specified via `-- ...`). Add test case to pass meaningless datadirs (we don't actually care if $GETTEXTDATADIRS is set to something that doesn't contain gettext data).
2022-01-28build: replace kwargs in CustomTarget initializerDylan Baker
Because we don't want to pass the Interpreter kwargs into the build layer. This turned out to be a mega commit, as there's really on elegant way to make this change in an incremental way. On the nice side, mypy made this change super easy, as nearly all of the calls to `CustomTarget` are fully type checked! It also turns out that we're not handling install_tags in custom_target correctly, since we're not converting the boolean values into Optional values!
2022-01-27flake8: fix indentation styleEli Schwartz
2022-01-22fix broken version annotations for the new itstool_join featureEli Schwartz
It was not added in 0.61.0 as that was already released.
2022-01-21i18n: Add support for joining XML localization via itstoolMatthias Klumpp
2021-12-18i18n: Fix typo for typed_pos_argsMatthias Klumpp
2021-12-02i18n module: correctly annotate the availability of data_dirsEli Schwartz
It was originally forgotten in merge_file() and later added for parity with gettext(). This means that the FeatureNew for each function is different.
2021-11-16i18n: Fix backtrace when missing input kwargXavier Claessens
When input kwarg is missing in i18n.merge_file() it was crashing with a backtrace because of kwargs['input'][0]. That code was useless anyway because CustomTarget now uses first output as default name which is what we need here.
2021-10-04f-stringsEli Schwartz
2021-10-03modules/i18n: fix gettext use of --datadirs paramDan Streetman
The previous commit bd2fcb268b9ff48797bebb6a2ef94d2741234191 accidentally used the wrong var so the param name was missing, leading to an error of "unrecognized arguments" for the datadirs parameter value.
2021-09-30modules/i18n: Fix remaining mypy spotted issuesDylan Baker
2021-09-30modules/i18n: use typed_kwargs for gettextDylan Baker
There were two allowed kwargs that were unused, I've dropped them for now, though I need to check if they were documented. If they are then we need to deprecate them to remove them, otherwise we'll just leave them removed.
2021-09-30modules/i18n: Use typed_kwargs for merge_fileDylan Baker
2021-09-30modules/i18n: use typed_pos_argsDylan Baker
2021-09-30modules/i18n: add easy type annotationsDylan Baker
2021-09-30modules/i18n: sort and clean up importsDylan Baker
2021-09-01make the display name of a gettext translation build, look prettierEli Schwartz
And more accurate too, TBH. Currently it says it is building "lang.mo", even though it is actually building "domain.mo" inside lang/LC_MESSAGES/. Since meson loudly complains if I try to name the display name "lang/domain.mo", name it with a dash instead of a slash. The actual name isn't a priority here IMO, and this is nicely readable.
2021-08-31i18n module: restore the <packagename>-gmo targetEli Schwartz
Removed in commit 487d45c1e5bfff0fbdb4747841db6a0b5b124af9 but perhaps it should not have -- people may have been depending on ensuring those are built somehow. Even though the internal implementation changed and it is now built by the all target, let's keep the old target around too. Now it just aliases the actual build rules, though.