Skip to content

Commit

Permalink
tmp: test action
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMind committed Jan 19, 2024
1 parent bdc17e7 commit 3354982
Show file tree
Hide file tree
Showing 6 changed files with 367 additions and 96 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/localization.yml
@@ -0,0 +1,29 @@
name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: [push]
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
cache: 'yarn'
- name: Install gettext
run: sudo apt-get install gettext
- name: Install node_modules
run: yarn install --frozen-lockfile --prefer-offline
- name: Extract locales
run: yarn run zx ./bin/locales.mjs
- name: Commit locales
run: |
git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}"
git config --global user.email "username@users.noreply.github.com"
git checkout -b localization-ci
git add ./locales
git commit -m 'test: localization'
git push -u origin localization-ci
41 changes: 41 additions & 0 deletions babel.config.locales.js
@@ -0,0 +1,41 @@
// Create UTC creation date in the correct format.
const potCreationDate = new Date()
.toISOString()
.replace('T', ' ')
.replace(/:\d{2}.\d{3}Z/, '+0000');

module.exports = {
extends: './babel.config.js',
plugins: [
[
'module:babel-gettext-extractor',
{
headers: {
'Project-Id-Version': 'amo',
'Report-Msgid-Bugs-To': 'EMAIL@ADDRESS',
'POT-Creation-Date': potCreationDate,
'PO-Revision-Date': 'YEAR-MO-DA HO:MI+ZONE',
'Last-Translator': 'FULL NAME <EMAIL@ADDRESS>',
'Language-Team': 'LANGUAGE <LL@li.org>',
'MIME-Version': '1.0',
'Content-Type': 'text/plain; charset=utf-8',
'Content-Transfer-Encoding': '8bit',
'plural-forms': 'nplurals=2; plural=(n!=1);',
},
functionNames: {
gettext: ['msgid'],
dgettext: ['domain', 'msgid'],
ngettext: ['msgid', 'msgid_plural', 'count'],
dngettext: ['domain', 'msgid', 'msgid_plural', 'count'],
pgettext: ['msgctxt', 'msgid'],
dpgettext: ['domain', 'msgctxt', 'msgid'],
npgettext: ['msgctxt', 'msgid', 'msgid_plural', 'count'],
dnpgettext: ['domain', 'msgctxt', 'msgid', 'msgid_plural', 'count'],
},
fileName: './locale/templates/LC_MESSAGES/amo.pot',
baseDirectory: process.cwd(),
stripTemplateLiteralIndent: true,
},
],
],
};
52 changes: 52 additions & 0 deletions bin/locales.mjs
@@ -0,0 +1,52 @@
#!/usr/bin/env zx

import {$, path, echo, within, glob} from 'zx';

const root = path.join(__dirname, '..');
const localeDir = path.join(root, 'locale');
const templateFile = path.join(localeDir, '/templates/LC_MESSAGES/amo.pot');

// git diff --numstat returns the number of insertions and deletions for each file
// this regex extracts the numbers from the output
const regex = /([0-9]+).*([0-9]+)/;

within(async () => {
const sourceDir = path.join(root, 'src', 'amo');
const outputDir = path.join(root, 'dist', 'locales');
const localesConfig = path.join(root, 'babel.config.locales.js');

await $`babel ${sourceDir} \
--out-dir ${outputDir} \
--config-file ${localesConfig} \
--verbose \
`;

const {stdout: output} = await $`git diff --numstat -- ${templateFile}`;

const [, insertions = 0, deletions = 0] = output.match(regex) || [];

const isLocaleClean = insertions < 2 && deletions < 2;

if (isLocaleClean) {
return echo('No locale changes, nothing to update, ending process');
}

const poFiles = await glob(`${localeDir}/**/amo.po`);

for await (const poFile of poFiles) {
const dir = path.dirname(poFile);
const stem = path.basename(poFile, '.po');
const tempFile = path.join(dir, `${stem}.po.tmp`);

try {
await $`msgmerge --no-fuzzy-matching -q -o ${tempFile} ${poFile} ${templateFile}`
await $`mv ${tempFile} ${poFile}`
} catch (error) {
await $`rm ${tempFile}`;
throw new Error(`Error merging ${poFile}`);
}
}

return true;
});

6 changes: 4 additions & 2 deletions package.json
Expand Up @@ -253,7 +253,8 @@
"webpack-isomorphic-tools": "4.0.0"
},
"devDependencies": {
"@babel/core": "^7.23.7",
"@babel/cli": "7.23.4",
"@babel/core": "7.23.7",
"@babel/eslint-parser": "^7.23.3",
"@babel/preset-env": "^7.23.8",
"@babel/preset-flow": "^7.23.3",
Expand Down Expand Up @@ -329,7 +330,8 @@
"webpack-cli": "^4.0.0",
"webpack-dev-middleware": "^6.1.1",
"webpack-hot-middleware": "^2.26.0",
"webpack-subresource-integrity": "5.1.0"
"webpack-subresource-integrity": "5.1.0",
"zx": "7.2.3"
},
"bundlewatch": [
{
Expand Down
2 changes: 1 addition & 1 deletion src/amo/components/AddAddonToCollection/index.js
Expand Up @@ -184,7 +184,7 @@ export class AddAddonToCollectionBase extends React.Component<InternalProps> {
let progressMessage;

if (loadingUserCollections) {
progressMessage = i18n.gettext('Loading…');
progressMessage = i18n.gettext('Test');
} else if (loadingAddonsInCollections) {
progressMessage = i18n.gettext('Adding…');
}
Expand Down

0 comments on commit 3354982

Please sign in to comment.