PHPackages                             sirgrimorum/transarticles - 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. [Localization &amp; i18n](/categories/localization)
4. /
5. sirgrimorum/transarticles

ActiveLibrary[Localization &amp; i18n](/categories/localization)

sirgrimorum/transarticles
=========================

Localization using db table as source for translated text

1.3.4(2mo ago)0275↓50%1MITPHPPHP ^8.2CI failing

Since Feb 17Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/sirgrimorum/transarticles)[ Packagist](https://packagist.org/packages/sirgrimorum/transarticles)[ Docs](http://desarrollo.grimorum.com/andres/transarticles)[ RSS](/packages/sirgrimorum-transarticles/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (22)Used By (1)

TransArticles
=============

[](#transarticles)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8e9951d408a9131c0fc42d21836236800ccb084406648ed82ba40ae2b936420e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7369726772696d6f72756d2f7472616e7361727469636c65732e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/8e9951d408a9131c0fc42d21836236800ccb084406648ed82ba40ae2b936420e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7369726772696d6f72756d2f7472616e7361727469636c65732e7376673f7374796c653d666c61742d737175617265)[![PHP Version](https://camo.githubusercontent.com/08d4177ebcfea9249ae66bec1a8bfc609263b38032741afd2585ba5bfd91e3e8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7369726772696d6f72756d2f7472616e7361727469636c65732e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/08d4177ebcfea9249ae66bec1a8bfc609263b38032741afd2585ba5bfd91e3e8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7369726772696d6f72756d2f7472616e7361727469636c65732e7376673f7374796c653d666c61742d737175617265)[![Total Downloads](https://camo.githubusercontent.com/a7cd68e7dffc21af1d4db461286e1b49c9ba7ec0ab79055aa148433f3f24c8ef/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7369726772696d6f72756d2f7472616e7361727469636c65732e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/a7cd68e7dffc21af1d4db461286e1b49c9ba7ec0ab79055aa148433f3f24c8ef/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7369726772696d6f72756d2f7472616e7361727469636c65732e7376673f7374796c653d666c61742d737175617265)[![License](https://camo.githubusercontent.com/9ebf024f9d2a677517a38abcd095e796b1f95ec0acd82b022f1ecb37206ef78e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7369726772696d6f72756d2f7472616e7361727469636c65732e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/9ebf024f9d2a677517a38abcd095e796b1f95ec0acd82b022f1ecb37206ef78e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7369726772696d6f72756d2f7472616e7361727469636c65732e7376673f7374796c653d666c61742d737175617265)

Database-backed multilingual content for Laravel. Store rich-text articles in the database instead of flat files, retrieve them by locale, expose them to JavaScript, and manage them via the CrudGenerator admin — all with a single helper call.

Features
--------

[](#features)

- **Database-backed translations** — articles stored per locale in the `articles` table
- **Automatic locale fallback** — returns any available language when the current locale is missing
- **Dot-notation keys** — `scope.nickname` addressing (e.g. `help.contact_us`)
- **JavaScript exposure** — publish a whole scope of articles to a JS global for frontend use
- **Blade directives** — render or expose articles without leaving the template
- **`trans_article()` helper** — global function usable anywhere in PHP
- **Seeder generation** — dump the current `articles` table to a seed file with one command
- **CrudGenerator integration** — articles can be managed via the CrudGenerator admin when both packages are installed

Requirements
------------

[](#requirements)

- PHP &gt;= 8.2
- Laravel &gt;= 9.0

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

[](#installation)

```
composer require sirgrimorum/transarticles
```

### Run migrations

[](#run-migrations)

```
php artisan migrate
```

This creates the `articles` table with columns: `id`, `nickname`, `scope`, `lang`, `content`, `activated`, `user_id`.

### Publish configuration (optional)

[](#publish-configuration-optional)

```
php artisan vendor:publish --provider="Sirgrimorum\TransArticles\TransArticlesServiceProvider" --tag=config
```

Publishes `config/sirgrimorum/transarticles.php`.

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

[](#configuration)

`config/sirgrimorum/transarticles.php`

```
return [
    // Eloquent model used to store articles
    'default_articles_model' => \Sirgrimorum\TransArticles\Models\Article::class,

    // Database column that stores the locale code
    'default_lang_column' => 'lang',

    // Model scope used to find a single article
    'default_findarticle_function_name' => 'findArticle',

    // Model scope used to find a collection of articles
    'default_findarticles_function_name' => 'findArticles',

    // JavaScript global variable for exposed articles
    'default_base_var' => 'translations',
];
```

Creating Articles
-----------------

[](#creating-articles)

Insert records directly or use the CrudGenerator admin (if installed):

```
\Sirgrimorum\TransArticles\Models\Article::create([
    'scope'     => 'homepage',
    'nickname'  => 'hero_title',
    'lang'      => 'en',
    'content'   => 'Welcome to our site',
    'activated' => true,
]);
```

Retrieving Articles
-------------------

[](#retrieving-articles)

### Facade

[](#facade)

```
use Sirgrimorum\TransArticles\Facades\TransArticles;

// Returns content for the current locale (or fallback)
$html = TransArticles::get('homepage.hero_title');

// Expose a scope as a  tag
$script = TransArticles::getjs('homepage');
```

### Helper function

[](#helper-function)

```
echo trans_article('homepage.hero_title');
```

### Blade directives

[](#blade-directives)

```
{{-- Render an article inline --}}
@transarticles('homepage.hero_title')

{{-- Expose an entire scope to JavaScript --}}
@transarticles_tojs('homepage')

{{-- Custom JS variable name --}}
@transarticles_tojs('homepage', 'pageContent')
```

### JavaScript usage (after `@transarticles_tojs`)

[](#javascript-usage-after-transarticles_tojs)

```
// window.translations.homepage.hero_title => "Welcome..."
document.getElementById('hero').innerHTML = translations.homepage.hero_title;
```

Locale Fallback Behaviour
-------------------------

[](#locale-fallback-behaviour)

1. Look for an article with `lang = App::getLocale()` and `activated = true`
2. If not found, return any activated article for that `scope.nickname`
3. If still not found, return the nickname itself (useful for spotting missing articles)

A warning label is shown when content is returned in a fallback language.

Artisan Commands
----------------

[](#artisan-commands)

### `transarticles:createseed`

[](#transarticlescreateseed)

Generates a database seed file from the current `articles` table:

```
# Seed only the articles table
php artisan transarticles:createseed

# Seed all tables (excluding migrations)
php artisan transarticles:createseed --all

# Force overwrite
php artisan transarticles:createseed --force
```

The generated seed file is placed in `database/seeds/` (or `database/seeders/` for Laravel 8+).

API Reference
-------------

[](#api-reference)

### `TransArticles::get()`

[](#transarticlesget)

```
TransArticles::get(string $nickname): string
```

Returns the HTML content of the article identified by `scope.nickname` for the current locale.

### `TransArticles::getjs()`

[](#transarticlesgetjs)

```
TransArticles::getjs(
    string $scope,      // Scope to expose (or 'scope.nickname' for a single article)
    string $basevar = '' // JS global variable (defaults to config 'default_base_var')
): string
```

Returns a `` tag that assigns all articles in the scope to `window.{basevar}.{scope}`.

### `trans_article()`

[](#trans_article)

```
trans_article(string $nickname): string
```

Global helper — equivalent to `TransArticles::get($nickname)`.

### Blade directive — `@transarticles`

[](#blade-directive--transarticles)

```
@transarticles(string $nickname)
```

### Blade directive — `@transarticles_tojs`

[](#blade-directive--transarticles_tojs)

```
@transarticles_tojs(string $scope, string $basevar = '')
```

License
-------

[](#license)

The MIT License (MIT). See [LICENSE.md](LICENSE.md).

###  Health Score

53

—

FairBetter than 97% of packages

Maintenance85

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity85

Battle-tested with a long release history

 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 ~147 days

Recently: every ~2 days

Total

21

Last Release

77d ago

PHP version history (3 changes)1.0.0PHP &gt;=7.0

1.3.0PHP ^8.0

1.3.3PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/38ced8f27be30def379c1900bf2a56c7e682180f6a693f17d8168e4e74b8ca82?d=identicon)[sirgrimorum](/maintainers/sirgrimorum)

---

Top Contributors

[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

---

Tags

sirgrimorumTransArticlesLocalizarion

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sirgrimorum-transarticles/health.svg)

```
[![Health](https://phpackages.com/badges/sirgrimorum-transarticles/health.svg)](https://phpackages.com/packages/sirgrimorum-transarticles)
```

###  Alternatives

[mcamara/laravel-localization

Easy localization for Laravel

3.5k9.1M112](/packages/mcamara-laravel-localization)[typicms/base

A modular multilingual CMS built with Laravel, enabling developers to manage structured content like pages, news, events, and more.

1.6k20.3k](/packages/typicms-base)[vemcogroup/laravel-translation

Translation package for Laravel to scan for localisations and up/download to poeditor

135304.0k2](/packages/vemcogroup-laravel-translation)

PHPackages © 2026

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