Merged in feat/syncDefaultMessage (pull request #3022)
Sync defaultMessage from lokalise * Enhance translation sync functionality and tests - Added logging for found component files during sync. - Introduced tests for handling complex components with replacements. - Updated regex in syncIntlFormatMessage to support optional second arguments. - Removed unused test files. * feat(syncDefaultMessage): add script for syncing default message with lokalise * feat(syncDefaultMessage): add script for syncing default message with lokalise Approved-by: Matilda Landström
This commit is contained in:
1
apps/scandic-redirect/.prettierignore
Normal file
1
apps/scandic-redirect/.prettierignore
Normal file
@@ -0,0 +1 @@
|
||||
netlify/functions/data/*.json
|
||||
@@ -16,10 +16,10 @@ https://scandichotelsab.sharepoint.com/:x:/s/921-ContentNewweb/ETGStOQAARtJhJXG9
|
||||
- Open it
|
||||
- Each domain/language has its own sheet
|
||||
- Export each sheet into their respective language code
|
||||
- File > Export > Download as CSV UTF-8
|
||||
- Save as [lang].csv in `./scripts/data/csv` folder
|
||||
- File > Export > Download as CSV UTF-8
|
||||
- Save as [lang].csv in `./scripts/data/csv` folder
|
||||
- Run the `generate` script target
|
||||
- E.g. `yarn workspace @scandic-hotels/scandic-redirect generate`
|
||||
- E.g. `yarn workspace @scandic-hotels/scandic-redirect generate`
|
||||
- Commit and push the JSON files in `./netlify/functions/data`.
|
||||
- Create a PR
|
||||
- Profit!
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { createReadStream } from "fs";
|
||||
import { join } from "path";
|
||||
import { createReadStream } from "fs"
|
||||
import { join } from "path"
|
||||
|
||||
export default async (req: Request) => {
|
||||
try {
|
||||
const body = await req.json();
|
||||
const body = await req.json()
|
||||
|
||||
if (body.lang && body.pathname) {
|
||||
const filePath = join(import.meta.dirname, `./data/${body.lang}.json`);
|
||||
const filePath = join(import.meta.dirname, `./data/${body.lang}.json`)
|
||||
|
||||
const redirectUrl = await new Promise<string | null>(
|
||||
(resolve, reject) => {
|
||||
@@ -14,58 +14,58 @@ export default async (req: Request) => {
|
||||
emitClose: false,
|
||||
encoding: "utf-8",
|
||||
highWaterMark: 1024,
|
||||
});
|
||||
const data: string[] = [];
|
||||
})
|
||||
const data: string[] = []
|
||||
|
||||
stream.on("data", (chunk) => {
|
||||
if (data.length === 3) {
|
||||
data.shift();
|
||||
data.shift()
|
||||
}
|
||||
data.push(chunk.toString());
|
||||
data.push(chunk.toString())
|
||||
// Since we strip trailing slash (in the trailingSlash middleware) before entering this middleware,
|
||||
// we need check matching paths both including and excluding trailing slash.
|
||||
const re = new RegExp(`"${body.pathname}\/?":"([^"]+)"`);
|
||||
const re = new RegExp(`"${body.pathname}\/?":"([^"]+)"`)
|
||||
|
||||
const match = data.join("").match(re);
|
||||
const match = data.join("").match(re)
|
||||
if (match?.[1]) {
|
||||
stream.destroy();
|
||||
resolve(match[1]);
|
||||
stream.destroy()
|
||||
resolve(match[1])
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
stream.on("error", (err) => {
|
||||
console.error("Stream error:", err);
|
||||
stream.destroy();
|
||||
reject(err);
|
||||
});
|
||||
console.error("Stream error:", err)
|
||||
stream.destroy()
|
||||
reject(err)
|
||||
})
|
||||
|
||||
stream.on("end", () => {
|
||||
stream.destroy();
|
||||
resolve(null); // No match found
|
||||
});
|
||||
stream.destroy()
|
||||
resolve(null) // No match found
|
||||
})
|
||||
}
|
||||
);
|
||||
)
|
||||
|
||||
if (redirectUrl) {
|
||||
// Make sure to exclude trailing slash in the redirectUrl to avoid an extra middleware roundtrip
|
||||
const redirectUrlWithoutTrailingSlash = redirectUrl.endsWith("/")
|
||||
? redirectUrl.slice(0, -1)
|
||||
: redirectUrl;
|
||||
: redirectUrl
|
||||
if (redirectUrlWithoutTrailingSlash === body.pathname) {
|
||||
console.log(
|
||||
`[scandic-redirect] recieved ${body.pathname}, found ${redirectUrlWithoutTrailingSlash}, no-op`
|
||||
);
|
||||
return new Response("Not Found", { status: 404 });
|
||||
)
|
||||
return new Response("Not Found", { status: 404 })
|
||||
}
|
||||
console.log(
|
||||
`[scandic-redirect] recieved ${body.pathname}, return ${redirectUrlWithoutTrailingSlash}, success`
|
||||
);
|
||||
return new Response(redirectUrlWithoutTrailingSlash);
|
||||
)
|
||||
return new Response(redirectUrlWithoutTrailingSlash)
|
||||
}
|
||||
}
|
||||
console.log(`[scandic-redirect] recieved ${body.pathname}, not found`);
|
||||
return new Response("Not Found", { status: 404 });
|
||||
console.log(`[scandic-redirect] recieved ${body.pathname}, not found`)
|
||||
return new Response("Not Found", { status: 404 })
|
||||
} catch (error) {
|
||||
return new Response("Bad request", { status: 400 });
|
||||
return new Response("Bad request", { status: 400 })
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,27 +1,28 @@
|
||||
{
|
||||
"name": "@scandic-hotels/scandic-redirect",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"packageManager": "yarn@4.6.0",
|
||||
"scripts": {
|
||||
"test": "vitest run",
|
||||
"test:watch": "vitest",
|
||||
"generate": "jiti ./scripts/generateRedirectFile/index.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@netlify/functions": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"convert-csv-to-json": "^3.4.0",
|
||||
"jiti": "^2.6.1",
|
||||
"vitest": "^3.2.4"
|
||||
},
|
||||
"prettier": {
|
||||
"semi": false,
|
||||
"trailingComma": "es5",
|
||||
"singleQuote": false,
|
||||
"printWidth": 80,
|
||||
"tabWidth": 2,
|
||||
"endOfLine": "lf"
|
||||
}
|
||||
"name": "@scandic-hotels/scandic-redirect",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"packageManager": "yarn@4.6.0",
|
||||
"scripts": {
|
||||
"test": "vitest run",
|
||||
"test:watch": "vitest",
|
||||
"generate": "jiti ./scripts/generateRedirectFile/index.ts",
|
||||
"format": "prettier --write ."
|
||||
},
|
||||
"dependencies": {
|
||||
"@netlify/functions": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"convert-csv-to-json": "^3.4.0",
|
||||
"jiti": "^2.6.1",
|
||||
"vitest": "^3.2.4"
|
||||
},
|
||||
"prettier": {
|
||||
"semi": false,
|
||||
"trailingComma": "es5",
|
||||
"singleQuote": false,
|
||||
"printWidth": 80,
|
||||
"tabWidth": 2,
|
||||
"endOfLine": "lf"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user