Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

2294 pontoon to webextension #2358

Merged

Conversation

jaredhirsch
Copy link
Member

This is built on top of the string extraction commit from #2344, which hasn't landed yet.

Commit message pretty much says it all:


Add pontoon strings & build step to transform into webextension strings

  • Add pontoon-to-webext.js script from bwinton/SnoozeTabs repo and
    related npm dependencies (to be removed when/if that script is
    published on npm as a standalone module).

  • Add extracted strings to a properties file at the location expected by
    Pontoon.

  • Add a pontoon-to-webextension build step to the Makefile

  • Also, replace the hand made messages.json with the more nicely-formatted
    script output.

This commit, together with the fix for #2344, closes #2294.

Makefile Outdated
@@ -35,6 +35,9 @@ imgs_server_dest := $(imgs_source:%=build/server/%)

raven_source := $(shell node -e 'console.log(require.resolve("raven-js/dist/raven.js"))')

l10n_source := $(wildcard locales/*/*.properties)
l10n_dest := $(l10n_source:%/*.properties=addon/webextension/_locales/%/messages.json)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about this, but make doesn't seem to complain, so I guess it's alright?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right to me, but I'm not sure. What should the value of $(l10n_source) be? If it's like locales/en-US/something.properties locales/es-ES/something.properties and you want to get addon/webextensions/_locales/en-US/messages.json addon/webextensions/_locales/en-US/messages.json then it's right. This presumes that each directory has only one properties file and that it's name isn't important.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking we'd eventually have multiple properties files in this directory, hence the double wildcard. However, now that I think about it, we would only ever want to package up the addon's strings in the addon...so I'll update this to grab $(wildcard locales/*/webextension.properties)

@jaredhirsch
Copy link
Member Author

@flodolo Hi, here's the other localization step, with the strings translated into Pontoon-ready .properties format. Comments again appreciated. The pontoon-to-webext script from snooze tabs worked perfectly, thanks for the suggestion 👍 (and huge thanks to @lmorchard for writing such a great tool).

@jaredhirsch jaredhirsch force-pushed the 2294-pontoon-to-webextension branch 2 times, most recently from 69de1cb to 2d123da Compare March 11, 2017 00:27
@@ -35,6 +35,9 @@ imgs_server_dest := $(imgs_source:%=build/server/%)

raven_source := $(shell node -e 'console.log(require.resolve("raven-js/dist/raven.js"))')

