Skip to content

Miscellaneous

Shared Translations

Shared translations provide common static text that is available across all sections in your project. Use them for repeated phrases like "Read More", "Add to Cart", or other text shared between multiple sections.

Shared translations live in a single file at the project root:

shared/
└── translation.ts

The format is the same as section-level translations — a record keyed by language code:

typescript
// shared/translation.ts
export default {
  en: {
    '$label.shared.title': 'Title',
    '$label.shared.description': 'Description',
    '$label.shared.read_more': 'Read More',
  },
  fr: {
    '$label.shared.title': 'Titre',
    '$label.shared.description': 'Description',
    '$label.shared.read_more': 'Lire la suite',
  },
} as const;

💡 Convention

Use the $label.shared.* prefix for shared translation keys to distinguish them from section-specific keys.

Shared translations are automatically injected into every section at build time. Access them in your Vue components using the useTranslation composable:

vue
<template>
  <a>{{ t('$label.shared.read_more') }}</a>
</template>

ℹ️ Hot Reload

Changes to shared/translation.ts trigger a full rebuild in preview mode.

Factory Methods

All configuration objects in Crane are created using factory functions from @lightspeed/crane-api. Factories accept a typed config object, auto-inject the type discriminator field, and return a fully typed result.

FactoryPurposeDetails
contentContent editor definitionsContent Editors
designDesign editor definitionsDesign Editors
layoutLayout configurations and design overridesLayout
showcaseShowcase configurationsShowcases
templateTemplate configuration and page definitionsTemplates
sectionSection references in pages (default, custom, store)Templates — Pages
translationTranslation settingsTranslations

The content and design factories also provide content.default.*() and design.default.*() sub-factories for creating standalone default values used in showcases.

typescript
import { content, design, layout, showcase, template, section, translation } from '@lightspeed/crane-api';

Linting

Crane provides @lightspeed/eslint-config-crane — a preconfigured ESLint setup for section development. The template scaffolds an eslint.config.cjs that consumes it as a one-liner:

javascript
// eslint.config.cjs
module.exports = require('@lightspeed/eslint-config-crane');

What It Includes

  • Vue 3eslint-plugin-vue with recommended rules
  • TypeScript@vue/eslint-config-typescript recommended rules
  • Scoped CSSeslint-plugin-vue-scoped-css recommended rules
  • Accessibilityeslint-plugin-vuejs-accessibility

Notable Rules

RuleSettingDescription
vue/component-api-stylescript-setup, compositionOnly Composition API with <script setup> allowed
max-len160Maximum line length for .ts and .vue files
no-consolewarnConsole statements produce warnings
no-debuggerwarnDebugger statements produce warnings

Running the Linter

The template does not include a lint script by default. Run ESLint directly:

bash
npx eslint "./**/*.{js,ts}"

Or add a script to your package.json:

json
{
  "scripts": {
    "lint": "eslint \"./**/*.{js,ts}\""
  }
}

Advanced Composables

These composables are exported from @lightspeed/crane-api for advanced use cases. Most sections won't need them.

useVueBaseProps

Low-level composable providing reactive access to the full section context:

  • context — store and environment information
  • content — raw content data
  • design — raw design data
  • defaults — default values
  • site — site configuration (languages, currency, etc.)
  • category — current category data (on category pages)
  • storeData — store metadata
  • globalDesign — global design settings (colors, fonts, text sizes)
  • tileId — the section's tile identifier

Use this when the typed content/design composables are not sufficient — for example, when accessing global design tokens directly or reading site-level configuration.

useInstantsiteJsApi

Returns window.instantsite — the platform's JavaScript API for interacting with the storefront runtime (e.g., triggering cart updates, navigation events).

typescript
import { useInstantsiteJsApi } from '@lightspeed/crane-api';

const api = useInstantsiteJsApi();

⚠️ Client-Only

This is a client-only API. Guard usage with typeof window !== 'undefined' or call it inside onMounted. See SSR vs Client-Only Rendering.