feat(i18n): show the new language when the session language changes

main
reionwong 1 week ago
parent 1d6cc1dbe9
commit f4e7e33fba

@ -242,6 +242,7 @@ SettingsWindow::SettingsWindow()
};
// A press anywhere outside the search field takes the focus off it.
m_window->onPointerPressed = [this](PointF position, MouseButton) { m_sidebar->releaseSearch(position); };
m_languageChanged = Application::instance()->languageChanged.connect([this] { retranslate(); });
for (const PageInfo& page : pages()) {
const bool sidebarPage = !page.category.empty();
@ -371,6 +372,16 @@ void SettingsWindow::showHistoryEntry(int index)
updateHeader();
}
void SettingsWindow::retranslate()
{
m_window->setTitle(tr("Settings"));
m_sidebar->retranslate();
if (m_historyIndex >= 0)
showHistoryEntry(m_historyIndex);
else
updateHeader();
}
void SettingsWindow::updateHeader()
{
m_back->setEnabled(canGoBack());

@ -90,6 +90,7 @@ private:
void updateHeader();
void updateBackground();
bool isReady() const;
void retranslate();
std::unique_ptr<cutefish::ui::Window> m_window;
SettingsRoot* m_root;
@ -108,6 +109,7 @@ private:
std::string m_pendingWifiJoin;
std::unique_ptr<cutefish::base::Timer> m_revealTimer;
bool m_revealed = false;
cutefish::base::Subscription m_languageChanged;
};
} // namespace settings

@ -316,6 +316,14 @@ void Sidebar::setEntries(std::vector<const PageInfo*> entries)
updateResults();
}
void Sidebar::retranslate()
{
m_title->setText(tr("Settings"));
m_search->setPlaceholder(tr("Search"));
m_noResults->setText(tr("No results"));
setEntries(m_entries);
}
void Sidebar::setSubPageAvailable(const std::string& id, bool available)
{
auto it = std::find(m_unavailableSubPages.begin(), m_unavailableSubPages.end(), id);

@ -32,6 +32,8 @@ public:
// The sidebar pages shown, in order.
void setEntries(std::vector<const PageInfo*> entries);
// Takes its text again after the session language changed.
void retranslate();
const std::vector<const PageInfo*>& entries() const { return m_entries; }
// Sub pages whose entry is unavailable stay out of search results.
void setSubPageAvailable(const std::string& id, bool available);

@ -5,6 +5,7 @@
#include <string>
#include "ui/application.h"
#include "ui/keys.h"
#include "ui/layout.h"
#include "ui/test_input.h"
@ -105,6 +106,19 @@ TEST_F(Fixture, HistoryGoesBackAndForward)
EXPECT_FALSE(settingsWindow->canGoForward());
}
TEST_F(Fixture, LanguageChangeMakesThePageAgain)
{
settingsWindow->switchToPage("dock");
settingsWindow->pushPage("hotcorners");
const Page* before = settingsWindow->currentPage();
Application::instance()->languageChanged.emit();
window().grab();
EXPECT_NE(settingsWindow->currentPage(), before);
EXPECT_NE(dumpLine(window(), "page:hotcorners"), "");
EXPECT_TRUE(settingsWindow->canGoBack());
EXPECT_FALSE(settingsWindow->canGoForward());
}
TEST_F(Fixture, BackAndForwardKeys)
{
settingsWindow->switchToPage("about");

Loading…
Cancel
Save