Skip to content

Commit fbce978

Browse files
committed
feat: add --bucket flag to replexica i18n cmd
1 parent a04f6af commit fbce978

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

.changeset/gold-badgers-taste.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@replexica/cli": patch
3+
---
4+
5+
Add --bucket flag to replexica i18n cmd

packages/cli/src/i18n.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Ora from 'ora';
66
import _ from 'lodash';
77
import { createBucketProcessor } from './workers/bucket';
88
import { createEngine } from './workers/engine';
9-
import { allLocalesSchema } from '@replexica/spec';
9+
import { targetLocaleSchema } from '@replexica/spec';
1010
import { createLockfileProcessor } from './workers/lockfile';
1111
import { createAuthenticator } from './workers/auth';
1212

@@ -15,6 +15,7 @@ export default new Command()
1515
.description('Run AI localization engine')
1616
.helpOption('-h, --help', 'Show help')
1717
.option('--locale <locale>', 'Locale to process')
18+
.option('--bucket <bucket>', 'Bucket to process')
1819
.option('--force', 'Ignore lockfile and process all keys')
1920
.action(async function(options) {
2021
const ora = Ora();
@@ -34,6 +35,10 @@ export default new Command()
3435
throw new Error('i18n.json not found. Please run `replexica init` to initialize the project.');
3536
} else if (!i18nConfig.buckets || !Object.keys(i18nConfig.buckets).length) {
3637
throw new Error('No buckets found in i18n.json. Please add at least one bucket containing i18n content.');
38+
} else if (flags.locale && !i18nConfig.locale.targets.includes(flags.locale)) {
39+
throw new Error(`Source locale ${i18nConfig.locale.source} does not exist in i18n.json locale.targets. Please add it to the list and try again.`);
40+
} else if (flags.bucket && !i18nConfig.buckets[flags.bucket]) {
41+
throw new Error(`Bucket ${flags.bucket} does not exist in i18n.json. Please add it to the list and try again.`);
3742
} else {
3843
ora.succeed('Replexica configuration loaded');
3944
}
@@ -57,7 +62,8 @@ export default new Command()
5762
ora.succeed('AI localization engine connected');
5863

5964
const lockfileProcessor = createLockfileProcessor();
60-
for (const [bucketPath, bucketType] of Object.entries(i18nConfig.buckets)) {
65+
const targetedBuckets = flags.bucket ? { [flags.bucket]: i18nConfig.buckets[flags.bucket] } : i18nConfig.buckets;
66+
for (const [bucketPath, bucketType] of Object.entries(targetedBuckets)) {
6167
console.log('');
6268
const bucketOra = Ora({ });
6369
// Create the payload processor instance for the current bucket type
@@ -138,7 +144,8 @@ export default new Command()
138144

139145
async function loadFlags(options: any) {
140146
return Z.object({
141-
locale: allLocalesSchema.optional(),
147+
locale: targetLocaleSchema.optional(),
148+
bucket: Z.string().optional(),
142149
force: Z.boolean().optional(),
143150
}).parse(options);
144151
}

0 commit comments

Comments
 (0)