Skip to content

msg and defineMessage

msg and defineMessage define message descriptors without translating them immediately. msg is an alias for defineMessage; they are functionally identical.

They are the right tools when the message needs to be stored, exported, reused across files, or translated later by a different renderer or runtime boundary.

For the framework-agnostic Lingui semantics, see the official msg and defineMessage reference.

Source
<script lang="ts">
  import { defineMessage, msg, t } from "lingui-for-svelte/macro";

  const submitLabel = defineMessage({
    id: "form.submit",
    message: "Submit",
  });
  let welcome = $derived(msg`Welcome back, ${name}`);
</script>

<p class="mb-2">
  {$t(welcome)}
</p>

<button type="button" class="rounded bg-blue-500 px-4 py-2 text-white">
  {$t(submitLabel)}
</button>
Result

Welcome back, Lingui

Locale
Name
<script lang="ts">
import { defineMessage, msg, t } from "lingui-for-svelte/macro";
const welcome = msg`Welcome back`;
const submitLabel = defineMessage({
id: "form.submit",
message: "Submit",
});
</script>
<p>{$t(welcome)}</p>
  • the translation should happen later, not at definition time
  • the same descriptor will be reused across files or renderers
  • you want plain TypeScript or JavaScript to stay close to official Lingui Core patterns

For plain .js and .ts files, prefer the official @lingui/core/macro package. Framework-specific packages are for framework syntax, not for generic descriptor authoring.