Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 29 additions & 4 deletions packages/cli/src/cli/base.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Command } from 'commander';
import { createOrUpdateConfig } from '../fs/config/setupConfig.js';
import findFilepath, { findFilepaths } from '../fs/findFilepath.js';
import findFilepath from '../fs/findFilepath.js';
import {
displayHeader,
promptText,
Expand All @@ -13,7 +13,6 @@ import {
startCommand,
createSpinner,
logMessage,
logWarning,
} from '../console/logging.js';
import path from 'node:path';
import fs from 'node:fs';
Expand Down Expand Up @@ -49,6 +48,8 @@ import {
import { getDownloaded, clearDownloaded } from '../state/recentDownloads.js';
import updateConfig from '../fs/config/updateConfig.js';
import { createLoadTranslationsFile } from '../fs/createLoadTranslationsFile.js';
import { createLoadTranslationsFile as createLoadTranslationsFileReactNative } from '../react-native/parse/createLoadTranslations.js';
import { detectEntryPoint } from '../react-native/utils/detectEntryPoint.js';
import type { SendDiffsFlags } from './commands/edits.js';
import { saveLocalEdits } from '../api/saveLocalEdits.js';

Expand Down Expand Up @@ -402,9 +403,13 @@ See the docs for more information: https://generaltranslation.com/docs/react/tut
const isUsingGTReact = packageJson
? isPackageInstalled('gt-react', packageJson)
: false;
const isUsingGTReactNative = packageJson
? isPackageInstalled('gt-react-native', packageJson)
: false;

// Ask if using another i18n library
const isUsingGT = isUsingGTNext || isUsingGTReact || ranReactSetup;
const isUsingGT =
isUsingGTNext || isUsingGTReact || isUsingGTReactNative || ranReactSetup;

// Ask where the translations are stored
const usingCDN = isUsingGT
Expand Down Expand Up @@ -432,7 +437,18 @@ See the docs for more information: https://generaltranslation.com/docs/react/tut

if (isUsingGT && !usingCDN) {
// Create loadTranslations.js file for local translations
await createLoadTranslationsFile(process.cwd(), finalTranslationsDir);
if (isUsingGTReactNative) {
// Use Expo-specific loadTranslations with configured locales
await createLoadTranslationsFileReactNative(
process.cwd(),
locales,
defaultLocale
);
} else {
// Use generic loadTranslations for Next.js and React
await createLoadTranslationsFile(process.cwd(), finalTranslationsDir);
}

logMessage(
`Created ${chalk.cyan('loadTranslations.js')} file for local translations.
Make sure to add this function to your app configuration.
Expand Down Expand Up @@ -482,12 +498,21 @@ See https://generaltranslation.com/en/docs/next/guides/local-tx`
configFilepath = 'src/gt.config.json';
}

// For Expo projects, verify entry point was detected in setup wizard
if (isUsingGTReactNative) {
const detection = detectEntryPoint(process.cwd());
logMessage(
`Verified Expo entry point: ${chalk.cyan(detection.entryPoint)}`
);
}

// Create gt.config.json
await createOrUpdateConfig(configFilepath, {
defaultLocale,
locales,
files: Object.keys(files).length > 0 ? files : undefined,
publish: isUsingGT && usingCDN,
framework: isUsingGTReactNative ? 'expo' : undefined,
});

logSuccess(
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/src/cli/commands/stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ export async function handleStage(

// Parse for React components
let reactComponents = 0;
if (library === 'gt-react' || library === 'gt-next') {
if (
library === 'gt-react' ||
library === 'gt-next' ||
library === 'gt-react-native'
) {
const updates = await aggregateReactTranslations(
options,
settings,
Expand Down
37 changes: 37 additions & 0 deletions packages/cli/src/cli/react-native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {
WrapOptions,
SupportedFrameworks,
SupportedLibraries,
} from '../types/index.js';
import { ReactCLI } from './react.js';
import { wrapContentReactNative } from '../react-native/parse/wrapContent.js';
import { Command } from 'commander';

const pkg = 'gt-react-native';

export class ReactNativeCLI extends ReactCLI {
constructor(
command: Command,
library: 'gt-react-native',
additionalModules?: SupportedLibraries[]
) {
super(command, library, additionalModules);
}
public init() {
this.setupStageCommand();
this.setupTranslateCommand();
this.setupGenerateSourceCommand();
this.setupValidateCommand();
}
public execute() {
super.execute();
}
protected wrapContent(
options: WrapOptions,
framework: SupportedFrameworks,
errors: string[],
warnings: string[]
): Promise<{ filesUpdated: string[] }> {
return wrapContentReactNative(options, pkg, framework, errors, warnings);
}
}
18 changes: 15 additions & 3 deletions packages/cli/src/cli/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const pkg = 'gt-react';
export class ReactCLI extends BaseCLI {
constructor(
command: Command,
library: 'gt-react' | 'gt-next',
library: 'gt-react' | 'gt-next' | 'gt-react-native',
additionalModules?: SupportedLibraries[]
) {
super(command, library, additionalModules);
Expand Down Expand Up @@ -154,10 +154,17 @@ export class ReactCLI extends BaseCLI {
): Promise<void> {
const settings = await generateSettings(initOptions);

const pkg =
this.library === 'gt-next'
? 'gt-next'
: this.library === 'gt-react-native'
? 'gt-react-native'
: 'gt-react';

const updates = await aggregateReactTranslations(
initOptions,
settings,
this.library === 'gt-next' ? 'gt-next' : 'gt-react'
pkg
);

// Convert updates to the proper data format
Expand Down Expand Up @@ -281,7 +288,12 @@ export class ReactCLI extends BaseCLI {
// First run the base class's handleTranslate method
const options = { ...initOptions, ...settings };

const pkg = this.library === 'gt-next' ? 'gt-next' : 'gt-react';
const pkg =
this.library === 'gt-next'
? 'gt-next'
: this.library === 'gt-react-native'
? 'gt-react-native'
: 'gt-react';

if (files && files.length > 0) {
// Validate specific files using createInlineUpdates
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/fs/determineFramework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ export function determineLibrary(): {
...packageJson.devDependencies,
};

// Check for gt-next or gt-react in dependencies
// Check for gt-next, gt-react, or gt-react-native in dependencies
if (dependencies['gt-next']) {
library = 'gt-next';
} else if (dependencies['gt-react']) {
library = 'gt-react';
} else if (dependencies['gt-react-native']) {
library = 'gt-react-native';
} else if (dependencies['next-intl']) {
library = 'next-intl';
} else if (dependencies['i18next']) {
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BaseCLI } from './cli/base.js';
import { NextCLI } from './cli/next.js';
import { ReactCLI } from './cli/react.js';
import { ReactNativeCLI } from './cli/react-native.js';
import { determineLibrary } from './fs/determineFramework.js';
import { Command } from 'commander';

Expand All @@ -11,6 +12,8 @@ export function main(program: Command) {
cli = new NextCLI(program, library, additionalModules);
} else if (library === 'gt-react') {
cli = new ReactCLI(program, library, additionalModules);
} else if (library === 'gt-react-native') {
cli = new ReactNativeCLI(program, library, additionalModules);
} else {
cli = new BaseCLI(program, library, additionalModules);
}
Expand Down
Loading
Loading