Skip to content

Commit

Permalink
Update moz.l10n, add hacky verbose resource diff (#96)
Browse files Browse the repository at this point in the history
* Update moz.l10n, add hacky verbose diff

* Fix standalone comment spacing in .properties files
  • Loading branch information
eemeli authored Nov 22, 2024
1 parent 0a749c1 commit 0259250
Show file tree
Hide file tree
Showing 47 changed files with 133 additions and 7 deletions.
53 changes: 47 additions & 6 deletions .github/scripts/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
from os import walk
from os.path import commonpath, exists, join, relpath
from sys import exit
from typing import Any, cast

from moz.l10n.resource import UnsupportedResource, l10n_equal, parse_resource
from moz.l10n.resource.data import Resource
from moz.l10n.resource.l10n_equal import l10n_meta, l10n_sections


def diff_tree(a_root: str, b_root: str, ignore: set[str]) -> int:
def diff_tree(a_root: str, b_root: str, ignore: set[str], verbose: bool) -> int:
common_root = commonpath((a_root, b_root))
diff_count = 0
b_seen: set[str] = set()
Expand All @@ -32,8 +35,7 @@ def diff_tree(a_root: str, b_root: str, ignore: set[str]) -> int:
if not exists(b_path):
print(f"Missing file: {relpath(b_path, common_root)}")
diff_count += 1
elif not l10n_equal_paths(a_path, b_path):
print(f"Files at {rel_path} differ")
elif not l10n_equal_paths(rel_path, a_path, b_path, verbose):
diff_count += 1
b_seen.add(b_path)
for dirpath, dirnames, filenames in walk(b_root):
Expand All @@ -49,7 +51,7 @@ def diff_tree(a_root: str, b_root: str, ignore: set[str]) -> int:
return diff_count


def l10n_equal_paths(a_path: str, b_path: str) -> bool:
def l10n_equal_paths(rel_path: str, a_path: str, b_path: str, verbose: bool) -> bool:
with open(a_path, "rb") as a_file:
a_bytes = a_file.read()
with open(b_path, "rb") as b_file:
Expand All @@ -76,15 +78,54 @@ def l10n_equal_paths(a_path: str, b_path: str) -> bool:
print(f"Parse error at {a_path}")
return False

return l10n_equal(a_res, b_res)
eq = l10n_equal(a_res, b_res)
if not eq:
print(f"Files at {rel_path} differ")
if verbose:
for line in HACK_l10n_compare(a_res, b_res):
print(" " + line)
return eq


def HACK_l10n_compare(a: Resource[Any, Any], b: Resource[Any, Any]) -> list[str]:
"""
Hacky diff of L10n resources.
Abuses `pytest` internal utilities.
"""
try:
from _pytest.assertion.util import _compare_eq_any
except ImportError:
raise SystemExit('pytest is required for verbose diffs')

def compare(prefix: str, left: Any, right: Any) -> list[str]:
highlight = cast(Any, lambda src, lexer=None: src)
res = _compare_eq_any(left, right, highlight, 1)
if "Full diff:" in res:
res = res[res.index("Full diff:") + 1 :]
return (
[f"{prefix}: {line}" if prefix else line for line in res]
if any(line.startswith(("-", "+")) for line in res)
else []
)

explanation: list[str] = []
explanation.extend(compare("format", a.format, b.format))
explanation.extend(compare("comment", a.comment.strip(), b.comment.strip()))
explanation.extend(compare("meta", l10n_meta(a), l10n_meta(b)))
explanation.extend(compare("", l10n_sections(a), l10n_sections(b)))
return explanation


if __name__ == "__main__":
parser = ArgumentParser(description=__doc__)
parser.add_argument("path", nargs=2, help="Root directories for the comparison")
parser.add_argument("--ignore", nargs="*", help="Relative paths to ignore")
parser.add_argument(
"-v", "--verbose", action="store_true", help="Verbose diff (requires pytest)"
)
args = parser.parse_args()

ignore = set(args.ignore) if args.ignore else set()
if diff_tree(args.path[0], args.path[1], ignore):
if diff_tree(args.path[0], args.path[1], ignore, args.verbose):
exit(1)
2 changes: 1 addition & 1 deletion .github/scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
moz.l10n ~= 0.3.0
moz.l10n ~= 0.5.3
tomli-w ~= 1.0
8 changes: 8 additions & 0 deletions browser/chrome/browser/browser.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ openFile = Open File
droponhometitle = Set Home Page
droponhomemsg = Do you want this document to be your new home page?
droponhomemsgMultiple = Do you want these documents to be your new home pages?

# context menu strings

# LOCALIZATION NOTE (contextMenuSearch): %1$S is the search engine,
# %2$S is the selection string.
contextMenuSearch = Search %1$S for “%2$S”
Expand All @@ -19,7 +21,9 @@ contextMenuPrivateSearch.accesskey = h
# this engine is different from the default engine name used in normal mode.
contextMenuPrivateSearchOtherEngine = Search with %S in a Private Window
contextMenuPrivateSearchOtherEngine.accesskey = h

# bookmark dialog strings

bookmarkAllTabsDefault = [Folder Name]
unsignedAddonsDisabled.message = One or more installed add-ons cannot be verified and have been disabled.
unsignedAddonsDisabled.learnMore.label = Learn More
Expand Down Expand Up @@ -252,7 +256,9 @@ protections.footer.blockedTrackerCounter.tooltip = Since %S
# #3 is replaced by a locale-formatted date with short month and numeric year.
# In English this looks like "Firefox blocked over 10,000 trackers since Oct 2019"
protections.milestone.description = #1 blocked #2 tracker since #3;#1 blocked over #2 trackers since #3

# Application menu

# LOCALIZATION NOTE(zoomReduce-button.tooltip): %S is the keyboard shortcut.
zoomReduce-button.tooltip = Zoom out (%S)
# LOCALIZATION NOTE(zoomReset-button.tooltip): %S is the keyboard shortcut.
Expand All @@ -265,7 +271,9 @@ cut-button.tooltip = Cut (%S)
copy-button.tooltip = Copy (%S)
# LOCALIZATION NOTE (paste-button.tooltip): %S is the keyboard shortcut.
paste-button.tooltip = Paste (%S)

# Geolocation UI

geolocation.allow = Allow
geolocation.allow.accesskey = A
geolocation.block = Block
Expand Down
1 change: 1 addition & 0 deletions browser/chrome/browser/syncSetup.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# Several other strings are used (via Weave.Status.login), but they come from
# /services/sync

# Firefox Accounts based setup.
continue.label = Continue
relinkVerify.title = Merge Warning
Expand Down
2 changes: 2 additions & 0 deletions browser/extensions/formautofill/formautofill.properties
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ savedCreditCardsBtnLabel = Saved Credit Cards…
autofillReauthCheckboxMac = Require macOS authentication to autofill, view, or edit stored credit cards.
autofillReauthCheckboxWin = Require Windows authentication to autofill, view, or edit stored credit cards.
autofillReauthCheckboxLin = Require Linux authentication to autofill, view, or edit stored credit cards.

# LOCALIZATION NOTE (savedAddressesBtnLabel): Label for the button that opens a dialog that shows the
# list of saved addresses.

# LOCALIZATION NOTE (autofillReauthOSDialogMac): This string is
# preceded by the operating system (macOS) with "Firefox is trying to ", and
# has a period added to its end. Make sure to test in your locale.
Expand Down
5 changes: 5 additions & 0 deletions browser/installer/custom.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# LOCALIZATION NOTE:

# This file must be saved as UTF8

# Accesskeys are defined by prefixing the letter that is to be used for the
# accesskey with an ampersand (e.g. &).

# Do not replace $BrandShortName, $BrandFullName, or $BrandFullNameDA with a
# custom string and always use the same one as used by the en-US files.
# $BrandFullNameDA allows the string to contain an ampersand (e.g. DA stands
# for double ampersand) and prevents the letter following the ampersand from
# being used as an accesskey.

# You can use \n to create a newline in the string but only when the string
# from en-US contains a \n.

REG_APP_DESC = $BrandShortName delivers safe, easy web browsing. A familiar user interface, enhanced security features including protection from online identity theft, and integrated search let you get the most out of the web.
BRIEF_APP_DESC = Fast and private web browsing
# LOCALIZATION NOTE:
Expand Down
6 changes: 6 additions & 0 deletions browser/installer/mui.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@

# To make the l10n tinderboxen see changes to this file you can change a value
# name by adding - to the end of the name followed by chars (e.g. Branding-2).

# LOCALIZATION NOTE:

# This file must be saved as UTF8

# Accesskeys are defined by prefixing the letter that is to be used for the
# accesskey with an ampersand (e.g. &).

# Do not replace $BrandShortName, $BrandFullName, or $BrandFullNameDA with a
# custom string and always use the same one as used by the en-US files.
# $BrandFullNameDA allows the string to contain an ampersand (e.g. DA stands
# for double ampersand) and prevents the letter following the ampersand from
# being used as an accesskey.

# You can use \n to create a newline in the string but only when the string
# from en-US contains a \n.

MUI_TEXT_WELCOME_INFO_TITLE = Welcome to the $BrandFullNameDA Setup Wizard
MUI_TEXT_WELCOME_INFO_TEXT = This wizard will guide you through the installation of $BrandFullNameDA.\n\nIt is recommended that you close all other applications before starting Setup. This will make it possible to update relevant system files without having to reboot your computer.\n\n$_CLICK
MUI_TEXT_COMPONENTS_TITLE = Choose Components
Expand Down
4 changes: 4 additions & 0 deletions browser/installer/nsisstrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# LOCALIZATION NOTE:

# This file must be saved as UTF8

# Do not replace $BrandShortName, $BrandProductName, $BrandFullName,
# or $BrandFullNameDA with a custom string and always use the same one as used
# by the en-US files.
# $BrandFullNameDA allows the string to contain an ampersand (e.g. DA stands
# for double ampersand) and prevents the letter following the ampersand from
# being used as an accesskey.

# You can use \n to create a newline in the string but only when the string
# from en-US contains a \n.

INSTALLER_WIN_CAPTION = $BrandShortName Installer
STUB_CLEANUP_PAVEOVER_HEADER2 = $BrandShortName is already installed. Let’s update it.
STUB_CLEANUP_REINSTALL_HEADER2 = $BrandShortName has been installed before. Let’s get you a new copy.
Expand Down
6 changes: 6 additions & 0 deletions browser/installer/override.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# LOCALIZATION NOTE:

# This file must be saved as UTF8

# Accesskeys are defined by prefixing the letter that is to be used for the
# accesskey with an ampersand (e.g. &).

# Do not replace $BrandShortName, $BrandFullName, or $BrandFullNameDA with a
# custom string and always use the same one as used by the en-US files.
# $BrandFullNameDA allows the string to contain an ampersand (e.g. DA stands
# for double ampersand) and prevents the letter following the ampersand from
# being used as an accesskey.

# You can use \n to create a newline in the string but only when the string
# from en-US contains a \n.

# Strings that require a space at the end should be enclosed with double
# quotes and the double quotes will be removed. To add quotes to the beginning
# and end of a strong enclose the add and additional double quote to the
# beginning and end of the string (e.g. ""This will include quotes"").

SetupCaption = $BrandFullName Setup
UninstallCaption = $BrandFullName Uninstall
BackBtn = < &Back
Expand Down
1 change: 1 addition & 0 deletions devtools/client/accessibility.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# You want to make that choice consistent across the developer tools.
# A good criteria is the language in which you'd find the best
# documentation on web development on the web.

# LOCALIZATION NOTE (accessibility.role): A title text used for Accessibility
# tree header column that represents accessible element role.
accessibility.role = Role
Expand Down
1 change: 1 addition & 0 deletions devtools/client/animationinspector.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# You want to make that choice consistent across the developer tools.
# A good criteria is the language in which you'd find the best
# documentation on web development on the web.

# LOCALIZATION NOTE (panel.noAnimation):
# This is the label shown in the panel when there are no displayable animations.
# (e.g. In case of user selected a non-element node or a node that is not animated).
Expand Down
2 changes: 2 additions & 0 deletions devtools/client/boxmodel.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

# LOCALIZATION NOTE : FILE This file contains the Layout View strings.
# The Layout View is a panel displayed in the computed view tab of the Inspector sidebar.

# LOCALIZATION NOTE : FILE The correct localization of this file might be to
# keep it in English, or another language commonly spoken among web developers.
# You want to make that choice consistent across the developer tools.
# A good criteria is the language in which you'd find the best
# documentation on web development on the web.

# LOCALIZATION NOTE (boxmodel.title) This is the title of the box model panel and is
# displayed as a label.
boxmodel.title = Box Model
Expand Down
1 change: 1 addition & 0 deletions devtools/client/changes.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# LOCALIZATION NOTE This file contains the strings for the Changes panel accessible from
# the Inspector sidebar.

# LOCALIZATION NOTE (changes.noChanges): This text is shown when no changes are available.
changes.noChanges = No changes found.
# LOCALIZATION NOTE (changes.noChangesDescription): This text is shown when no changes are
Expand Down
1 change: 1 addition & 0 deletions devtools/client/components.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# LOCALIZATION NOTE These strings are used in the shared React components,
# so files in `devtools/client/shared/components/*`.

# LOCALIZATION NOTE (frame.unknownSource): When we do not know the source filename of
# a frame, we use this string instead.
frame.unknownSource = (unknown)
Expand Down
1 change: 1 addition & 0 deletions devtools/client/debugger.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# You want to make that choice consistent across the developer tools.
# A good criteria is the language in which you'd find the best
# documentation on web development on the web.

# LOCALIZATION NOTE (collapseSources): This is the tooltip for the button
# that collapses the Sources and Outlines panes in the debugger UI.
collapseSources = Collapse Sources and Outline panes
Expand Down
1 change: 1 addition & 0 deletions devtools/client/device.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# that choice consistent across the developer tools. A good criteria is the
# language in which you'd find the best documentation on web development on the
# web.

# LOCALIZATION NOTE:
# These strings are category names in a list of devices that a user can choose
# to simulate (e.g. "ZTE Open C", "VIA Vixen", "720p HD Television", etc).
Expand Down
1 change: 1 addition & 0 deletions devtools/client/dom.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# You want to make that choice consistent across the developer tools.
# A good criteria is the language in which you'd find the best
# documentation on web development on the web.

# LOCALIZATION NOTE (dom.filterDOMPanel): A placeholder text used for
# DOM panel search box.
dom.filterDOMPanel = Filter DOM Panel
Expand Down
1 change: 1 addition & 0 deletions devtools/client/filterwidget.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# LOCALIZATION NOTE These strings are used in the CSS Filter Editor Widget
# which can be found in a tooltip that appears in the Rule View when clicking
# on a filter swatch displayed next to CSS declarations like 'filter: blur(2px)'.

# LOCALIZATION NOTE (emptyFilterList):
# This string is displayed when filter's list is empty
# (no filter specified / all removed)
Expand Down
1 change: 1 addition & 0 deletions devtools/client/font-inspector.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# LOCALIZATION NOTE This file contains the Font Inspector strings.
# The Font Inspector is a panel accessible in the Inspector sidebar.

# LOCALIZATION NOTE (fontinspector.system) This label indicates that the font is a local
# system font.
fontinspector.system = system
Expand Down
1 change: 1 addition & 0 deletions devtools/client/har.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# You want to make that choice consistent across the developer tools.
# A good criteria is the language in which you'd find the best
# documentation on web development on the web.

# LOCALIZATION NOTE (har.responseBodyNotIncluded): A label used within
# HAR file explaining that HTTP response bodies are not includes
# in exported data.
Expand Down
1 change: 1 addition & 0 deletions devtools/client/inspector.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# You want to make that choice consistent across the developer tools.
# A good criteria is the language in which you'd find the best
# documentation on web development on the web.

inspector.panelLabel.markupView = Markup View
# LOCALIZATION NOTE (markupView.more.showing)
# When there are too many nodes to load at once, we will offer to
Expand Down
2 changes: 2 additions & 0 deletions devtools/client/jsonview.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
# LOCALIZATION NOTE These strings are used in the JSON View tool
# that is used to inspect application/json document types loaded
# in the browser.

# LOCALIZATION NOTE The correct localization of this file might be to keep it
# in English, or another language commonly spoken among web developers.
# You want to make that choice consistent across the developer tools.
# A good criteria is the language in which you'd find the best documentation
# on web development on the web.

# LOCALIZATION NOTE (jsonViewer.tab.JSON, jsonViewer.tab.RawData,
# jsonViewer.tab.Headers): Label for a panel tab.
jsonViewer.tab.JSON = JSON
Expand Down
1 change: 1 addition & 0 deletions devtools/client/layout.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# LOCALIZATION NOTE This file contains the Layout Inspector strings.
# The Layout Inspector is a panel accessible in the Inspector sidebar.

# LOCALIZATION NOTE (flexbox.header): The accordion header for the Flexbox panel when
# no flex container or item is selected.
flexbox.header = Flexbox
Expand Down
1 change: 1 addition & 0 deletions devtools/client/memory.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# You want to make that choice consistent across the developer tools.
# A good criteria is the language in which you'd find the best
# documentation on web development on the web.

# LOCALIZATION NOTE (snapshot.io.save): The label for the link that saves a
# snapshot to disk.
snapshot.io.save = Save
Expand Down
1 change: 1 addition & 0 deletions devtools/client/netmonitor.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# You want to make that choice consistent across the developer tools.
# A good criteria is the language in which you'd find the best
# documentation on web development on the web.

# LOCALIZATION NOTE (netmonitor.security.state.secure)
# This string is used as an tooltip for request that was performed over secure
# channel i.e. the connection was encrypted.
Expand Down
1 change: 1 addition & 0 deletions devtools/client/network-throttling.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# You want to make that choice consistent across the developer tools.
# A good criteria is the language in which you'd find the best
# documentation on web development on the web.

# LOCALIZATION NOTE (responsive.noThrottling): UI option in a menu to configure
# network throttling. This option is the default and disables throttling so you
# just have normal network conditions. There is not very much room in the UI
Expand Down
Loading

0 comments on commit 0259250

Please sign in to comment.