Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smartling on-demand translation delivery from main #1268

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ccddd3d
File src/content/docs/en/sdk/android/v4/features/callbacks.mdx was tr…
smartling-github-connector[bot] Jan 6, 2025
607c3f1
File src/content/docs/en/sdk/android/v4/features/callbacks.mdx was tr…
smartling-github-connector[bot] Jan 6, 2025
4d43b3e
File src/content/docs/en/sdk/android/v4/features/callbacks.mdx was tr…
smartling-github-connector[bot] Jan 6, 2025
96dc1b5
File src/content/docs/en/sdk/android/v5/features/callbacks.mdx was tr…
smartling-github-connector[bot] Jan 6, 2025
a0a53d8
File src/content/docs/en/sdk/android/v5/features/callbacks.mdx was tr…
smartling-github-connector[bot] Jan 6, 2025
97e82b0
File src/content/docs/en/sdk/android/v5/features/callbacks.mdx was tr…
smartling-github-connector[bot] Jan 6, 2025
481e486
fix: fixed error in the fixTranslations script
bzavhorodskyi Jan 7, 2025
ce49c91
fix: changed workflow file
bzavhorodskyi Jan 7, 2025
911a9cf
fix: fixed workflow file
bzavhorodskyi Jan 7, 2025
830dd59
fix: workflow file
bzavhorodskyi Jan 7, 2025
59e9adf
fix: workflow
bzavhorodskyi Jan 7, 2025
1661449
fix: changed fix script
bzavhorodskyi Jan 7, 2025
eb0d9f6
fix: reverted changes
bzavhorodskyi Jan 7, 2025
16dd236
fix: workflow
bzavhorodskyi Jan 7, 2025
4427827
fix: workflow
bzavhorodskyi Jan 7, 2025
ad4b6ea
fix: workflow
bzavhorodskyi Jan 7, 2025
95a90af
fix: fixed
bzavhorodskyi Jan 7, 2025
683f9d5
Merge 95a90af228db0735f69874525fdc5b9c29ca2be9 into bf75dd862eaa5d8ba…
smartling-github-connector[bot] Jan 7, 2025
720b776
Fix translated and formatted files
github-actions[bot] Jan 7, 2025
b8ac349
fix: lint for the mdoc files
bzavhorodskyi Jan 7, 2025
1c76f4f
Merge b8ac34956e3d5fde3a153400c5e61c85f254229a into bf75dd862eaa5d8ba…
smartling-github-connector[bot] Jan 7, 2025
d3356f5
Fix translated and formatted files
github-actions[bot] Jan 7, 2025
c29e40c
fix: changed markdoc
bzavhorodskyi Jan 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .github/scripts/fixTranslations.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const TAG_LIST = MDX_TAGS.join("|");

// Helper function to split the front matter (YAML) from content
function splitFrontMatter(content) {
const match = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)/);
const match = content.match(/^---\r?\n([\s\S]*?)\n---\r?\n([\s\S]*)/);

if (match) {
return [match[1], match[2]];
}
Expand Down Expand Up @@ -140,7 +141,7 @@ function getModifiedFiles() {
// Format MDX files using Prettier
async function formatMdxFile(file) {
return new Promise((resolve, reject) => {
exec(`npx prettier --write ${file}`, (error, stdout, stderr) => {
exec(`npx prettier --write ../../${file}`, (error, stdout, stderr) => {
if (error) return reject(stderr);
console.log(stdout);
resolve();
Expand All @@ -151,7 +152,7 @@ async function formatMdxFile(file) {
// Format MDOC files using the custom formatter
async function formatMdocFile(file) {
return new Promise((resolve, reject) => {
exec(`node ../../markdoc-formatter.mjs ${file}`, (error, stdout, stderr) => {
exec(`node ../../markdoc-formatter.mjs ../../${file}`, (error, stdout, stderr) => {
if (error) return reject(stderr);
console.log(stdout);
resolve();
Expand All @@ -162,7 +163,7 @@ async function formatMdocFile(file) {
// Process a single file
async function processFile(file, locale) {
console.log(`Processing ${file} for ${locale}`);
const originalContent = await fs.readFile(file, "utf-8");
const originalContent = await fs.readFile(`../../${file}`, "utf-8");
const [frontMatterYaml, fileContent] = splitFrontMatter(originalContent);

const frontMatter = yaml.load(frontMatterYaml);
Expand All @@ -178,7 +179,7 @@ async function processFile(file, locale) {
const finalContent = `---\n${yaml.dump(updatedFrontMatter, { noRefs: true })}---\n${updatedContent}`;

if (finalContent !== originalContent) {
await fs.writeFile(file, finalContent, "utf-8");
await fs.writeFile(`../../${file}`, finalContent, "utf-8");
modifiedFiles.push(file);

// Format the file after writing changes
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/fix_translations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
- name: Checkout the full PR history
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0

# Set up Node.js environment
Expand Down Expand Up @@ -42,7 +43,9 @@ jobs:
- name: Commit changes
if: ${{ steps.git-check.outputs.MODIFIED == 'true' }}
run: |
BRANCH_NAME=${GITHUB_HEAD_REF}
git config --global user.name "github-actions"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -B "$BRANCH_NAME"
git commit -am "Fix translated and formatted files"
git push
git push origin "$BRANCH_NAME"
12 changes: 6 additions & 6 deletions markdoc-formatter.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';
import path from 'path';
import Markdoc from '@markdoc/markdoc';
import fs from "fs";
import path from "path";
import Markdoc from "@markdoc/markdoc";

/**
* Format a list of Markdoc (.mdoc) files
Expand All @@ -11,20 +11,20 @@ async function formatMarkdocFiles(files) {
const absolutePath = path.resolve(filePath);

// Read the file content
const source = fs.readFileSync(absolutePath, 'utf-8');
const source = fs.readFileSync(absolutePath, "utf-8");

// Parse and format using Markdoc
const ast = Markdoc.parse(source);
let formatted = Markdoc.format(ast);

// Write the formatted content back to the file
fs.writeFileSync(absolutePath, formatted, 'utf-8');
fs.writeFileSync(absolutePath, formatted, "utf-8");
});
}

// Parse command-line arguments and run the formatter
const files = process.argv.slice(2);
formatMarkdocFiles(files).catch((error) => {
console.error('Error formatting Markdoc files:', error);
console.error("Error formatting Markdoc files:", error);
process.exit(1);
});
Loading
Loading