mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-09-14 23:00:12 -04:00
119 lines
3.2 KiB
JavaScript
119 lines
3.2 KiB
JavaScript
/* eslint no-console: 0 */
|
|
|
|
import fs from "fs";
|
|
import path from "path";
|
|
import yargs from "yargs";
|
|
|
|
import {
|
|
copyAndroidTitle,
|
|
removeUnsupportedDirectories,
|
|
renameDirectories,
|
|
} from "./i18ncli/fastlane";
|
|
import {
|
|
jsonifyLocalizations,
|
|
normalize,
|
|
normalizeFileNames,
|
|
supportedLocales,
|
|
untranslatable,
|
|
unused,
|
|
validate,
|
|
} from "./i18ncli/ftl";
|
|
|
|
// Write src/i18n/loadTranslations.ts, a file with a function that
|
|
// statically loads translation files given a locale
|
|
const writeLoadTranslations = async ( ) => {
|
|
const locales = await supportedLocales( );
|
|
const outPath = path.join( __dirname, "..", "src", "i18n", "loadTranslations.ts" );
|
|
const out = fs.createWriteStream( outPath );
|
|
const repoRoot = path.join( __dirname, ".." );
|
|
const commentPath = path.relative( repoRoot, __filename );
|
|
out.write( `// AUTO-GENERATED. See ${commentPath}\n` );
|
|
out.write( "export default ( locale: string ): Record<string, unknown> => {\n" );
|
|
locales.forEach(
|
|
locale => out.write(
|
|
` if ( locale === "${locale}" ) { return require( "./l10n/${locale}.ftl.json" ); }\n`,
|
|
),
|
|
);
|
|
out.write( " return require( \"./l10n/en.ftl.json\" );\n" );
|
|
out.write( "};\n" );
|
|
out.write( "\n" );
|
|
out.write( "export const SUPPORTED_LOCALES = [\n" );
|
|
out.write( locales.sort( ).map( l => ` "${l}",` ).join( "\n" ) );
|
|
out.write( "\n];\n" );
|
|
};
|
|
|
|
// eslint-disable-next-line no-unused-expressions, @typescript-eslint/no-unused-expressions
|
|
yargs
|
|
.usage( "Usage: $0 <cmd> [args]" )
|
|
.option( "verbose", {
|
|
alias: "v",
|
|
type: "boolean",
|
|
description: "Run with verbose logging",
|
|
} )
|
|
.command(
|
|
"build",
|
|
"Prepare existing localizations for use in the app",
|
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
( ) => {},
|
|
async argv => {
|
|
// Make sure all files are iNat locales before validating and
|
|
// normalizing FT
|
|
await normalizeFileNames( );
|
|
await validate( );
|
|
await normalize( );
|
|
await untranslatable( );
|
|
await unused( );
|
|
jsonifyLocalizations( argv );
|
|
writeLoadTranslations( );
|
|
},
|
|
)
|
|
.command(
|
|
"checkify",
|
|
"Prepend translations w/ ✅ to help see unglobalized text",
|
|
( ) => undefined,
|
|
async argv => {
|
|
jsonifyLocalizations( { ...argv, checkify: true } );
|
|
writeLoadTranslations( );
|
|
},
|
|
)
|
|
.command(
|
|
"validate",
|
|
"Validate source strings",
|
|
( ) => undefined,
|
|
_argv => {
|
|
validate( );
|
|
},
|
|
)
|
|
.command(
|
|
"unused",
|
|
"List unused translation keys",
|
|
( ) => undefined,
|
|
_argv => {
|
|
unused( );
|
|
},
|
|
)
|
|
.command(
|
|
"untranslatable",
|
|
"List translation keys in source code but not in strings.ftl",
|
|
( ) => undefined,
|
|
_argv => {
|
|
untranslatable( );
|
|
},
|
|
)
|
|
.command(
|
|
"prepare-fastlane-metadata",
|
|
"Prepare existing localizations for uploading metadata via Fastlane",
|
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
( ) => {},
|
|
async argv => {
|
|
console.log( "Renaming directories..." );
|
|
await renameDirectories( argv );
|
|
console.log( "Removing unsupported directories..." );
|
|
await removeUnsupportedDirectories( argv );
|
|
console.log( "Copying Android title..." );
|
|
await copyAndroidTitle( argv );
|
|
},
|
|
)
|
|
.help( )
|
|
.argv;
|