Skip to content

Commit

Permalink
port over improvements from #914
Browse files Browse the repository at this point in the history
  • Loading branch information
achou11 committed Jan 29, 2025
1 parent 9fd819f commit d59ec6f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 40 deletions.
21 changes: 0 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@
"eslint": "8.47.0",
"eslint-config-prettier": "9.1.0",
"execa": "8.0.1",
"glob": "10.3.15",
"husky": "8.0.3",
"jest": "29.7.0",
"jest-expo": "52.0.3",
Expand All @@ -164,7 +163,6 @@
"prettier": "3.2.5",
"react-native-svg-transformer": "1.5.0",
"react-test-renderer": "18.3.1",
"rimraf": "5.0.5",
"semver": "7.6.0",
"type-fest": "4.26.0",
"typescript": "5.3.3"
Expand Down
27 changes: 10 additions & 17 deletions scripts/build-translations.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
* (see https://github.com/digidem/mapeo-mobile/discussions/828).
*/

import {compile} from '@formatjs/cli-lib';
import {glob} from 'glob';
import {mkdirSync} from 'node:fs';
import {writeFile} from 'node:fs/promises';
import {mkdirSync, readdirSync, rmSync, writeFileSync} from 'node:fs';
import path from 'node:path';
import {rimraf} from 'rimraf';
import {compile} from '@formatjs/cli-lib';

import LANGUAGE_NAME_TRANSLATIONS from '../src/frontend/languages.json' with {type: 'json'};

Expand All @@ -31,21 +28,17 @@ const CROWDIN_FORMATTER_PATH = new URL(
import.meta.resolve('@formatjs/cli-lib/src/formatters/crowdin.js'),
).pathname;

// We want to preserve the translations/ directory
await rimraf(`${TRANSLATIONS_DIR_PATH}/*`, {glob: true, preserveRoot: true});

try {
mkdirSync(TRANSLATIONS_DIR_PATH);
} catch (_) {
// Translations directory already exists
}
rmSync(TRANSLATIONS_DIR_PATH, {force: true, recursive: true});
mkdirSync(TRANSLATIONS_DIR_PATH);

const files = await glob(`${PROJECT_ROOT_DIR_PATH}/messages/**/*.json`);
const files = readdirSync(path.join(PROJECT_ROOT_DIR_PATH, 'messages'), {
withFileTypes: true,
});

const compiled = await Promise.all(
files.map(async f => {
const lang = path.parse(f).name;
const compiledMessages = await compile([f], {
const lang = path.parse(f.name).name;
const compiledMessages = await compile([path.join(f.path, f.name)], {
ast: true,
format: CROWDIN_FORMATTER_PATH,
});
Expand All @@ -67,6 +60,6 @@ for (const [lang, messages] of compiled) {
translations[lang] = messages;
}

await writeFile(TRANSLATIONS_OUTPUT_PATH, JSON.stringify(translations));
writeFileSync(TRANSLATIONS_OUTPUT_PATH, JSON.stringify(translations));

console.log(`Successfully built translations to ${TRANSLATIONS_OUTPUT_PATH}\n`);

0 comments on commit d59ec6f

Please sign in to comment.