PHPackages                             dennis-koster/lighthouse-translatable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. dennis-koster/lighthouse-translatable

ActiveLibrary[API Development](/categories/api)

dennis-koster/lighthouse-translatable
=====================================

Adds translatable directive for automatic schema generation for translatable fields

1.0.0(1y ago)12.5k↓33.3%MITPHPCI passing

Since Sep 27Pushed 1y ago1 watchersCompare

[ Source](https://github.com/dennis-koster/lighthouse-translatable)[ Packagist](https://packagist.org/packages/dennis-koster/lighthouse-translatable)[ Docs](https://github.com/dennis-koster/lighthouse-translatable)[ RSS](/packages/dennis-koster-lighthouse-translatable/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (13)Used By (0)

Lighthouse Translatable
=======================

[](#lighthouse-translatable)

This package will make generation of GraphQL types for translatable type definitions a breeze. It ships the `@translatable` directive, which can be applied to any GraphQL type definition.

The directive will look for any attributes of the `TranslatableString` scalar type, also included in this package, and include it in the types it generates. It will respect nullable states of attributes when generating the type definitions.

The directive can generate two types of GraphQL types, based off the main type the directive gets applied to:

- A translation type: an individual type definition containing all the attributes that are translatable, along with its locale
- An input type: an input definition, containing all the attributes that are translatable, along with its locale

Installation
------------

[](#installation)

The package can be installed through composer.

```
composer require dennis-koster/lighthouse-translatable
```

Package compatibility
---------------------

[](#package-compatibility)

The package is completely agnostic of any translations package you might use for saving and retrieving translations to and from the database. This package focuses solely on generating schema definitions.

Its only dependency is on `nuwave/lighthouse` version `6` or higher.

Arguments
---------

[](#arguments)

The directive comes with a couple of arguments, all of them optional.

ArgumentDescriptionDefault**generateTranslationType**Whether or not to generate a type for the translation definition.Boolean: `True`**translationTypeName**The name of the type to be generated for the translation definition.String: `Translation`**translationsFieldName**The name of the field that holds the array of translations.String: `translations`**translationsInputName**The name of the input that holds the array of translations inputs.String: `translations`**generateInputType**Whether or not to generate a type for the translation input definition.Boolean: `True`**inputTypeName**The name of the type to be generated for the translation input definition.String: `TranslationInput`**appendInput**The inputs the translation model input should be appended to.Array: \[\]The default values for the arguments may be altered through the publishable config file.

Basic usage
-----------

[](#basic-usage)

In its most primal form, the directive uses some sensible defaults. It will always generate a translation definition and a translation input definition for the type the directive is applied to.

It will take the name of the base type, in the example below `NewsItem` and append `Translation` (so `NewsItemTranslation`) for the translation definition, and `TranslationInput` for the translation input definition (`NewsItemTranslationInput`).

An attribute will be added to the base type definition, holding the translation definitions. By default, the attribute will be called `translations` but this is customizable through the `translationsAttribute` argument.

```
type NewsItem @translatable
{
    id: ID!
    title: TranslatableString!
    introduction: TranslatableString
}

# Will result in the following schema definition
type NewsItem
{
    id: ID!
    title: TranslatableString!
    introduction: TranslatableString
    translations: [NewsItemTranslation!]! # Added through the directive
}

type NewsItemTranslation {
    locale: String!
    title: String!
    introduction: String
}

input NewsItemTranslationInput {
    locale: String!
    title: String!
    introduction: String
}
```

Append input type to existing inputs
------------------------------------

[](#append-input-type-to-existing-inputs)

It's possible to provide the directive an array of existing inputs you want to append a translations argument to, through the `appendInput` argument.

The attribute will be called `translations` by default, and can be changed through the `translationsAttribute` argument.

```
type NewsItem @translatable(appendInput: ["CreateNewsItemInput"])
{
    id: ID!
    slug: String!
    title: TranslatableString!
    introduction: TranslatableString
}

input CreateNewsItemInput {
    slug: String!
}

# Will append the translations attribute to the CreateNewsItemInput
input CreateNewsItemInput {
    slug: String!
    translations: [NewsItemTranslationInput!]!
}
```

Customize type names and attribute name
---------------------------------------

[](#customize-type-names-and-attribute-name)

It's possible to customize the names of the type definitions that are generated, as well as the name of the attribute it appends to existing type definitions.

```
type NewsItem @translatable(
    translationTypeName: "FooBarTranslation"
    inputTypeName: "FooBarTranslationInput"
    translationsAttribute: "localizations"
    appendInput: ["CreateNewsItemInput"]
) {
    id: ID!
    title: TranslatableString!
    introduction: TranslatableString
}

input CreateNewsItemInput {
    slug: String!
}

# Will result in the following schema definition
type NewsItem
{
    id: ID!
    title: TranslatableString!
    introduction: TranslatableString
    localizations: [FooBarTranslation!]!
}

input CreateNewsItemInput {
    slug: String!
    localizations: [FooBarTranslationInput!]!
}

type FooBarTranslation {
    locale: String!
    title: String!
    introduction: String
}

input FooBarTranslationInput {
    locale: String!
    title: String!
    introduction: String
}
```

Configuration
-------------

[](#configuration)

The directive comes with a configuration file that can be published through:

```
php artisan vendor:publish --provider=DennisKoster\\LighthouseTranslatable\\Providers\\LighthouseTranslatableProvider
```

Through the configuration file, all the default values for the directive may be adjusted to your liking.

View stubs
----------

[](#view-stubs)

The generated types are created using blade views. These blade views can also be published and adjusted to your needs.

**Blade view overview**

```
type NewsItem @translatable(appendInput: ["CreateNewsItemInput"])
{
    id: ID!
    title: TranslatableString!
    introduction: TranslatableString
}

input CreateNewsItemInput {
    slug: String!
}

# Will result in the following schema definition
type NewsItem
{
    id: ID!
    title: TranslatableString!
    introduction: TranslatableString
    translations: [NewsItemTranslation!]! # translations-field.blade.php
}

input CreateNewsItemInput {
    slug: String!
    translations: [NewsItemTranslationInput!]! # translations-input.blade.php
}

type NewsItemTranslation {
    locale: String! # translatable-attribute-field.blade.php
    title: String! # translatable-attribute-field.blade.php
    introduction: String # translatable-attribute-field.blade.php
}

input NewsItemTranslationInput {
    locale: String! # translatable-attribute-input.blade.php
    title: String! # translatable-attribute-input.blade.php
    introduction: String # translatable-attribute-input.blade.php
}
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance42

Moderate activity, may be stable

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~12 days

Recently: every ~23 days

Total

11

Last Release

471d ago

Major Versions

0.5.0 → 1.0.02025-01-24

### Community

Maintainers

![](https://www.gravatar.com/avatar/48a35604e924d56a81bff335b7e1f2dce0fb905b86e379f804207dbb956b9b40?d=identicon)[denniskoster](/maintainers/denniskoster)

---

Top Contributors

[![dennis-koster](https://avatars.githubusercontent.com/u/8804219?v=4)](https://github.com/dennis-koster "dennis-koster (5 commits)")

---

Tags

typelaraveltranslationsgraphqltranslatablelighthouse

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dennis-koster-lighthouse-translatable/health.svg)

```
[![Health](https://phpackages.com/badges/dennis-koster-lighthouse-translatable/health.svg)](https://phpackages.com/packages/dennis-koster-lighthouse-translatable)
```

###  Alternatives

[nuwave/lighthouse

A framework for serving GraphQL from Laravel

3.5k10.7M93](/packages/nuwave-lighthouse)[joselfonseca/lighthouse-graphql-passport-auth

Add GraphQL types and mutations for login and recover password functionalities

234769.9k1](/packages/joselfonseca-lighthouse-graphql-passport-auth)[yakovenko/laravel-lighthouse-graphql-multi-schema

A Laravel package that provides multi-schema support for Lighthouse GraphQL.

1562.5k](/packages/yakovenko-laravel-lighthouse-graphql-multi-schema)[mll-lab/laravel-graphiql

Easily integrate GraphiQL into your Laravel project

683.2M9](/packages/mll-lab-laravel-graphiql)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
