Build: correct locale folders generated by Pontoon
Pontoon (the software we use to localize the extension) generates
folders with locale codes which are not the ones used by Chrome nor
Firefox. This change adds logic to the build process which changes these
locale codes to the correct ones, so browsers can recognize and use all
translations.
For now, we're transforming 'pt-rBR' to 'pt', since for now it is the
only locale with a wrong code. We use 'pt' instead of 'pt_BR' since we
want to use its strings for both Portuguese (Portugal) and Portuguese
(Brazil).
Bug: twpowertools:40
Change-Id: If9ab8fc9646aa5252d3637fd8cf0fcdba11dffee
diff --git a/webpack.config.js b/webpack.config.js
index 312a276..615ae14 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -3,6 +3,31 @@
const CopyWebpackPlugin = require('copy-webpack-plugin');
const WebpackShellPluginNext = require('webpack-shell-plugin-next');
+// Pontoon uses their own locale set. This array lets us convert those locales
+// to the ones accepted by Chrome, Firefox, etc.
+const localeOverrides = [
+ {
+ pontoonLocale: 'pt-rBR',
+ webExtLocale: 'pt', // This way it targets both 'pt_BR' and 'pt_PT'
+ },
+];
+
+const getCopyPluginsForOverridenLocales = outputPath => {
+ return localeOverrides.map(l => {
+ return new CopyWebpackPlugin({
+ patterns: [
+ {
+ from: path.join(__dirname, 'src/static/_locales/' + l.pontoonLocale),
+ to: path.join(outputPath, '_locales/' + l.webExtLocale),
+ globOptions: {
+ ignore: ['**/OWNERS', '**.md'],
+ }
+ },
+ ]
+ });
+ });
+};
+
module.exports = (env, args) => {
let entry = {
// Content scripts
@@ -30,6 +55,9 @@
let outputPath = path.join(__dirname, 'dist', env.browser_target);
+ let overridenLocalePaths =
+ localeOverrides.map(l => '**/_locales/' + l.pontoonLocale);
+
return {
entry,
output: {
@@ -52,11 +80,12 @@
from: path.join(__dirname, 'src/static'),
to: outputPath,
globOptions: {
- ignore: ['**/OWNERS'],
+ ignore: ['**/OWNERS', '**.md', ...overridenLocalePaths],
}
},
]
}),
+ ...getCopyPluginsForOverridenLocales(outputPath),
],
// NOTE: Change to
// (args.mode == 'production' ? 'source-map' : 'inline-source-map')