Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .changeset/pseudo-config-schema.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@lingo.dev/_spec": patch
"lingo.dev": patch
---

fix(cli): add dev.usePseudotranslator to config schema and respect it in CLI setup
6 changes: 4 additions & 2 deletions packages/cli/src/cli/cmd/run/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export default async function setup(input: CmdRunContext) {
{
title: "Selecting localization provider",
task: async (ctx, task) => {
const provider = ctx.flags.pseudo ? "pseudo" : ctx.config?.provider;
const isPseudo = ctx.flags.pseudo || ctx.config?.dev?.usePseudotranslator;
const provider = isPseudo ? "pseudo" : ctx.config?.provider;
const vNext = ctx.config?.vNext;
ctx.localizer = createLocalizer(provider, ctx.flags.apiKey, vNext);
if (!ctx.localizer) {
Expand All @@ -72,7 +73,8 @@ export default async function setup(input: CmdRunContext) {
enabled: (ctx) =>
(ctx.localizer?.id === "Lingo.dev" ||
ctx.localizer?.id === "Lingo.dev vNext") &&
!ctx.flags.pseudo,
!ctx.flags.pseudo &&
!ctx.config?.dev?.usePseudotranslator,
task: async (ctx, task) => {
const authStatus = await ctx.localizer!.checkAuth();
if (!authStatus.authenticated) {
Expand Down
24 changes: 24 additions & 0 deletions packages/spec/src/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,30 @@ describe("I18n Config Parser", () => {
expect(result).toEqual(createV1_4Config());
});

it("should parse config with dev.usePseudotranslator", () => {
const configWithDev = {
...createV1_4Config(),
version: "1.14",
dev: {
usePseudotranslator: true,
},
};
const result = parseI18nConfig(configWithDev);

expect(result.dev?.usePseudotranslator).toBe(true);
expect(result.version).toBe("1.14");
});

it("should parse config without dev field", () => {
const configWithoutDev = {
...createV1_4Config(),
version: "1.14",
};
const result = parseI18nConfig(configWithoutDev);

expect(result.dev).toBeUndefined();
});

it("should throw an error for unsupported locales", () => {
const invalidLocaleConfig = createInvalidLocaleConfig();
expect(() => parseI18nConfig(invalidLocaleConfig)).toThrow(
Expand Down
30 changes: 29 additions & 1 deletion packages/spec/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,36 @@ export const configV1_13Definition = extendConfigDefinition(
},
);

// v1.13 -> v1.14
// Changes: Add "dev" field for development-specific settings
const devSettingsSchema = Z.object({
usePseudotranslator: Z.boolean()
.optional()
.describe(
"Use pseudotranslator instead of real translation provider. Useful for testing i18n without API calls.",
),
}).describe("Development-specific settings.");

export const configV1_14Definition = extendConfigDefinition(
configV1_13Definition,
{
createSchema: (baseSchema) =>
baseSchema.extend({
dev: devSettingsSchema.optional(),
}),
createDefaultValue: (baseDefaultValue) => ({
...baseDefaultValue,
version: "1.14",
}),
createUpgrader: (oldConfig) => ({
...oldConfig,
version: "1.14",
}),
},
);

// exports
export const LATEST_CONFIG_DEFINITION = configV1_13Definition;
export const LATEST_CONFIG_DEFINITION = configV1_14Definition;

export type I18nConfig = Z.infer<(typeof LATEST_CONFIG_DEFINITION)["schema"]>;

Expand Down