# Localization

Localization is how Krayin renders the same UI in any supported language. Each package ships its own translation files under Resources/lang/<locale>/app.php and registers a translation namespace so callers can reference strings with package::path.to.key.

For deeper Laravel-specific guidance see the Laravel localization docs (opens new window).

# โš™๏ธ Configure the default and fallback locale

The application-wide default lives in config/app.php:

'locale' => env('APP_LOCALE', 'en'),
'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'),
Setting Why
locale Which language Laravel renders if the user has no other preference.
fallback_locale Used when a string is missing from the requested locale โ€” keep this set to en so untranslated keys still render something readable.

Set both via your .env:

APP_LOCALE=en
APP_FALLBACK_LOCALE=en

# ๐Ÿ“ Create the language files

By convention each package keeps translations under src/Resources/lang/<locale>/app.php. Add a folder per language โ€” we'll start with English:

packages
โ””โ”€โ”€ Webkul
    โ””โ”€โ”€ Example
        โ””โ”€โ”€ src
            โ”œโ”€โ”€ ...
            โ””โ”€โ”€ Resources
                โ””โ”€โ”€ lang
                    โ””โ”€โ”€ en
                        โ””โ”€โ”€ app.php

Inside app.php, return an associative array of keys. Nest the array to match your view's dot-notation:

<?php

return [
    'examples' => [
        'index' => [
            'title' => 'Examples',
        ],

        'create-btn' => 'Create Example',
        'create-success' => 'Example created successfully.',
        'update-success' => 'Example updated successfully.',
        'delete-success' => 'Example deleted successfully.',
    ],

    'acl' => [
        'examples' => 'Examples',
        'create' => 'Create',
        'delete' => 'Delete',
    ],
];

To add another language, copy en/ to fr/, de/, hi/, etc. and translate the values โ€” keep the keys identical.

# ๐Ÿ”Œ Register translations with the service provider

The translation namespace is what lets you write @lang('example::examples.index.title'). Register it in boot():

<?php

namespace Webkul\Example\Providers;

use Illuminate\Support\ServiceProvider;

class ExampleServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        $this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'example');
    }
}

loadTranslationsFrom() takes the absolute path to the lang/ folder and a short namespace ('example'). After this, callers anywhere in the app can use the example:: prefix.

# ๐ŸŒ Use translations

# In Blade templates

@lang('example::app.examples.index.title')

# In PHP code

trans('example::app.examples.create-success');
__('example::app.examples.create-success'); // alias for trans()

# With placeholders

Add named placeholders in your language file with : prefix:

'welcome' => 'Welcome back, :name!',

Then pass the replacement when calling the helper:

{{ __('example::app.welcome', ['name' => $user->name]) }}

# ๐Ÿงช Verify

Pick a string you just translated and:

  1. Visit a page that renders it โ€” confirm the value comes from your app.php, not the raw key (example::app.examples.index.title).
  2. Change APP_LOCALE in .env to a locale you've translated for, run php artisan config:clear, reload, and confirm the page switches language.

If you see the raw key on the page, loadTranslationsFrom() didn't run โ€” check it's inside boot() and re-run php artisan optimize:clear.

# ๐Ÿ“ Next steps

  • Assets โ€” once your package speaks the user's language, ship JS / CSS with it.
  • DataGrid โ€” uses translation keys for column labels and filter options.