Skip to content

Commit 11d121e

Browse files
committed
chore: cleanup translation-server
There were a bunch of leftover from experiments. e.g. _lingoConfig was a hack, a field with a config copy added to the config object which can be read by the translation-server cli to parse the arguments. But bundlers were always complaining about it, plus in next with our async setup it would not work. So there is no way to parse the config now. We could add some though if needed, but honestly parsing the file and finding our config section.
1 parent 2d676c8 commit 11d121e

File tree

7 files changed

+148
-493
lines changed

7 files changed

+148
-493
lines changed

packages/new-compiler/src/plugin/next.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -210,31 +210,39 @@ export async function withLingo(
210210
// We have two barriers, a simple one here and a more complex one inside the startTranslationServer which doesn't start the server if it can find one running.
211211
// We do not use isMainRunner here, because we need to start the server as early as possible, so the loaders get the translation server url. The main runner in dev mode runs after a dev server process is started.
212212
if (isDev && !process.env.LINGO_TRANSLATION_SERVER_URL) {
213-
const translationServer = await startOrGetTranslationServer({
214-
translationService: new TranslationService(lingoConfig, logger),
215-
onError: (err) => {
216-
logger.error("Translation server error:", err);
217-
},
218-
onReady: (port) => {
219-
logger.info(`Translation server started successfully on port: ${port}`);
220-
},
221-
config: lingoConfig,
222-
});
223-
process.env.LINGO_TRANSLATION_SERVER_URL = translationServer.url;
224-
if (translationServer.server) {
225-
// We start the server in the same process, so we should be fine without any sync cleanup. Server should be killed with the process.
226-
registerCleanupOnCurrentProcess({
227-
asyncCleanup: async () => {
228-
await translationServer.server.stop();
213+
if (lingoConfig.dev.translationServerUrl) {
214+
logger.info(`Using existing translation server URL (${lingoConfig.dev.translationServerUrl}) from config`);
215+
process.env.LINGO_TRANSLATION_SERVER_URL =
216+
lingoConfig.dev.translationServerUrl;
217+
} else {
218+
const translationServer = await startOrGetTranslationServer({
219+
translationService: new TranslationService(lingoConfig, logger),
220+
onError: (err) => {
221+
logger.error("Translation server error:", err);
229222
},
223+
onReady: (port) => {
224+
logger.info(
225+
`Translation server started successfully on port: ${port}`,
226+
);
227+
},
228+
config: lingoConfig,
230229
});
230+
process.env.LINGO_TRANSLATION_SERVER_URL = translationServer.url;
231+
if (translationServer.server) {
232+
// We start the server in the same process, so we should be fine without any sync cleanup. Server should be killed with the process.
233+
registerCleanupOnCurrentProcess({
234+
asyncCleanup: async () => {
235+
await translationServer.server.stop();
236+
},
237+
});
238+
}
231239
}
232240
}
233241

234242
const translationServerUrl = process.env.LINGO_TRANSLATION_SERVER_URL;
235243

236244
if (isMainRunner()) {
237-
// We need to cleaup the file only once, to avoid having extra translation introduced into the build, or old translation to pile up.
245+
// We need to clean up the file only once to avoid having extra translation introduced into the build, or old translation to pile up.
238246
cleanupExistingMetadata(metadataFilePath);
239247

240248
registerCleanupOnCurrentProcess({

0 commit comments

Comments
 (0)