commit 2d3eb0655bcdf9b67117a3f3fb36dd6c0a0ad246
parent af02c8c08aea65a83ff81820b8a520a73d75377c
Author: stransky <stransky@redhat.com>
Date: Thu, 9 Oct 2025 18:06:51 +0000
Bug 1744641 [Linux] Add wake lock strings localization r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D266646
Diffstat:
2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/dom/locales/en-US/chrome/dom/dom.properties b/dom/locales/en-US/chrome/dom/dom.properties
@@ -479,3 +479,8 @@ PreviousInterceptCallOptionOverriddenWarning=The ā%1$Sā option for a previou
# LOCALIZATION NOTE: Do not translate "Window.fullScreen".
FullscreenAttributeWarning=Window.fullScreen attribute is deprecated and will be removed in the future.
+
+# LOCALIZATION NOTE: Wake lock related strings for system notifications
+WakeLockVideoPlaying=Playing video
+WakeLockAudioPlaying=Playing audio
+
diff --git a/widget/gtk/WakeLockListener.cpp b/widget/gtk/WakeLockListener.cpp
@@ -10,6 +10,10 @@
#include "WakeLockListener.h"
#include "WidgetUtilsGtk.h"
#include "mozilla/ScopeExit.h"
+#include "mozilla/Services.h"
+#include "nsIStringBundle.h"
+#include "nsReadableUtils.h"
+#include "nsContentUtils.h"
#ifdef MOZ_ENABLE_DBUS
# include <gio/gio.h>
@@ -54,6 +58,16 @@ using namespace mozilla::widget;
NS_IMPL_ISUPPORTS(WakeLockListener, nsIDOMMozWakeLockListener)
+static nsCString GetLocalizedWakeLockString(const char* aStringName) {
+ nsAutoString localizedString;
+ nsresult rv = nsContentUtils::GetLocalizedString(
+ nsContentUtils::eDOM_PROPERTIES, aStringName, localizedString);
+ if (NS_FAILED(rv)) {
+ return nsCString();
+ }
+ return NS_ConvertUTF16toUTF8(localizedString);
+}
+
#define WAKE_LOCK_LOG(str, ...) \
MOZ_LOG(gLinuxWakeLockLog, mozilla::LogLevel::Debug, \
("[%p] " str, this, ##__VA_ARGS__))
@@ -146,9 +160,23 @@ class WakeLockTopic {
CopyUTF16toUTF8(aTopic, mTopic);
WAKE_LOCK_LOG("WakeLockTopic::WakeLockTopic() created %s", mTopic.get());
if (mTopic.Equals("video-playing")) {
- mNiceTopic = "Playing video";
+ static nsCString videoPlayingString = []() -> nsCString {
+ auto string = GetLocalizedWakeLockString("WakeLockVideoPlaying");
+ if (string.IsEmpty()) {
+ string = "Playing video";
+ }
+ return string;
+ }();
+ mNiceTopic = videoPlayingString;
} else if (mTopic.Equals("audio-playing")) {
- mNiceTopic = "Playing audio";
+ static nsCString audioPlayingString = []() -> nsCString {
+ auto string = GetLocalizedWakeLockString("WakeLockAudioPlaying");
+ if (string.IsEmpty()) {
+ string = "Playing audio";
+ }
+ return string;
+ }();
+ mNiceTopic = audioPlayingString;
}
if (sWakeLockType == Initial) {
InitializeWakeLockType();