Skip to content

Commit e919eba

Browse files
maxprilutskiymainstar123
authored andcommitted
feat: simplify locale resolution (lingodotdev#165)
* chore: add editorconfig * feat(spec): simplify locale resolution
1 parent 1b4a92e commit e919eba

5 files changed

Lines changed: 96 additions & 265 deletions

File tree

.changeset/odd-hornets-taste.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@replexica/spec": minor
3+
"@replexica/sdk": minor
4+
"replexica": minor
5+
"@replexica/cli": minor
6+
---
7+
8+
Update locale code resolution logic

.editorconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
insert_final_newline = true

packages/sdk/src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Z from 'zod';
2-
import { sourceLocaleSchema, targetLocaleSchema, allLocalesSchema } from '@replexica/spec';
2+
import { localeCodeSchema } from '@replexica/spec';
33
import { createId } from "@paralleldrive/cuid2";
44

55
const engineParamsSchema = Z.object({
@@ -24,12 +24,12 @@ const payloadSchema = Z.record(
2424
);
2525

2626
const localizationParamsSchema = Z.object({
27-
sourceLocale: sourceLocaleSchema,
28-
targetLocale: targetLocaleSchema,
27+
sourceLocale: localeCodeSchema,
28+
targetLocale: localeCodeSchema,
2929
});
3030

3131
const referenceSchema = Z.record(
32-
allLocalesSchema,
32+
localeCodeSchema,
3333
payloadSchema,
3434
);
3535

@@ -178,4 +178,4 @@ export class ReplexicaEngine {
178178
return 0;
179179
}
180180
}
181-
}
181+
}

packages/spec/src/config.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import Z from 'zod';
2-
import { allLocalesSchema, sourceLocaleSchema, targetLocaleSchema } from './locales';
2+
import { localeCodeSchema } from './locales';
33
import { bucketTypeSchema } from './formats';
44

55
// common
66
export const localeSchema = Z.object({
7-
source: sourceLocaleSchema,
8-
targets: Z.array(targetLocaleSchema),
7+
source: localeCodeSchema,
8+
targets: Z.array(localeCodeSchema),
99
});
1010

1111
// factories
@@ -139,7 +139,7 @@ export const configV1_1Definition = extendConfigDefinition(configV1Definition, {
139139
export const configV1_2Definition = extendConfigDefinition(configV1_1Definition, {
140140
createSchema: (baseSchema) => baseSchema.extend({
141141
locale: localeSchema.extend({
142-
extraSource: allLocalesSchema.optional(),
142+
extraSource: localeCodeSchema.optional(),
143143
}),
144144
}),
145145
createDefaultValue: (baseDefaultValue) => ({
@@ -166,4 +166,4 @@ export function parseI18nConfig(rawConfig: unknown) {
166166
}
167167
}
168168

169-
export const defaultConfig = LATEST_CONFIG_DEFINITION.defaultValue;
169+
export const defaultConfig = LATEST_CONFIG_DEFINITION.defaultValue;

0 commit comments

Comments
 (0)