Skip to content

useModule ​

Derives i18n-translated module names, permission key, and layout metadata from a component's name / moduleName / routeName props. Used by table and page components to display localised module titles without hardcoding strings.

File: vue/src/js/hooks/useModule.js
Props factory: makeModuleProps


Usage ​

js
import { useModule, makeModuleProps } from '@/hooks'

const props = defineProps({ ...makeModuleProps() })
const {
  transNameSingular,
  transNamePlural,
  permissionName,
  snakeName,
  searchPlaceholder
} = useModule(props, context)
html
<h1>{{ transNamePlural }}</h1>
<p>{{ searchPlaceholder }}</p>

Props (via makeModuleProps) ​

PropTypeDefaultDescription
nameString—Module or route name (used for i18n and permission key)
customTitleString—Override the translated plural name
titlePrefixString''Prepend a string to the title
titleKeyString'name'Key used for the display title
fillHeightBooleanfalseExpand component to fill container height
slotsObject{}Slot overrides
noFullScreenBooleanfalseDisable fullscreen toggle
endpointsObject{}Endpoint URL map
itemsArray[]Initial item list

Returns ​

NameTypeDescription
snakeNameString_.snakeCase(props.name)
moduleSnakeNameString_.snakeCase(props.moduleName ?? props.name)
routeSnakeNameString_.snakeCase(props.routeName ?? props.name)
tableTranslationNotationStringFull dot-notation i18n key, e.g. modules.blog.posts.name
transNameSingularComputedRef<String>t(notation, 0) — singular form
transNamePluralComputedRef<String>t(notation, 1) — plural form
permissionNameComputedRef<String>_.kebabCase(name) — used for permission checks
searchPlaceholderStringt('Type to Search')
searchModelStringInitial empty search string
elementsArrayInitial items from props.items
windowSizeObject{ x, y } — updated by onResize
onResizeFunctionUpdates windowSize from window.innerWidth/Height

Translation key structure ​

The hook resolves i18n keys from modules.*:

// For a module named 'Blog' with route 'Post':
tableTranslationNotation = 'modules.blog.post.name'

// In your lang file:
{
  modules: {
    blog: {
      post: { name: 'Post | Posts' }
    }
  }
}

See Also ​