Skip to content

Commit

Permalink
I18N: Do not mark empty strings for a translation
Browse files Browse the repository at this point in the history
An empty string has a special meaning in gettext and marking such
string produces invalid catalogs with a duplicate message ID entry.

We cannot use simply Error("") necause Error() expects
BgettextMessage argument. Therefore I added EMPTY_MESSAGE macro which
expands to the same as M_(""), but is not caught by xgettext.

I think it's cleaner solution than overriding xgettext behaviour for
that line of code. For aesthetic reasons I also disabled clang-format
at two places.

Fixes: #1158
  • Loading branch information
ppisar authored and m-blaha committed Jan 12, 2024
1 parent 9111440 commit 5a8f2df
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions include/libdnf5/utils/bgettext/bgettext-mark-domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "bgettext-mark-common.h"

// clang-format off
// Use EMPTY_MESSAGE instead of M_(""). Otherwise, xgettext breaks catalogs.
#define EMPTY_MESSAGE \
{ .bgettextMsg = "\004" GETTEXT_DOMAIN "\00" "" }
#define M_(msgId) \
{ .bgettextMsg = "\004" GETTEXT_DOMAIN "\00" msgId }
#define MP_(msgId, msgIdPlural) \
Expand All @@ -34,5 +38,6 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
{ .bgettextMsg = "\006" GETTEXT_DOMAIN "\00" context "\004" msgId }
#define MCP_(context, msgId, msgIdPlural) \
{ .bgettextMsg = "\007" GETTEXT_DOMAIN "\00" context "\004" msgId "\00" msgIdPlural }
//clang-format on

#endif /* _BGETTEXT_MARK_DOMAIN_H_ */
5 changes: 5 additions & 0 deletions include/libdnf5/utils/bgettext/bgettext-mark.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "bgettext-mark-common.h"

// clang-format off
// Use EMPTY_MESSAGE instead of M_(""). Otherwise, xgettext breaks catalogs.
#define EMPTY_MESSAGE \
{ .bgettextMsg = "\000" "" }
#define M_(msgId) \
{ .bgettextMsg = "\000" msgId }
#define MP_(msgId, msgIdPlural) \
Expand All @@ -30,5 +34,6 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
{ .bgettextMsg = "\002" context "\004" msgId }
#define MCP_(context, msgId, msgIdPlural) \
{ .bgettextMsg = "\003" context "\004" msgId "\00" msgIdPlural }
// clang-format on

#endif /* _BGETTEXT_MARK_H_ */
2 changes: 1 addition & 1 deletion libdnf5-cli/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ const char * GoalResolveError::what() const noexcept {
return message.c_str();
}

SilentCommandExitError::SilentCommandExitError(int exit_code) : Error(M_("")), exit_code(exit_code) {}
SilentCommandExitError::SilentCommandExitError(int exit_code) : Error(EMPTY_MESSAGE), exit_code(exit_code) {}

} // namespace libdnf5::cli

0 comments on commit 5a8f2df

Please sign in to comment.