In the Fox's Den: One small step
Another day, another post. I won’t be able to keep up this pace for long.
In the last post of this series I mentioned that the first important step when working on a big software project is to manage to build it and run it.
After this is done, we may be tempted to try implementing ambitious features and complex refactors. But we should not be getting ahead of ourselves. We have to follow the proper process to make sure that we have a good grasp of the system and how everything fits together.
This was my approach with Firefox development as well. I wanted to make a small change with quick feedback. This would give me a small dopamine hit and encourage me to continue exploring.
Making a change
The good thing about Graphical User Interface (GUI) applications is that they present a lot of text to the user in the form of dialog boxes, menu options and other similar elements that the user interacts with. Thus, a fast and easy way to modify a GUI application is to search for some phrase in the source code files, edit it and see if your change is observable after rebuilding and running the application.
This is not always guaranteed to be successful. Many projects have complex machinery to support internationalization and localization (what we can naively describe as translations), and a simple change to a file containing some text may not propagate cleanly to the final User Interface (UI).
Luckily, this is not the case for Firefox.
My approach was simple.
I tried to think of a unique dialog that would not have much repeated text in other areas of the UI. My first thought was the “About” dialog.
The information text in the middle seemed like a good candidate to search for:
Mozilla is a global community working together to keep the Web open, public and accessible to all.
I picked a part of the phrase and searched for it in the source code. The result was two hits inside the same file.
$ rg 'working together to keep the Web open'
browser/locales/en-US/browser/aboutDialog.ftl
79:community-exp = <label data-l10n-name="community-exp-mozillaLink">{ -vendor-short-name }</label> is a <label data-l10n-name="community-exp-creditsLink">global community</label> working together to keep the Web open, public and accessible to all.
81:community-2 = { -brand-short-name } is designed by <label data-l10n-name="community-mozillaLink">{ -vendor-short-name }</label>, a <label data-l10n-name="community-creditsLink">global community</label> working together to keep the Web open, public and accessible to all.
The obvious match to what I saw in the actual “About” dialog was the first line.
So, I appended some text to it: (Kit was here).
After the usual ceremony of ./mach build and ./mach run, I was able to see my change in the
Firefox UI.
Success. Kit was happy.
Going further
But that is not all. Even though the change was simple and quite fast to figure out, that does not mean that it had no educational value.
I took a closer look at the modified file path: browser/locales/en-US/browser/aboutDialog.ftl
First, the top level directory of the path (i.e. browser) gives us a hint about where most of
the Firefox UI code is located.
Indeed, we will see and explore in the following posts that this is exactly where the UI/UX layer of
Firefox is defined.
Second, the file has an .ftl extension.
Files with this extension are Fluent1 files and are used to streamline the localization of the
project.
In its simplest view a Fluent file is a key-value store.
I could already tell how each store item value is used.
What about the key, though?
I pulled this thread and searched for the key in the codebase.
$ rg '\bcommunity-exp\b'
browser/locales/en-US/browser/aboutDialog.ftl
79:community-exp = <label data-l10n-name="community-exp-mozillaLink">{ -vendor-short-name }</label> is a <label data-l10n-name="community-exp-creditsLink">global community</label> working together to keep the Web open, public and accessible to all.
browser/base/content/aboutDialog.xhtml
122: <description class="text-blurb" id="communityExperimentalDesc" data-l10n-id="community-exp">
123: <label is="text-link" href="https://www.mozilla.org/?utm_source=firefox-browser&utm_medium=firefox-desktop&utm_campaign=about-dialog" data-l10n-name="community-exp-mozillaLink"/>
124: <label is="text-link" useoriginprincipal="true" href="about:credits" data-l10n-name="community-exp-creditsLink"/>
I discovered one additional file: browser/base/content/aboutDialog.xhtml.
I noticed that both files have the same pattern: name.{extension}.
I was onto something, so I did one last search to find all such files.
$ fd 'aboutDialog\.'
browser/locales/en-US/browser/aboutDialog.ftl
browser/branding/unofficial/content/aboutDialog.css
browser/branding/official/content/aboutDialog.css
browser/branding/nightly/content/aboutDialog.css
browser/branding/aurora/content/aboutDialog.css
browser/base/content/aboutDialog.xhtml
browser/base/content/aboutDialog.js
browser/base/content/aboutDialog.css
And there it all was.
I found files with .js, .xhtml, .css and .ftl extensions.
I didn’t need to look any deeper for the time being, such as finding out the specific binding
details.
I already had a pretty good feeling about how the various components are generated.
The .xhtml file describes the HTML structure, the .css file provides some styling, the .js
file describes some runtime logic and the .ftl holds all translatable text segments to enable the
localization of the UI.
My findings will be useful in my future attempts to modify and contribute to the project.
Conclusion
The takeaway is that, even in the process of a simple change, we can still gain valuable information about a system. We improve our understanding and make future modifications easier and faster to make. By probing the source code with simple command line tools, we can start creating a mental image of the project that will make it possible to recognize areas of friction and suggest improvements in the future.
Do not underestimate the lessons that even the smallest amount of work can teach us.
Keep hacking and see you at the next episode.
-
Fluent is a modern localization system introduced into the Gecko platform with a focus on quality, performance, maintenance and completeness. ↩
It is part of a series of posts that aim to explore the Mozilla Firefox source code. Check them out here.