Skip to content

Commit

Permalink
Update scripts, add crowdin:sync command, update main.yml to deploy l…
Browse files Browse the repository at this point in the history
…ocalized versions
  • Loading branch information
ImmaZoni committed Aug 16, 2023
1 parent dcd6911 commit bd4cddb
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 62 deletions.
51 changes: 51 additions & 0 deletions .github/scripts/reorganize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const fs = require('fs');
const path = require('path');
const { locales } = require('../../docusaurus.config').i18n;

const moveContents = (source, destination) => {
if (!fs.existsSync(source)) return; // Skip if the source doesn't exist

const items = fs.readdirSync(source);

items.forEach((item) => {
const sourceItem = path.join(source, item);
const destinationItem = path.join(destination, item);

if (fs.lstatSync(sourceItem).isDirectory()) {
if (!fs.existsSync(destinationItem)) {
fs.mkdirSync(destinationItem, { recursive: true });
}
moveContents(sourceItem, destinationItem);
fs.rmSync(sourceItem, { recursive: true });
} else {
if (!fs.existsSync(path.dirname(destinationItem))) {
fs.mkdirSync(path.dirname(destinationItem), { recursive: true });
}
fs.copyFileSync(sourceItem, destinationItem);
fs.unlinkSync(sourceItem);
}
});
};

locales.forEach((locale) => {
const basePath = `i18n/${locale}/docusaurus-plugin-content-docs`;

// Move JSON files and other sections
moveContents(`i18n/${locale}/i18n/en/docusaurus-plugin-content-docs`, basePath);
moveContents(`i18n/${locale}/i18n/en/docusaurus-plugin-content-blog`, `i18n/${locale}/docusaurus-plugin-content-blog`);
moveContents(`i18n/${locale}/i18n/en/docusaurus-theme-classic`, `i18n/${locale}/docusaurus-theme-classic`);
fs.renameSync(`i18n/${locale}/i18n/en/code.json`, `i18n/${locale}/code.json`);

// Remove now-empty sub-i18n folder
fs.rmSync(`i18n/${locale}/i18n`, { recursive: true });

// Move the version-latest folder to the same level as the current folder
moveContents(`${basePath}/versioned_docs/version-latest`, `${basePath}/version-latest`);

// Move other contents
moveContents(`${basePath}/current/docs`, `${basePath}/current`);
fs.rmSync(`${basePath}/current/docs`, { recursive: true }); // Remove empty /docs folder

moveContents(`${basePath}/versioned_docs`, basePath);
fs.rmSync(`${basePath}/versioned_docs`, { recursive: true }); // Remove empty /versioned_docs folder
});
6 changes: 6 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:
deploy:
name: Deploy to GitHub Pages
runs-on: ubuntu-latest
env:
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
Expand All @@ -18,6 +20,10 @@ jobs:

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Sync Localization Files
run: yarn crowdin:sync

- name: Build website
run: yarn build

Expand Down
7 changes: 3 additions & 4 deletions crowdin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ preserve_hierarchy: true
files:
# JSON translation files
- source: /i18n/en/**/*
translation: "/i18n/%two_letters_code%/**/%original_file_name%"
translation: "/i18n/%two_letters_code%/%original_path%/%original_file_name%"
# Docs Markdown files
- source: /docs/**/*
translation: /i18n/%two_letters_code%/docusaurus-plugin-content-docs/current/**/%original_file_name%
skip_untranslated_files: false
translation: /i18n/%two_letters_code%/docusaurus-plugin-content-docs/current/%original_path%/%original_file_name%
- source: /versioned_docs/**/*
translation: /i18n/%two_letters_code%/docusaurus-plugin-content-docs/**/%original_file_name%
translation: /i18n/%two_letters_code%/docusaurus-plugin-content-docs/%original_path%/%original_file_name%
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"clear": "docusaurus clear",
"serve": "docusaurus serve",
"crowdin": "crowdin",
"crowdin:sync": "docusaurus write-translations && crowdin upload && crowdin download",
"crowdin:sync": "docusaurus write-translations --locale en && crowdin upload && crowdin download && node .github/scripts/reorganize.js",
"copy-all-versions": "node copy-all-versions.js",
"version-update": "node .github/scripts/version-update",
"write-translations": "docusaurus write-translations",
"write-all-translations": "node write-all-translations.js",
"write-heading-ids": "docusaurus write-heading-ids",
"reorganize": "node .github/scripts/reorganize.js",
"typecheck": "tsc"
},
"dependencies": {
Expand Down
38 changes: 0 additions & 38 deletions reorganize.js

This file was deleted.

18 changes: 0 additions & 18 deletions write-all-translations.js

This file was deleted.

0 comments on commit bd4cddb

Please sign in to comment.