diff --git a/.github/scripts/fixTranslations.mjs b/.github/scripts/fixTranslations.mjs new file mode 100644 index 000000000..d3d096b44 --- /dev/null +++ b/.github/scripts/fixTranslations.mjs @@ -0,0 +1,218 @@ +import fs from "fs/promises"; +import yaml from "js-yaml"; +import { exec, execSync } from "child_process"; + +const MDX_TAGS = [ + "Accordion", + "Callout", + "CodeBlock", + "MinorVersion", + "Tabs", + "Tab", + "ListColumns", +]; + +// Define the base MDOC tags, and dynamically generate opening and closing variants +const BASE_MDOC_TAGS = [ + "tabs", + "tab", + "deflist", + "minorversion", + "codeblock", + "listcolumns", + "accordion", + "callout", +]; +const MDOC_TAGS = BASE_MDOC_TAGS.flatMap(tag => [tag, `/${tag}`]); + +const locales = ["ja", "ko", "zh"]; +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]*)/); + if (match) { + return [match[1], match[2]]; + } + return ["", content]; +} + +// Fix the YAML front matter +function fixFrontMatter(frontMatter, locale) { + if (frontMatter.slug && frontMatter.slug.startsWith("en/")) { + frontMatter.slug = `${locale}/${frontMatter.slug.slice(3)}`; + } + + if (frontMatter.redirects) { + for (const version in frontMatter.redirects) { + if (frontMatter.redirects[version].startsWith("/en/")) { + frontMatter.redirects[version] = `/${locale}/${frontMatter.redirects[version].slice(4)}`; + } + } + } + + return frontMatter; +} + +// Remove escape slashes from tags +function removeEscapeSlashesFromTags(content) { + return content.replace(/\\(?=[-#])/g, ""); +} + +// Add newline after closing tags +function addNewlineAfterClosingTags(content, tags) { + const tagList = tags.join("|"); + const regex = new RegExp(`(\\S)(\\s*{%\\s*/(?:${tagList})\\s*%})(?!\\n)`, "g"); + return content.replace(regex, "$1\n$2"); +} + +function fixHeaders(content) { + const headerRegex = /^(\s*#+\s.*?)(\\{\\#.*?\\})/gm; + return content.replace(headerRegex, (match, p1, p2) => p1 + p2.replace(/\\/g, "")); +} + + +// Fix MDX content +function fixMdxContent(content, locale) { + // Fix tags to ensure correct casing + for (const tag of MDX_TAGS) { + const lowercaseTag = tag.toLowerCase(); + const regex = new RegExp(`<(${lowercaseTag})`, "g"); + content = content.replace(regex, `<${tag}`); + } + + // Fix broken unescaped angle brackets in Japanese content + if (locale === "ja") { + content = content.replace(/(<)/g, "(\\<)"); + } + + // Ensure newline between any two tags on the same line + const tagRegex = new RegExp(`(<[^<>]*\\/?(?:${TAG_LIST})[^<>]*>)(\\s*)(<[^<>]*\\/?(?:${TAG_LIST})[^<>]*>)`, "g"); + content = content.replace(tagRegex, "$1\n$3"); + content = fixHeaders(content); + + // Fix escaped headers + const headerRegex = /^(\s.*?)(\\{#.*?\\})/gm; + content = content.replace(headerRegex, (match, p1, p2) => p1 + p2.replace(/\\/g, "")); + + // Update URLs + content = content.replace(/https:\/\/help\.adjust\.com\/en\//g, `https://help.adjust.com/${locale}/`); + content = content.replace(/\(\/en\/(.*?)\)/g, `(/${locale}/$1)`); + + // Remove unnecessary IDs + content = content.replace(/ id="sl-md0000000"/g, ""); + content = content.replace(/\s?md0000000\s?/g, ""); + + return content; +} + +// Fix mdoc content +function fixMdocContent(content, locale) { + // Unescape escaped curly braces + content = content.replace(/\\{%(.*?)%\\}/g, "{%$1%}"); + content = fixHeaders(content); + + content = removeEscapeSlashesFromTags(content); + + content = addNewlineAfterClosingTags(content, MDOC_TAGS); + + // Update URLs + content = content.replace(/https:\/\/help\.adjust\.com\/en\//g, `https://help.adjust.com/${locale}/`); + content = content.replace(/\(\/en\/(.*?)\)/g, `(/${locale}/$1)`); + + // Add newline between two adjacent opening tags + content = content.replace(/(%}\s*)({%\s*[^%]+%})/g, "$1\n$2"); + + // Add newline between two adjacent closing tags + content = content.replace(/(%}\s*)({%\s*\/[^%]+%})/g, "$1\n$2"); + + return content; +} + +const modifiedFiles = []; + +// Get the list of modified files in the current PR +function getModifiedFiles() { + const output = execSync("git diff --name-only HEAD~1", { encoding: "utf-8" }); + return output.split("\n").filter((file) => file.trim() !== ""); +} + +// Format MDX files using Prettier +async function formatMdxFile(file) { + return new Promise((resolve, reject) => { + exec(`npx prettier --write ${file}`, (error, stdout, stderr) => { + if (error) return reject(stderr); + console.log(stdout); + resolve(); + }); + }); +} + +// 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) => { + if (error) return reject(stderr); + console.log(stdout); + resolve(); + }); + }); +} + +// Process a single file +async function processFile(file, locale) { + console.log(`Processing ${file} for ${locale}`); + const originalContent = await fs.readFile(file, "utf-8"); + const [frontMatterYaml, fileContent] = splitFrontMatter(originalContent); + + const frontMatter = yaml.load(frontMatterYaml); + const updatedFrontMatter = fixFrontMatter(frontMatter, locale); + + let updatedContent; + if (file.endsWith(".mdx")) { + updatedContent = fixMdxContent(fileContent, locale); + } else if (file.endsWith(".mdoc")) { + updatedContent = fixMdocContent(fileContent, locale); + } + + const finalContent = `---\n${yaml.dump(updatedFrontMatter, { noRefs: true })}---\n${updatedContent}`; + + if (finalContent !== originalContent) { + await fs.writeFile(file, finalContent, "utf-8"); + modifiedFiles.push(file); + + // Format the file after writing changes + if (file.endsWith(".mdx")) { + await formatMdxFile(file); + } else if (file.endsWith(".mdoc")) { + await formatMdocFile(file); + } + } +} + +// Main function to process only modified files +async function main() { + const files = getModifiedFiles(); + console.log("Modified files:", files); + + for (const locale of locales) { + const relevantFiles = files.filter((file) => + file.startsWith(`src/content/docs/${locale}/`) && (file.endsWith(".mdx") || file.endsWith(".mdoc")) + ); + + for (const file of relevantFiles) { + await processFile(file, locale); + } + } + + if (modifiedFiles.length > 0) { + console.log("Processed files:", modifiedFiles.join(", ")); + } else { + console.log("No relevant files were modified."); + } +} + +main().catch((err) => { + console.error(err); + process.exit(1); +}); diff --git a/.github/scripts/fix_i18n.py b/.github/scripts/fix_i18n.py deleted file mode 100644 index 8e9ffc35b..000000000 --- a/.github/scripts/fix_i18n.py +++ /dev/null @@ -1,166 +0,0 @@ -import re -import glob -import yaml - -# Define MDX tags and locales -MDX_TAGS = [ - "Accordion", - "Callout", - "CodeBlock", - "MinorVersion", - "Tabs", - "Tab", - "ListColumns", -] -locales = ["ja", "ko", "zh"] -TAG_LIST = "|".join(MDX_TAGS) - - -# Process each file -def process_file(file, locale): - print(f"Processing {file} for {locale}") - - # Read file content - with open(file, "r", encoding="utf-8") as f: - content = f.read() - - # Split the front matter (YAML) from the content - front_matter, file_content = split_front_matter(content) - - # Parse the front matter as YAML and update keys - front_matter = yaml.safe_load(front_matter) - updated_front_matter = fix_front_matter(front_matter, locale) - - # Apply MDX or mdoc specific fixes - if file.endswith(".mdx"): - file_content = fix_mdx_content(file_content, locale) - elif file.endswith(".mdoc"): - file_content = fix_mdoc_content(file_content, locale) - - # Rebuild the final content (YAML front matter + content) - final_content = "---\n" + yaml.dump(updated_front_matter, sort_keys=False, allow_unicode=True) + "---\n" + file_content - - # Write back the modified content - with open(file, "w", encoding="utf-8") as f: - f.write(final_content) - - -# Split the front matter (YAML) from the content -def split_front_matter(content): - match = re.match(r"^---\n(.*?)\n---\n(.*)", content, re.DOTALL) - if match: - return match.group(1), match.group(2) - return "", content # If no front matter is found, return empty front matter and original content - - -# Fix the YAML front matter -def fix_front_matter(front_matter, locale): - # Update slug - if "slug" in front_matter and front_matter["slug"].startswith("en/"): - front_matter["slug"] = f"{locale}/{front_matter['slug'][3:]}" - - # Update redirects slugs - if "redirects" in front_matter: - for version, slug in front_matter["redirects"].items(): - if slug.startswith("/en/"): - front_matter["redirects"][version] = f"/{locale}/{slug[4:]}" - - return front_matter - -def remove_escape_slashes_from_tags(content): - # This regex finds escaped slashes outside of quotes - # It looks for slashes that are not followed by a quote - return re.sub(r"\\(?![\"])([-#])", r"\1", content) - -def add_newline_after_closing_tags(content): - # Only add a newline if the closing tag is inline with other content - return re.sub(r"(\S)(\s*{%\s*/[^%]+%\})(?!\n)", r"\1\n\2", content) - - -# Fix MDX content (non-YAML part) -def fix_mdx_content(content, locale): - # Fix tags - for tag in MDX_TAGS: - lowercase_tag = tag.lower() - content = re.sub(rf"<({lowercase_tag})", rf"<{tag}", content) - - # Fix broken unescaped angle brackets in Japanese content - if locale == "ja": - content = re.sub(r"(<)", r"(\\<)", content) - - # Ensure newline between any two tags on the same line - lines = content.split("\n") - fixed_lines = [] - for line in lines: - line = re.sub( - rf"(<[^<>]*[\/]?({TAG_LIST})[^<>]*>)(\s*)(<[^<>]*[\/]?({TAG_LIST})[^<>]*>)", - r"\1\n\4", - line, - ) - fixed_lines.append(line) - content = "\n".join(fixed_lines) - - # Fix escaped headers - content = re.sub( - r"^(\s.*?)(\\\{\\#.*?\\\})", - lambda m: m.group(1) + m.group(2).replace("\\", ""), - content, - flags=re.MULTILINE, - ) - - # Update URLs - content = re.sub( - r"https://help.adjust.com/en/", f"https://help.adjust.com/{locale}/", content - ) - - # Update internal links - content = re.sub(r"\(/en/(.*?)\)", rf"(/{locale}/\1)", content) - - # Remove unnecessary IDs - content = re.sub(r' id="sl-md0000000"', "", content) - content = re.sub(r"\s?md0000000\s?", "", content) - - return content - - -# Fix mdoc content -def fix_mdoc_content(content, locale): - # Unescape escaped curly braces - content = re.sub(r"\\{%(.*?)%\\}", r"{%\1%}", content) - - content = remove_escape_slashes_from_tags(content) - - content = add_newline_after_closing_tags(content) - - # Update URLs - content = re.sub( - r"https://help.adjust.com/en/", f"https://help.adjust.com/{locale}/", content - ) - - # Add newline between two adjacent opening tags (e.g., {% tabs %}{% tab %}) - content = re.sub(r"(%\}\s*)(\{%\s*[^%]+%\})", r"\1\n\2", content) - - # Add newline between two adjacent closing tags (e.g., {% /tab %}{% /tabs %}) - content = re.sub(r"(%\}\s*)(\{%\s*/[^%]+%\})", r"\1\n\2", content) - - # Convert underlined H2 headers - content = re.sub(r"^(.*)\n[-]{2,}\n", r"## \1\n", content, flags=re.MULTILINE) - - # Update internal links - content = re.sub(r"\(/en/(.*?)\)", rf"(/{locale}/\1)", content) - - return content - - -# Main function to find and process all relevant files -def main(): - for locale in locales: - patterns = [f"../../src/content/docs/{locale}/**/*.mdx", f"../../src/content/docs/{locale}/**/*.mdoc"] - for pattern in patterns: - files = glob.glob(pattern, recursive=True) - for file in files: - process_file(file, locale) - - -if __name__ == "__main__": - main() diff --git a/.github/scripts/poetry.lock b/.github/scripts/poetry.lock deleted file mode 100644 index af673aa78..000000000 --- a/.github/scripts/poetry.lock +++ /dev/null @@ -1,68 +0,0 @@ -# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. - -[[package]] -name = "pyyaml" -version = "6.0.2" -description = "YAML parser and emitter for Python" -optional = false -python-versions = ">=3.8" -files = [ - {file = "PyYAML-6.0.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:0a9a2848a5b7feac301353437eb7d5957887edbf81d56e903999a75a3d743086"}, - {file = "PyYAML-6.0.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:29717114e51c84ddfba879543fb232a6ed60086602313ca38cce623c1d62cfbf"}, - {file = "PyYAML-6.0.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8824b5a04a04a047e72eea5cec3bc266db09e35de6bdfe34c9436ac5ee27d237"}, - {file = "PyYAML-6.0.2-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:7c36280e6fb8385e520936c3cb3b8042851904eba0e58d277dca80a5cfed590b"}, - {file = "PyYAML-6.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ec031d5d2feb36d1d1a24380e4db6d43695f3748343d99434e6f5f9156aaa2ed"}, - {file = "PyYAML-6.0.2-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:936d68689298c36b53b29f23c6dbb74de12b4ac12ca6cfe0e047bedceea56180"}, - {file = "PyYAML-6.0.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:23502f431948090f597378482b4812b0caae32c22213aecf3b55325e049a6c68"}, - {file = "PyYAML-6.0.2-cp310-cp310-win32.whl", hash = "sha256:2e99c6826ffa974fe6e27cdb5ed0021786b03fc98e5ee3c5bfe1fd5015f42b99"}, - {file = "PyYAML-6.0.2-cp310-cp310-win_amd64.whl", hash = "sha256:a4d3091415f010369ae4ed1fc6b79def9416358877534caf6a0fdd2146c87a3e"}, - {file = "PyYAML-6.0.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:cc1c1159b3d456576af7a3e4d1ba7e6924cb39de8f67111c735f6fc832082774"}, - {file = "PyYAML-6.0.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:1e2120ef853f59c7419231f3bf4e7021f1b936f6ebd222406c3b60212205d2ee"}, - {file = "PyYAML-6.0.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5d225db5a45f21e78dd9358e58a98702a0302f2659a3c6cd320564b75b86f47c"}, - {file = "PyYAML-6.0.2-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:5ac9328ec4831237bec75defaf839f7d4564be1e6b25ac710bd1a96321cc8317"}, - {file = "PyYAML-6.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3ad2a3decf9aaba3d29c8f537ac4b243e36bef957511b4766cb0057d32b0be85"}, - {file = "PyYAML-6.0.2-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:ff3824dc5261f50c9b0dfb3be22b4567a6f938ccce4587b38952d85fd9e9afe4"}, - {file = "PyYAML-6.0.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:797b4f722ffa07cc8d62053e4cff1486fa6dc094105d13fea7b1de7d8bf71c9e"}, - {file = "PyYAML-6.0.2-cp311-cp311-win32.whl", hash = "sha256:11d8f3dd2b9c1207dcaf2ee0bbbfd5991f571186ec9cc78427ba5bd32afae4b5"}, - {file = "PyYAML-6.0.2-cp311-cp311-win_amd64.whl", hash = "sha256:e10ce637b18caea04431ce14fabcf5c64a1c61ec9c56b071a4b7ca131ca52d44"}, - {file = "PyYAML-6.0.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:c70c95198c015b85feafc136515252a261a84561b7b1d51e3384e0655ddf25ab"}, - {file = "PyYAML-6.0.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:ce826d6ef20b1bc864f0a68340c8b3287705cae2f8b4b1d932177dcc76721725"}, - {file = "PyYAML-6.0.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1f71ea527786de97d1a0cc0eacd1defc0985dcf6b3f17bb77dcfc8c34bec4dc5"}, - {file = "PyYAML-6.0.2-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:9b22676e8097e9e22e36d6b7bda33190d0d400f345f23d4065d48f4ca7ae0425"}, - {file = "PyYAML-6.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:80bab7bfc629882493af4aa31a4cfa43a4c57c83813253626916b8c7ada83476"}, - {file = "PyYAML-6.0.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:0833f8694549e586547b576dcfaba4a6b55b9e96098b36cdc7ebefe667dfed48"}, - {file = "PyYAML-6.0.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8b9c7197f7cb2738065c481a0461e50ad02f18c78cd75775628afb4d7137fb3b"}, - {file = "PyYAML-6.0.2-cp312-cp312-win32.whl", hash = "sha256:ef6107725bd54b262d6dedcc2af448a266975032bc85ef0172c5f059da6325b4"}, - {file = "PyYAML-6.0.2-cp312-cp312-win_amd64.whl", hash = "sha256:7e7401d0de89a9a855c839bc697c079a4af81cf878373abd7dc625847d25cbd8"}, - {file = "PyYAML-6.0.2-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:efdca5630322a10774e8e98e1af481aad470dd62c3170801852d752aa7a783ba"}, - {file = "PyYAML-6.0.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:50187695423ffe49e2deacb8cd10510bc361faac997de9efef88badc3bb9e2d1"}, - {file = "PyYAML-6.0.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0ffe8360bab4910ef1b9e87fb812d8bc0a308b0d0eef8c8f44e0254ab3b07133"}, - {file = "PyYAML-6.0.2-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:17e311b6c678207928d649faa7cb0d7b4c26a0ba73d41e99c4fff6b6c3276484"}, - {file = "PyYAML-6.0.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:70b189594dbe54f75ab3a1acec5f1e3faa7e8cf2f1e08d9b561cb41b845f69d5"}, - {file = "PyYAML-6.0.2-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:41e4e3953a79407c794916fa277a82531dd93aad34e29c2a514c2c0c5fe971cc"}, - {file = "PyYAML-6.0.2-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:68ccc6023a3400877818152ad9a1033e3db8625d899c72eacb5a668902e4d652"}, - {file = "PyYAML-6.0.2-cp313-cp313-win32.whl", hash = "sha256:bc2fa7c6b47d6bc618dd7fb02ef6fdedb1090ec036abab80d4681424b84c1183"}, - {file = "PyYAML-6.0.2-cp313-cp313-win_amd64.whl", hash = "sha256:8388ee1976c416731879ac16da0aff3f63b286ffdd57cdeb95f3f2e085687563"}, - {file = "PyYAML-6.0.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:24471b829b3bf607e04e88d79542a9d48bb037c2267d7927a874e6c205ca7e9a"}, - {file = "PyYAML-6.0.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d7fded462629cfa4b685c5416b949ebad6cec74af5e2d42905d41e257e0869f5"}, - {file = "PyYAML-6.0.2-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:d84a1718ee396f54f3a086ea0a66d8e552b2ab2017ef8b420e92edbc841c352d"}, - {file = "PyYAML-6.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9056c1ecd25795207ad294bcf39f2db3d845767be0ea6e6a34d856f006006083"}, - {file = "PyYAML-6.0.2-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:82d09873e40955485746739bcb8b4586983670466c23382c19cffecbf1fd8706"}, - {file = "PyYAML-6.0.2-cp38-cp38-win32.whl", hash = "sha256:43fa96a3ca0d6b1812e01ced1044a003533c47f6ee8aca31724f78e93ccc089a"}, - {file = "PyYAML-6.0.2-cp38-cp38-win_amd64.whl", hash = "sha256:01179a4a8559ab5de078078f37e5c1a30d76bb88519906844fd7bdea1b7729ff"}, - {file = "PyYAML-6.0.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:688ba32a1cffef67fd2e9398a2efebaea461578b0923624778664cc1c914db5d"}, - {file = "PyYAML-6.0.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:a8786accb172bd8afb8be14490a16625cbc387036876ab6ba70912730faf8e1f"}, - {file = "PyYAML-6.0.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d8e03406cac8513435335dbab54c0d385e4a49e4945d2909a581c83647ca0290"}, - {file = "PyYAML-6.0.2-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:f753120cb8181e736c57ef7636e83f31b9c0d1722c516f7e86cf15b7aa57ff12"}, - {file = "PyYAML-6.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3b1fdb9dc17f5a7677423d508ab4f243a726dea51fa5e70992e59a7411c89d19"}, - {file = "PyYAML-6.0.2-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:0b69e4ce7a131fe56b7e4d770c67429700908fc0752af059838b1cfb41960e4e"}, - {file = "PyYAML-6.0.2-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:a9f8c2e67970f13b16084e04f134610fd1d374bf477b17ec1599185cf611d725"}, - {file = "PyYAML-6.0.2-cp39-cp39-win32.whl", hash = "sha256:6395c297d42274772abc367baaa79683958044e5d3835486c16da75d2a694631"}, - {file = "PyYAML-6.0.2-cp39-cp39-win_amd64.whl", hash = "sha256:39693e1f8320ae4f43943590b49779ffb98acb81f788220ea932a6b6c51004d8"}, - {file = "pyyaml-6.0.2.tar.gz", hash = "sha256:d584d9ec91ad65861cc08d42e834324ef890a082e591037abe114850ff7bbc3e"}, -] - -[metadata] -lock-version = "2.0" -python-versions = "^3.13.0" -content-hash = "3400ae8e74332ce5bfde84cefa8c5f582b3458e4005fe647830d2e189b27159d" diff --git a/.github/scripts/pyproject.toml b/.github/scripts/pyproject.toml deleted file mode 100644 index d0191bbed..000000000 --- a/.github/scripts/pyproject.toml +++ /dev/null @@ -1,17 +0,0 @@ -[tool.poetry] -name = "fix-i18n" -version = "0.1.0" -description = "A small Python script used to fix up translated files coming from Smartling" -authors = ["Ciarán Ainsworth "] -license = "MIT" -readme = "README.md" -package-mode = false - -[tool.poetry.dependencies] -python = "^3.13.0" -pyyaml = "^6.0.2" - - -[build-system] -requires = ["poetry-core"] -build-backend = "poetry.core.masonry.api" diff --git a/.github/workflows/fix_translations.yml b/.github/workflows/fix_translations.yml index 3ac8f518d..447486b71 100644 --- a/.github/workflows/fix_translations.yml +++ b/.github/workflows/fix_translations.yml @@ -10,59 +10,39 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NODE_AUTH_TOKEN: ${{ secrets.ADJUST_NPM_TOKEN }} steps: - - name: Checkout the latest commit - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + - name: Checkout the full PR history + uses: actions/checkout@v4 with: - ref: ${{ github.event.pull_request.head.ref }} + fetch-depth: 0 - # Install Poetry - - name: Install Poetry - run: | - pipx install poetry - - # Set up Python environment - - name: Set up Python - uses: actions/setup-python@v5 + # Set up Node.js environment + - name: Set up Node.js + uses: actions/setup-node@v4 with: - python-version: "3.12" - cache: "poetry" + node-version: "20.x" + registry-url: https://npm.pkg.github.com/ + scope: "@adjust" - # Install dependencies using Poetry - - name: Install dependencies with Poetry + # Install npm dependencies + - name: Install dependencies working-directory: .github/scripts - run: | - poetry install + run: npm install - # Run the script using Poetry - - name: Run translation fixes script with Poetry + # Run the .mjs script to fix translations and format modified files + - name: Run translation fixes script working-directory: .github/scripts - run: | - poetry run python fix_i18n.py + run: node fix_i18n.mjs # Check for modified files - name: Check for modified files id: git-check run: echo "MODIFIED=$(if [ -n "$(git status --porcelain)" ]; then echo "true"; else echo "false"; fi)" >> "$GITHUB_OUTPUT" - # Set up Node if files were modified - - name: Set up node - if: ${{ steps.git-check.outputs.MODIFIED == 'true' }} - uses: actions/setup-node@v4 - with: - node-version: "20.x" - registry-url: https://npm.pkg.github.com/ - scope: "@adjust" - - # Install npm dependencies if files were modified - - name: Install dependencies - if: ${{ steps.git-check.outputs.MODIFIED == 'true' }} - run: npm i - # Commit and push changes if any files were modified - name: Commit changes if: ${{ steps.git-check.outputs.MODIFIED == 'true' }} run: | git config --global user.name "github-actions" git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" - git commit -am "Fix translated files" + git commit -am "Fix translated and formatted files" git push diff --git a/package-lock.json b/package-lock.json index e108c6d2a..f911e7568 100644 --- a/package-lock.json +++ b/package-lock.json @@ -53,6 +53,7 @@ "@types/unist": "^3.0.3", "eslint": "^8.57.1", "husky": "^9.1.6", + "js-yaml": "^4.1.0", "lint-staged": "^15.2.10", "prettier": "^3.3.3", "prettier-plugin-astro": "^0.14.1", @@ -6876,6 +6877,7 @@ "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "license": "MIT", "dependencies": { "argparse": "^2.0.1" }, diff --git a/package.json b/package.json index 94aee7d96..0422d930d 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "@types/unist": "^3.0.3", "eslint": "^8.57.1", "husky": "^9.1.6", + "js-yaml": "^4.1.0", "lint-staged": "^15.2.10", "prettier": "^3.3.3", "prettier-plugin-astro": "^0.14.1",