Skip to content

Commit

Permalink
i18n: add macro my_gettext(), do not define "gettext"
Browse files Browse the repository at this point in the history
Defining the macro "gettext" can cause breakages if the C++ standard
library happens to include libintl.h (which GCC 14 does).
  • Loading branch information
MaxKellermann committed Jul 23, 2024
1 parent c26f4c0 commit 249b62f
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Command.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ get_cmds_max_name_width()
const char *
get_key_description(Command command)
{
return gettext(cmds[size_t(command)].description);
return my_gettext(cmds[size_t(command)].description);
}

const char *
Expand Down
6 changes: 3 additions & 3 deletions src/HelpPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ HelpPage::GetListItemText(char *, size_t, unsigned i) const noexcept
assert(i < std::size(help_text));

if (row->text != nullptr)
return gettext(row->text);
return my_gettext(row->text);

if (row->command != Command::NONE)
return get_key_description(row->command);
Expand Down Expand Up @@ -272,7 +272,7 @@ HelpPage::PaintListItem(WINDOW *w, unsigned i,

if (row->command == Command::NONE) {
if (row->text != nullptr)
mvwaddstr(w, y, 6, gettext(row->text));
mvwaddstr(w, y, 6, my_gettext(row->text));
else if (row->highlight == 2)
mvwhline(w, y, 3, ACS_HLINE, width - 6);
} else {
Expand All @@ -285,7 +285,7 @@ HelpPage::PaintListItem(WINDOW *w, unsigned i,
mvwaddch(w, y, 21, ':');
mvwaddstr(w, y, 23,
row->text != nullptr
? gettext(row->text)
? my_gettext(row->text)
: get_key_description(row->command));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/KeyDefPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ CommandListPage::GetListItemText(char *buffer, size_t size,

snprintf(buffer + get_cmds_max_name_width(),
size - get_cmds_max_name_width(),
" - %s", gettext(get_command_definitions()[idx].description));
" - %s", my_gettext(get_command_definitions()[idx].description));

return buffer;
}
Expand Down
6 changes: 3 additions & 3 deletions src/SearchPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class SearchHelpText final : public ListText {
" %s : %s [%s]",
GetGlobalKeyBindings().GetKeyNames(Command::SEARCH_MODE).c_str(),
get_key_description(Command::SEARCH_MODE),
gettext(mode[options.search_mode].label));
my_gettext(mode[options.search_mode].label));
return buffer;
}

Expand Down Expand Up @@ -453,7 +453,7 @@ SearchPage::GetTitle(char *str, size_t size) const noexcept
"%s '%s' [%s]",
_("Search"),
pattern.c_str(),
gettext(mode[options.search_mode].label));
my_gettext(mode[options.search_mode].label));
else
return _("Search");

Expand All @@ -478,7 +478,7 @@ SearchPage::OnCommand(struct mpdclient &c, Command cmd)
if (mode[options.search_mode].label == nullptr)
options.search_mode = 0;
screen_status_printf(_("Search mode: %s"),
gettext(mode[options.search_mode].label));
my_gettext(mode[options.search_mode].label));

if (pattern.empty())
/* show the new mode in the help text */
Expand Down
8 changes: 4 additions & 4 deletions src/SongPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,14 @@ static std::unique_ptr<Page>
screen_song_init(ScreenManager &_screen, WINDOW *w, Size size) noexcept
{
for (unsigned i = 0; tag_labels[i].label != nullptr; ++i) {
unsigned width = StringWidthMB(gettext(tag_labels[i].label));
unsigned width = StringWidthMB(my_gettext(tag_labels[i].label));
if (width > max_tag_label_width)
max_tag_label_width = width;
}

for (unsigned i = 0; i < std::size(stats_labels); ++i) {
if (stats_labels[i] != nullptr) {
unsigned width = StringWidthMB(gettext(stats_labels[i]));
unsigned width = StringWidthMB(my_gettext(stats_labels[i]));

if (width > max_stats_label_width)
max_stats_label_width = width;
Expand Down Expand Up @@ -267,7 +267,7 @@ get_tag_label(unsigned tag) noexcept
{
for (unsigned i = 0; tag_labels[i].label != nullptr; ++i)
if (tag_labels[i].tag_type == tag)
return gettext(tag_labels[i].label);
return my_gettext(tag_labels[i].label);

assert(tag < MPD_TAG_COUNT);
return mpd_tag_name((enum mpd_tag_type)tag);
Expand Down Expand Up @@ -351,7 +351,7 @@ SongPage::AddSong(const struct mpd_song *song) noexcept
void
SongPage::AppendStatsLine(enum stats_label label, const char *value) noexcept
{
AppendLine(gettext(stats_labels[label]), value, max_stats_label_width);
AppendLine(my_gettext(stats_labels[label]), value, max_stats_label_width);
}

bool
Expand Down
2 changes: 1 addition & 1 deletion src/TabBar.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PaintTabBar(WINDOW *w, const PageMeta &current_page_meta,
title = current_page_title;

if (title == nullptr)
title = gettext(page->title);
title = my_gettext(page->title);

PaintPageTab(w, page->command, title,
page == &current_page_meta);
Expand Down
8 changes: 3 additions & 5 deletions src/i18n.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project

#ifndef I18N_H
#define I18N_H
#pragma once

#include "config.h"

#ifdef ENABLE_NLS

#include <libintl.h> // IWYU pragma: export

#define my_gettext(x) gettext(x)
#define _(x) gettext(x)

#ifdef gettext_noop
Expand All @@ -19,12 +19,10 @@
#endif

#else
#define gettext(x) (x)
#define my_gettext(x) (x)
#define _(x) x
#define N_(x) x
#endif

#define YES_TRANSLATION _("y")
#define NO_TRANSLATION _("n")

#endif

0 comments on commit 249b62f

Please sign in to comment.