Runtime API
Lunaria can also be used outside of its build process, allowing for integrations and other use cases through its available runtime functions.
createLunaria()
Section titled “createLunaria()”Returns a Promise of a Lunaria instance to get Lunaria’s localization status during runtime, after loading and validating your configuration and running your integrations.
import { createLunaria } from '@lunariajs/core';
const lunaria = await createLunaria();const status = await lunaria.getFullStatus();createLunaria() accepts an optional object with the following properties:
config— a Lunaria configuration object to use instead of loading yourlunaria.config.*file.force— whether to ignore the cached git data and build the status from scratch, like the--forceCLI option.logLevel— the verbosity of the console output, one of'error','warn','info','debug', or'silent'. Defaults to'info'.
import { createLunaria } from '@lunariajs/core';
const lunaria = await createLunaria({ config: { // your Lunaria configuration // ... }, force: true, logLevel: 'silent',});config
Section titled “config”The final Lunaria configuration, after being validated and updated by your integrations.
const { sourceLocale, locales } = lunaria.config;getFullStatus()
Section titled “getFullStatus()”Returns a Promise of the localization status array of all the tracked files, in the same order as your files entries.
const status = await lunaria.getFullStatus();getFileStatus()
Section titled “getFileStatus()”Returns a Promise of the localization status of a single file. It accepts either the path of a source file or one of its localizations.
const status = await lunaria.getFileStatus('src/content/docs/en/getting-started.mdx');gitHostingLinks()
Section titled “gitHostingLinks()”Returns an object of functions to generate links to your files in the git hosting platform set in your repository configuration, the same links used in the dashboard:
source(path)— the link to view a file in the tracked branch.history(path, since?)— the link to the commit history of a file, optionally starting from an ISO date.create(path)— the link to create a file at the specified path, e.g. for a missing localization.clone()— the URL to clone the repository.
const links = lunaria.gitHostingLinks();
const sourceLink = links.source('src/content/docs/en/guide.mdx');const historyLink = links.history('src/content/docs/en/guide.mdx', '2024-01-01T00:00:00.000Z');generateDashboard()
Section titled “generateDashboard()”Returns the HTML of your localization dashboard for the specified configuration and status, the same way lunaria build does.
import { createLunaria, generateDashboard } from '@lunariajs/core';
const lunaria = await createLunaria();const status = await lunaria.getFullStatus();
const dashboard = generateDashboard(lunaria.config, status);