Title: [225216] trunk
Revision
225216
Author
[email protected]
Date
2017-11-28 07:01:22 -0800 (Tue, 28 Nov 2017)

Log Message

Skip back and forward buttons should not hard-code their numeric amount in localised strings
https://bugs.webkit.org/show_bug.cgi?id=180077

Patch by Antoine Quint <[email protected]> on 2017-11-28
Reviewed by Eric Carlson.

Source/WebCore:

Split out the numeric value used in the skip forward and skip back localized strings to make
it easier to localized the numeric value itself.

Test: media/modern-media-controls/localized-strings/replaced-string.html

* English.lproj/modern-media-controls-localized-strings.js:
* Modules/modern-media-controls/main.js:
(UIString):

LayoutTests:

Add a new test to check replaced localized string work as expected.

* media/modern-media-controls/localized-strings/replaced-string-expected.txt: Added.
* media/modern-media-controls/localized-strings/replaced-string.html: Added.
* platform/ios-simulator/TestExpectations:
* platform/mac/TestExpectations:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (225215 => 225216)


--- trunk/LayoutTests/ChangeLog	2017-11-28 14:43:31 UTC (rev 225215)
+++ trunk/LayoutTests/ChangeLog	2017-11-28 15:01:22 UTC (rev 225216)
@@ -1,5 +1,19 @@
 2017-11-28  Antoine Quint  <[email protected]>
 
+        Skip back and forward buttons should not hard-code their numeric amount in localised strings
+        https://bugs.webkit.org/show_bug.cgi?id=180077
+
+        Reviewed by Eric Carlson.
+
+        Add a new test to check replaced localized string work as expected.
+
+        * media/modern-media-controls/localized-strings/replaced-string-expected.txt: Added.
+        * media/modern-media-controls/localized-strings/replaced-string.html: Added.
+        * platform/ios-simulator/TestExpectations:
+        * platform/mac/TestExpectations:
+
+2017-11-28  Antoine Quint  <[email protected]>
+
         Pressing the space bar while watching a fullscreen video doesn't play or pause
         https://bugs.webkit.org/show_bug.cgi?id=180033
         <rdar://problem/33610443>

Added: trunk/LayoutTests/media/modern-media-controls/localized-strings/replaced-string-expected.txt (0 => 225216)


--- trunk/LayoutTests/media/modern-media-controls/localized-strings/replaced-string-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/media/modern-media-controls/localized-strings/replaced-string-expected.txt	2017-11-28 15:01:22 UTC (rev 225216)
@@ -0,0 +1,10 @@
+Testing that we can load a replaced string using UIString.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS UIString('Test replaced string') is "Value 15 should be printed here"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/media/modern-media-controls/localized-strings/replaced-string.html (0 => 225216)


--- trunk/LayoutTests/media/modern-media-controls/localized-strings/replaced-string.html	                        (rev 0)
+++ trunk/LayoutTests/media/modern-media-controls/localized-strings/replaced-string.html	2017-11-28 15:01:22 UTC (rev 225216)
@@ -0,0 +1,14 @@
+<script src=""
+<script src="" type="text/_javascript_"></script>
+<script src="" type="text/_javascript_"></script>
+<script type="text/_javascript_">
+
+description("Testing that we can load a replaced string using UIString.");
+
+UIStrings["##REPLACEMENT_VALUE##"] = "15";
+UIStrings["Test replaced string"] = ["Value %s should be printed here", "##REPLACEMENT_VALUE##"];
+
+shouldBeEqualToString("UIString('Test replaced string')", "Value 15 should be printed here");
+
+</script>
+<script src=""

Modified: trunk/LayoutTests/platform/ios-simulator/TestExpectations (225215 => 225216)


--- trunk/LayoutTests/platform/ios-simulator/TestExpectations	2017-11-28 14:43:31 UTC (rev 225215)
+++ trunk/LayoutTests/platform/ios-simulator/TestExpectations	2017-11-28 15:01:22 UTC (rev 225216)
@@ -56,6 +56,7 @@
 media/modern-media-controls/invalid-placard [ Pass ]
 media/modern-media-controls/layout-item [ Pass ]
 media/modern-media-controls/layout-node [ Pass ]
+media/modern-media-controls/localized-strings [ Pass ]
 media/modern-media-controls/media-controller [ Pass ]
 media/modern-media-controls/media-controls/media-controls-display-above-captions.html [ Pass ]
 media/modern-media-controls/media-documents [ Pass ]

Modified: trunk/LayoutTests/platform/mac/TestExpectations (225215 => 225216)


--- trunk/LayoutTests/platform/mac/TestExpectations	2017-11-28 14:43:31 UTC (rev 225215)
+++ trunk/LayoutTests/platform/mac/TestExpectations	2017-11-28 15:01:22 UTC (rev 225216)
@@ -1453,6 +1453,7 @@
 media/modern-media-controls/invalid-placard [ Pass ]
 media/modern-media-controls/layout-item [ Pass ]
 media/modern-media-controls/layout-node [ Pass ]
+media/modern-media-controls/localized-strings [ Pass ]
 media/modern-media-controls/macos-fullscreen-media-controls/macos-fullscreen-media-controls-drag-is-prevented-over-button.html [ Pass ]
 media/modern-media-controls/macos-fullscreen-media-controls/macos-fullscreen-media-controls-drag.html [ Pass ]
 media/modern-media-controls/macos-fullscreen-media-controls/macos-fullscreen-media-controls-volume-controls-hidden-when-mute-button-disabled.html [ Pass ]

Modified: trunk/Source/WebCore/ChangeLog (225215 => 225216)


--- trunk/Source/WebCore/ChangeLog	2017-11-28 14:43:31 UTC (rev 225215)
+++ trunk/Source/WebCore/ChangeLog	2017-11-28 15:01:22 UTC (rev 225216)
@@ -1,5 +1,21 @@
 2017-11-28  Antoine Quint  <[email protected]>
 
+        Skip back and forward buttons should not hard-code their numeric amount in localised strings
+        https://bugs.webkit.org/show_bug.cgi?id=180077
+
+        Reviewed by Eric Carlson.
+
+        Split out the numeric value used in the skip forward and skip back localized strings to make
+        it easier to localized the numeric value itself.
+
+        Test: media/modern-media-controls/localized-strings/replaced-string.html
+
+        * English.lproj/modern-media-controls-localized-strings.js:
+        * Modules/modern-media-controls/main.js:
+        (UIString):
+
+2017-11-28  Antoine Quint  <[email protected]>
+
         Pressing the space bar while watching a fullscreen video doesn't play or pause
         https://bugs.webkit.org/show_bug.cgi?id=180033
         <rdar://problem/33610443>

Modified: trunk/Source/WebCore/English.lproj/modern-media-controls-localized-strings.js (225215 => 225216)


--- trunk/Source/WebCore/English.lproj/modern-media-controls-localized-strings.js	2017-11-28 14:43:31 UTC (rev 225215)
+++ trunk/Source/WebCore/English.lproj/modern-media-controls-localized-strings.js	2017-11-28 15:01:22 UTC (rev 225216)
@@ -1,4 +1,5 @@
 const UIStrings = {
+    "##SKIP_AMOUNT##": "15",
     "AirPlay": "AirPlay",
     "Audio": "Audio",
     "Audio Controls": "Audio Controls",
@@ -17,8 +18,8 @@
     "Play": "Play",
     "Remaining": "Remaining",
     "Rewind": "Rewind",
-    "Skip Back 15 seconds": "Skip Back 15 seconds",
-    "Skip Forward 15 seconds": "Skip Forward 15 seconds",
+    "Skip Back 15 seconds": ["Skip Back %s seconds", "##SKIP_AMOUNT##"],
+    "Skip Forward 15 seconds": ["Skip Forward %s seconds", "##SKIP_AMOUNT##"],
     "Subtitles": "Subtitles",
     "This video is playing in picture in picture.": "This video is playing in picture in picture.",
     "This video is playing on your Apple TV": "This video is playing on your Apple TV",

Modified: trunk/Source/WebCore/Modules/modern-media-controls/main.js (225215 => 225216)


--- trunk/Source/WebCore/Modules/modern-media-controls/main.js	2017-11-28 14:43:31 UTC (rev 225215)
+++ trunk/Source/WebCore/Modules/modern-media-controls/main.js	2017-11-28 15:01:22 UTC (rev 225216)
@@ -37,17 +37,22 @@
     return new MediaController(shadowRoot, media, host);
 }
 
-function UIString(string)
+function UIString(stringToLocalize)
 {
-    let localizedStrings = {};
+    let allLocalizedStrings = {};
     try {
-        localizedStrings = UIStrings;
+        allLocalizedStrings = UIStrings;
     } catch (error) {}
 
-    if (localizedStrings[string])
-        return localizedStrings[string];
+    const localizedString = allLocalizedStrings[stringToLocalize];
+    if (!localizedString)
+        return stringToLocalize;
 
-    return string;
+    // We allow an array of a string and a replacement.
+    if (Array.isArray(localizedString) && localizedString.length == 2)
+        return localizedString[0].replace("%s", UIString(localizedString[1]));
+
+    return localizedString;
 }
 
 function formatTimeByUnit(value)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to