Files
myeasycms-v2/apps/dev-tool/app/translations/lib/server-actions.ts
Giancarlo Buomprisco 68276fda8a chore: bump version to 2.23.13 and update dependencies (#450)
* chore: bump version to 2.23.13 and update dependencies

- Updated application version from 2.23.12 to 2.23.13 in package.json.
- Upgraded several dependencies including @marsidev/react-turnstile to 1.4.2, @next/bundle-analyzer to 16.1.6, @next/eslint-plugin-next to 16.1.6, and others for improved functionality and security.
- Adjusted package versions in pnpm-lock.yaml and pnpm-workspace.yaml for consistency across the project.
- Removed unused AI translation functionality from translations-comparison component to streamline the codebase.

* refactor: clean up code formatting and update Stripe API version

- Removed unnecessary blank lines in LineItemDetails component for improved readability.
- Enhanced formatting in PricingItem component for better clarity.
- Updated Stripe API version from '2025-12-15.clover' to '2026-01-28.clover' for compatibility with the latest features.
- Adjusted i18n initialization in email templates for consistency.
- Reformatted props in AdminReactivateUserDialog for better structure.
- Cleaned up type imports in ImageUploadInput component.
2026-02-06 12:55:05 +01:00

62 lines
1.7 KiB
TypeScript

'use server';
import { revalidatePath } from 'next/cache';
import { readFileSync, writeFileSync } from 'node:fs';
import { resolve } from 'node:url';
import { z } from 'zod';
const Schema = z.object({
locale: z.string().min(1),
namespace: z.string().min(1),
key: z.string().min(1),
value: z.string(),
});
/**
* Update a translation value in the specified locale and namespace.
* @param props
*/
export async function updateTranslationAction(props: z.infer<typeof Schema>) {
// Validate the input
const { locale, namespace, key, value } = Schema.parse(props);
const root = resolve(process.cwd(), '..');
const filePath = `${root}apps/web/public/locales/${locale}/${namespace}.json`;
try {
// Read the current translations file
const translationsFile = readFileSync(filePath, 'utf8');
const translations = JSON.parse(translationsFile) as Record<string, any>;
// Update the nested key value
const keys = key.split('.') as string[];
let current = translations;
// Navigate through nested objects until the second-to-last key
for (let i = 0; i < keys.length - 1; i++) {
const currentKey = keys[i] as string;
if (!current[currentKey]) {
current[currentKey] = {};
}
current = current[currentKey];
}
// Set the value at the final key
const finalKey = keys[keys.length - 1] as string;
current[finalKey] = value;
// Write the updated translations back to the file
writeFileSync(filePath, JSON.stringify(translations, null, 2), 'utf8');
revalidatePath(`/translations`);
return { success: true };
} catch (error) {
console.error('Failed to update translation:', error);
throw new Error('Failed to update translation');
}
}