l10n_source := $(wildcard locales/*)
l10n_dest := $(l10n_source:%/webextension.properties=addon/webextension/_locales/%/messages.json)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ianb meh, decided to just solve today's problem, and worry about building server strings when we get there

@jaredhirsch jaredhirsch force-pushed the 2294-pontoon-to-webextension branch 3 times, most recently from 3224cfe to cf3d02c Compare March 11, 2017 01:21
Copy link
Collaborator

@flodolo flodolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One tiny update to a comment but it looks great

cancelScreenshot = Cancel
downloadScreenshot = Download
notificationLinkCopiedTitle = Link Copied
# LOCALIZATION NOTE(notificationLinkCopiedDetails): The string "{meta_key}-V" should be translated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can avoid the LOCALIZATION NOTE part, since tools will associate and display the comment to the following string.

Possible comment:

# The string "{meta_key}-V" should be translated to the region-specific
# shorthand for the Paste keyboard shortcut. {meta_key} is a placeholder for the
# modifier key used in the shortcut (do not translate it): for example, Ctrl-V
# on Windows systems.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks for the feedback! I'll update that comment.

@jaredhirsch
Copy link
Member Author

@ianb Is this good to land?

Makefile Outdated
@@ -103,6 +106,9 @@ signed_xpi: addon
./node_modules/.bin/web-ext sign --api-key=${AMO_USER} --api-secret=${AMO_SECRET} --source-dir addon/webextension/
mv web-ext-artifacts/*.xpi build/pageshot.xpi

addon_locales: $(l10n_dest)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not confident exactly how this will work. Generally the Makefile pattern would be to set the requirement and then have other rules for how to generate addon/webextension/_locales/%/messages.json, like:

addon/webextension/_locales/%/messages.json: locales/%/webextension.properties
  script-that-translates-one-file $< $@

Since this appears to generate all the files in one go, it doesn't quite fit that pattern. I can't decide if $(l10n_source) belongs here, or maybe not, or maybe nothing at all?

Also there should be .PHONY: addon_locales above this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon further reflection, I guess an empty dependencies list is the right thing here, given that we don't have recipes for how to generate those individual files. Either way I believe the .json files get rebuilt on every make run because we're not telling make enough for it to know when a rebuild is necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 The rebuild is pretty cheap, for now at least (one locale...)

Makefile Outdated
@@ -103,6 +106,9 @@ signed_xpi: addon
./node_modules/.bin/web-ext sign --api-key=${AMO_USER} --api-secret=${AMO_SECRET} --source-dir addon/webextension/
mv web-ext-artifacts/*.xpi build/pageshot.xpi

addon_locales: $(l10n_dest)
./bin/pontoon-to-webext.js --dest addon/webextension/_locales
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pontoon-to-webext should go in bin/build-scripts/ since it isn't called directly, instead it's only called through the Makefile

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

package.json Outdated
@@ -16,8 +16,10 @@
"envc": "2.5.0",
"escape-html": "1.0.3",
"express": "4.15.2",
"habitat": "^3.1.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've generally been using exact versions, then upgrading in batch, so that we know everyone has the exact same version.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -1,33 +1,79 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this file be in the source at all? Isn't it generated from the properties file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 removed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

er, removed and gitignore'd

const langcode = localeLocation.split(path.sep).slice(-1)[0];

if (langcode) {
localeList.push(langcode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why wouldn't this be present? Seems like it should be a warning.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I agree that it's hard to see how langcode could fail to exist.

dirTree.splice(0,1);
dirTree.forEach((localeLocation) => {
// Get the locale code from the end of the path. We're expecting the structure of Pontoon's output here
const langcode = localeLocation.split(path.sep).slice(-1)[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't localeLocation.split(path.sep).slice(-1)[0] equivalent to localeLocation.split(path.sep)[1] ? That is, split with a string argument always splits 0 or 1 times.

(I find that split behavior confusing, so I'm always suspicious when I see it being used.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(To be clear, this is upstream code that I'm hoping Les will turn into an npm package. We're using copypasta because it's expedient.)

So, this line is getting the last directory's name off an absolute path; the slice(-1)[0] is effectively the same as doing a pop() off the end of the array.

let localeLocation = '/Users/jhirsch/codez/github/mozilla-services-pageshot/locales/en-US'
localeLocation.split('/')
// Array [ "", "Users", "jhirsch", "codez", "github", "mozilla-services-pageshot", "locales", "en-US" ]
localeLocation.split('/').slice(-1)
// Array [ "en-US" ]
localeLocation.split('/').slice(-1)[0]
// "en-US"

reject(e);
});
} else {
supportedLocales = supportedLocales.split(',').map(item => item.trim());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should be supportedLocales.split(/,/g)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're good here, since split splits globally by default:

'a,b,c'.split(',') // returns [ "a", "b", " c" ]

}).then(() => {
log(`Done compiling locales at: ${localesPath}`);
}).catch((e) => {
error(e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These errors won't lead to a build error, but they should. It's okay if build scripts are a little finicky as long as they fail hard.

I'd recommend:

function fatal(...args) {
  console.error(...args);
  process.exit(1);
}

Also this is all kind of brutal in Node.js compared to Python, but eh.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 changed (I went ahead and upstreamed that suggestion :-)

- Add pontoon-to-webext.js script from bwinton/SnoozeTabs repo and
  related npm dependencies (to be removed when/if that script is
  published on npm as a standalone module).

- Add extracted strings to a properties file at the location expected by
  Pontoon. Remove the webextension-formatted strings from git.

- Add a pontoon-to-webextension build step to the Makefile.

This commit, together with the fix for mozilla-services#2344, closes mozilla-services#2294.
@jaredhirsch
Copy link
Member Author

@ianb Updated. Mind taking another look?

@ianb ianb mentioned this pull request Mar 14, 2017
@ianb ianb merged commit f9e24d7 into mozilla-services:master Mar 14, 2017
@jaredhirsch jaredhirsch deleted the 2294-pontoon-to-webextension branch March 14, 2017 16:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

implement l10n in addon
3 participants