Created
June 24, 2025 20:47
-
-
Save fusionstrings/fcd8cce323cfcbff239fef70836a9639 to your computer and use it in GitHub Desktop.
inlang sdk experiment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { loadProjectInMemory, newProject } from "@inlang/sdk"; | |
import { writeFile } from "node:fs"; | |
import { readFile } from "node:fs/promises"; | |
const project = await loadProjectInMemory({ | |
blob: await newProject({ | |
settings: { | |
baseLocale: "en", | |
locales: ["en"], | |
modules: [ | |
"https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format@latest/dist/index.js", | |
], | |
}, | |
}), | |
}); | |
// Accessing settings and plugins | |
const settings = await project.settings.get(); | |
const plugins = await project.plugins.get(); | |
console.log("settings"); | |
console.log(settings); | |
console.log("plugins"); | |
console.log(plugins); | |
await project.settings.set({ | |
...settings, | |
modules: [ | |
...(settings.modules ?? []), | |
"https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format@latest/dist/index.js", | |
], | |
}); | |
const project2 = await loadProjectInMemory({ | |
blob: await project.toBlob(), | |
}); | |
const settings2 = await project2.settings.get(); | |
const plugins2 = await project2.plugins.get(); | |
console.log("settings2"); | |
console.log(settings2); | |
console.log("plugins2"); | |
console.log(plugins2); | |
const file = await readFile("./i18n/locales/en.json"); | |
// Import files | |
await project.importFiles({ | |
pluginKey: "plugin.inlang.messageFormat", | |
files: [ | |
{ locale: "en", content: file }, | |
], | |
}); | |
// Querying messages | |
const messages = await project.db | |
.selectFrom("message") | |
.selectAll() | |
.execute(); | |
console.log(messages); | |
// Create a new project | |
// const file = await newProject(); | |
// // write the file anywhere you want | |
// const buffer = Buffer.from(await file.arrayBuffer()); | |
// await writeFile("./sdk/project.inlang", buffer, (err) => { | |
// if (err) throw err; | |
// console.log('The file has been saved!'); | |
// }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment