Skip to content

Working with Multiple Language Guide

Azizul Hakim edited this page Oct 13, 2023 · 7 revisions

Elevate the accessibility and user-friendliness of this Starter Project by embracing multiple languages. With the assistance of Filament Translations and the Laravel Lang package, this Starter Project offers comprehensive multilingual support.

Supported Languages

As of now, this Starter Project provides support for two languages: Bangla and English. However, the flexibility is built in for you to add more languages based on your project's requirements.

Getting Started

To expand your project's language support, follow these steps:

  1. Visit the Filament Translations Documentation:

    Start by visiting the Filament Translations documentation to understand how to manage translations efficiently.

  2. Leverage Laravel Lang:

    The Laravel Lang package provides a wealth of language files for different languages. You can access and integrate these language files into your project.

  3. Custom Translations:

    If you require custom translations for specific project-related content, you can create your own translation files and integrate them with your project.

Publishing a new language

Adding a new language to your project is a breeze. Execute the following command to publish a new language:

php artisan lang:add es

It will be installed in lang\es folder

Project Directory Structure

Custom Translation

Inside your language folder, you can add custom translations to tailor your project to specific language requirements. For example, check out this sample Bangla translation in resources.php:

<?php

declare(strict_types=1);

return [
    'role'   => 'রোল',
    'role.plural' => 'রোলগুলো',
    'permission' => 'পার্মিশন',
    'permission.plural' => 'পার্মিশনগুলো',
    'user' => 'ব্যবহারকারী',
    'user.plural' => 'ব্যবহারকারীরা',
];

Using Custom Translation in Filament

To implement custom translations in Filament, you can set the Model label and plural Label in a resource, and the rest of the translation will be handled by Filament translations. Here's an example:

   public static function getModelLabel(): string
    {
        return __('resources.user');
    }
    public static function getPluralLabel(): ?string
    {
        return __('resources.user.plural');
    }
Clone this wiki locally