lingo.dev
lingo.dev copied to clipboard
SDK Modules (/packages/sdk): Implement convenience methods for common use cases
The SDK could benefit from some convenience methods that encapsulate common usage patterns, such as:
// Localize a simple key-value map
async localizeSimpleMap(
map: Record<string, string>,
params: Z.infer<typeof localizationParamsSchema>
): Promise<Record<string, string>> {
return this.localizeObject(map, params);
}
// Localize an array of strings
async localizeStringArray(
strings: string[],
params: Z.infer<typeof localizationParamsSchema>
): Promise<string[]> {
const mapped = strings.reduce((acc, str, i) => {
acc[`item_${i}`] = str;
return acc;
}, {} as Record<string, string>);
const result = await this.localizeObject(mapped, params);
return Object.values(result);
}
nice, this one is quick and easy!
(must have tests as well btw)
@maxprilutskiy can you please assign this to me?
Sure @apsinghdev, thank you for your interest. And dont forget the test coverage, please ;)