auto-localization
Version:
A powerful tool to automatically extract text strings from React Native (or React) components and generate localization files. Supports generating JSON or JavaScript/TypeScript constants files for easy integration with your app's localization system.
38 lines (31 loc) • 1.23 kB
JavaScript
const fs = require('fs-extra');
const path = require('path');
const extractStrings = require('./extractStrings');
const run = () => {
const args = process.argv.slice(2);
// If no arguments or incorrect usage, show the help
if (args.length !== 2 && args.length !== 1) {
console.log('Usage: auto-localization <directory-or-file-path> <output-file-name>');
console.log('Usage for extracting from a single file: auto-localization <file-path> <output-file-name>');
process.exit(1);
}
const inputPath = args[0];
const outputFileName = args[1] || 'localization.json'; // Default to localization.json if not provided
// If the input is a file
if (fs.existsSync(inputPath) && fs.statSync(inputPath).isFile()) {
console.log(`Extracting strings from file: ${inputPath}`);
extractStrings(inputPath, outputFileName);
}
// If the input is a directory
else if (fs.existsSync(inputPath) && fs.statSync(inputPath).isDirectory()) {
console.log(`Extracting strings from directory: ${inputPath}`);
extractStrings(inputPath, outputFileName);
}
// If the input path is invalid
else {
console.log('Invalid directory or file path!');
process.exit(1);
}
};
run();