{"id":29049283,"url":"https://github.com/labrodev/laravel-translatable","last_synced_at":"2026-04-29T06:38:24.298Z","repository":{"id":301219923,"uuid":"998414719","full_name":"labrodev/laravel-translatable","owner":"labrodev","description":"A Laravel package adding JSON-based multilingual support to Eloquent models, with locale-aware field localization and case-insensitive, multi-locale search.","archived":false,"fork":false,"pushed_at":"2025-06-25T18:13:25.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-25T19:25:55.318Z","etag":null,"topics":["eloquent-models","eloquent-orm","labrodev","laravel","laravel-framework","laravel-package","laravel-utility","laravel12","php","php-library","php8","query-builder-php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/labrodev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-08T15:05:06.000Z","updated_at":"2025-06-25T18:13:28.000Z","dependencies_parsed_at":"2025-06-25T19:26:19.055Z","dependency_job_id":"b3141af0-7ec3-4107-95ae-e01df5e2130e","html_url":"https://github.com/labrodev/laravel-translatable","commit_stats":null,"previous_names":["labrodev/laravel-translatable"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/labrodev/laravel-translatable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labrodev%2Flaravel-translatable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labrodev%2Flaravel-translatable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labrodev%2Flaravel-translatable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labrodev%2Flaravel-translatable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/labrodev","download_url":"https://codeload.github.com/labrodev/laravel-translatable/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labrodev%2Flaravel-translatable/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261953128,"owners_count":23235449,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eloquent-models","eloquent-orm","labrodev","laravel","laravel-framework","laravel-package","laravel-utility","laravel12","php","php-library","php8","query-builder-php"],"created_at":"2025-06-26T19:07:37.013Z","updated_at":"2026-04-29T06:38:19.275Z","avatar_url":"https://github.com/labrodev.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Labrodev Laravel Translatable\n\nA Laravel package that adds JSON-based multilingual support to your Eloquent models. It provides:\n\n- **QueryFieldLocalizer**: Utility to localize JSON fields to the current locale.\n- **SearchQueryBuilder**: Trait for case-insensitive, multi-locale JSON field searching.\n- **LocaleResolver**: Default resolver that returns `app.locale` and `app.fallback_locale`.\n\n---\n\n## Installation\n\nRequire the package via Composer:\n\n```bash\ncomposer require labrodev/laravel-translatable\n```\n\nOptionally, publish the configuration (if you add a config file later):\n\n```bash\nphp artisan vendor:publish --provider=\"Labrodev\\Translatable\\TranslatableServiceProvider\"\n```\n\n\u003e **Note:** No configuration file is required out of the box—this is here for future customization.\n\n---\n\n## Usage\n\n### 1. Localizing JSON Fields\n\n`QueryFieldLocalizer` helps you build locale-specific JSON paths for query fields:\n\n```php\nuse Labrodev\\Translatable\\Utilities\\QueryFieldLocalizer;\n\n// Assume the `title` column contains JSON:\n// { \"en\": \"Hello\", \"es\": \"Hola\" }\n$localized = QueryFieldLocalizer::translatableField('title');\n// On locale `es`, returns: \"title-\u003ees\"\n\n// Use in query:\n$posts = Post::whereRaw(\"{$localized} = ?\", ['Hola'])-\u003eget();\n```\n\n### 2. Multilingual Search on JSON Columns\n\nAdd the `SearchQueryBuilder` trait to your Eloquent model:\n\n```php\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Labrodev\\Translatable\\Base\\Traits\\SearchQueryBuilder;\n\nclass Article extends Model\n{\n    use SearchQueryBuilder;\n\n    protected $casts = [\n        'titles' =\u003e 'array',\n    ];\n}\n```\n\nPerform a case-insensitive search across all configured locales:\n\n```php\n// Searches \"manzana\" in `titles` JSON for locales [en, es]\n$results = Article::query()\n    -\u003ewhere(function ($q) {\n        $this-\u003esearchField($q, 'manzana', 'titles');\n    })\n    -\u003eget();\n```\n\nOr chain with existing conditions:\n\n```php\n$posts = Article::query()\n    -\u003ewhere('published', true)\n    -\u003eorWhere(function ($q) {\n        $this-\u003esearchFieldOr($q, 'orange', 'titles');\n    })\n    -\u003eget();\n```\n\n### 3. Customizing Locales\n\nBy default, locales come from `app.locale` and `app.fallback_locale`. To customize, bind your own `LocaleResolver` implementation:\n\n```php\nuse Labrodev\\Translatable\\Contracts\\LocaleResolver;\n\n$this-\u003eapp-\u003esingleton(LocaleResolver::class, function ($app) {\n    return new class implements LocaleResolver {\n        public function all(): array\n        {\n            return ['en', 'fr', 'es'];\n        }\n    };\n});\n```\n\n---\n\n## Testing\n\nThis package uses Pest with Orchestra Testbench for testing and PHPStan for static analysis.\nThis package uses [Pest](https://pestphp.com/) with [Orchestra Testbench](https://github.com/orchestral/testbench) for testing and [PHPStan](https://https://phpstan.org/) for static analysis\n\n1. Install dependencies:\n   ```bash\n   composer install\n   ```\n2. Run static analysis:\n   ```bash\n   composer analyse\n   ```\n   \n3. Run tests:\n   ```bash\n   composer test\n   ```\n\nTests cover:\n- `QueryFieldLocalizer::translatableField()` outputs correct JSON path.\n- `SearchQueryBuilder` builds proper SQL \u0026 bindings for multilingual JSON searches.\n- `DefaultLocaleResolverTest` resolve locales array.\n\n---\n\n## Security\n\nIf you discover any security-related issues, please email contact@labrodev.com instead of using the issue tracker.\n\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Credits\n\n- [Labro Dev](https://github.com/labrodev)\n\n## Contributing\n\nFeel free to open issues or submit pull requests. Check Coding Standards:\n\n- PSR-12\n- Strict types enabled\n\n---\n\n## License\n\nMIT © Labro Dev\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flabrodev%2Flaravel-translatable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flabrodev%2Flaravel-translatable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flabrodev%2Flaravel-translatable/lists"}