### Typical Package Installation Sequence Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/commands.md Outlines the common steps for installing and setting up the laravel-lang-sync-inertia package. This includes composer and npm installation, publishing language files, and publishing package configuration. ```bash # 1. Install the package composer require erag/laravel-lang-sync-inertia npm install @erag/lang-sync-inertia # 2. Publish Laravel language files (if needed) php artisan lang:publish # 3. Publish package configuration php artisan erag:install-lang # 4. (Optional) Customize config/inertia-lang.php # 5. (Optional) Generate JSON translations php artisan erag:generate-lang ``` -------------------------------- ### Default Configuration File Example Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/configuration.md An example of a default configuration file (`config/inertia-lang.php`) defining `lang_path` and `output_lang`. ```php base_path('lang'), 'output_lang' => env('TRANSLATION_OUTPUT_PATH', resource_path('js/lang')), ]; ``` -------------------------------- ### Install Laravel Lang Sync Inertia Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/index.md Install the package using Composer and npm. Publish configuration and run the installation command. ```bash composer require erag/laravel-lang-sync-inertia npm install @erag/lang-sync-inertia php artisan lang:publish # If needed php artisan erag:install-lang ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/CONTRIBUTING.md Steps to clone the repository and install project dependencies using Composer and npm. ```bash git clone https://github.com/your-username/laravel-lang-sync-inertia.git cd laravel-lang-sync-inertia composer install ``` ```bash npm install npm run dev ``` -------------------------------- ### Install Frontend Helper Package with npm Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/README.md Use npm to install the frontend helper package, which provides utilities for Vue, React, and Svelte. ```bash npm install @erag/lang-sync-inertia ``` -------------------------------- ### Install Laravel and Frontend Packages Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/usage-patterns.md Install the Laravel package via Composer and the frontend package via npm. Publish language files and package configuration as needed. ```bash # 1. Install Laravel package composer require erag/laravel-lang-sync-inertia # 2. Install frontend package npm install @erag/lang-sync-inertia # 3. Publish Laravel language files (if needed) php artisan lang:publish # 4. Publish package configuration php artisan erag:install-lang ``` -------------------------------- ### Customized Configuration File Example Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/commands.md Provides an example of how to customize the 'inertia-lang.php' configuration file after it has been published. This allows developers to specify custom paths for language files and output locations. ```php resource_path('languages'), // Custom output path for generated JSON files 'output_lang' => public_path('locales'), ]; ``` -------------------------------- ### Example PHP Translation File Input Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/commands.md An example of a typical PHP translation file that the command processes. ```php 'These credentials do not match our records.', 'password' => 'The provided password is incorrect.', 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', 'welcome' => 'Welcome, :name!', ]; ``` -------------------------------- ### Vue Component Example Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/frontend-integration.md Demonstrates how to integrate the translation functions within a Vue 3 component's script setup and template. ```APIDOC ## Vue Component Example ### Description Demonstrates how to integrate the translation functions within a Vue 3 component's script setup and template. ### Code ```vue ``` ``` -------------------------------- ### Custom Configuration Example for inertia-lang Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/api-reference.md An example of a custom configuration for the inertia-lang package. This allows you to specify alternative paths for language files and JSON output. ```php resource_path('languages'), 'output_lang' => public_path('assets/locales'), ]; ``` -------------------------------- ### Install Laravel Lang Sync Inertia Package Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/README.md Install the backend and frontend packages using Composer and npm. Publish language files and package configuration using Artisan commands. ```bash # Backend composer require erag/laravel-lang-sync-inertia # Frontend npm install @erag/lang-sync-inertia # Publish language files (if needed) php artisan lang:publish # Publish package configuration php artisan erag:install-lang ``` -------------------------------- ### Backend Translation File Example Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/frontend-integration.md This is an example of a backend language file in PHP. It defines translation keys and their corresponding strings. ```php return [ 'greeting' => 'Hello', ]; ``` -------------------------------- ### Production Configuration Example Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/configuration.md Configure `lang_path` and `output_lang` for production. Ensure `output_lang` points to a writable directory if `erag:generate-lang` runs at runtime. ```php // config/inertia-lang.php (production) return [ 'lang_path' => base_path('lang'), 'output_lang' => storage_path('app/translations'), // Writable on production ]; ``` -------------------------------- ### Install Laravel Lang Sync Inertia Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/resources/boost/skills/laravel-lang-sync-inertia/references/examples.md Install both the Composer package for the backend and the npm package for the frontend. Publish Laravel's language files if they don't exist, then publish the package's configuration. ```bash composer require erag/laravel-lang-sync-inertia npm install @erag/lang-sync-inertia ``` ```bash php artisan lang:publish ``` ```bash php artisan erag:install-lang ``` -------------------------------- ### JSON Export Example Input Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/resources/boost/skills/laravel-lang-sync-inertia/references/examples.md Example of a PHP language file (`lang/en/auth.php`) that will be converted into a JSON file. ```php // lang/en/auth.php return [ 'greeting' => 'Hello!', 'welcome' => 'Welcome, :name', ]; ``` -------------------------------- ### Install Package Configuration Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/resources/boost/skills/laravel-lang-sync-inertia/references/api.md Publishes the package's configuration file using the `erag:install-lang` Artisan command. ```bash php artisan erag:install-lang ``` -------------------------------- ### Publish Service Provider Configuration Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/configuration.md Manually publish the configuration using the service provider. This is an alternative to the dedicated install command. ```bash php artisan vendor:publish --provider="LaravelLangSyncInertia\LangSyncInertiaServiceProvider" ``` -------------------------------- ### Environment-Driven Configuration Example Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/configuration.md Illustrates how to use environment variables to override default configuration values for `lang_path` and `output_lang` in `config/inertia-lang.php` and `.env`. ```php env('LANG_PATH', base_path('lang')), 'output_lang' => env('TRANSLATION_OUTPUT_PATH', resource_path('js/lang')), ]; ``` ```env LANG_PATH="/custom/lang/path" TRANSLATION_OUTPUT_PATH="/var/translations" ``` -------------------------------- ### Install Laravel Package with Composer Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/README.md Use Composer to install the main Laravel package. This command adds the package to your project's dependencies. ```bash composer require erag/laravel-lang-sync-inertia ``` -------------------------------- ### Language File Structure Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/resources/boost/skills/laravel-lang-sync-inertia/references/examples.md Example of a typical PHP language file structure, including simple strings, placeholders, and pluralization rules. ```php 'Hello!', 'welcome' => 'Welcome, :name', 'legacy_welcome' => 'Welcome, {name}', 'notifications' => '{0} No notifications|{1} One notification|[2,*] :count notifications', ]; ``` -------------------------------- ### Artisan Commands Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/package-structure.md Provides Artisan commands for installing and generating language files. ```APIDOC ## Artisan Commands ### Description Commands to manage language files within the Inertia application. ### Commands #### `php artisan erag:install-lang` Installs the necessary language files and configurations. #### `php artisan erag:generate-lang` Generates language files based on the current configuration. ``` -------------------------------- ### Publishing and Configuring Inertia Lang Sync Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/usage-patterns.md After installing the package, publish the configuration file using the provided artisan command. This allows customization of paths and other settings in config/inertia-lang.php. ```bash # Wrong: No config file composer require erag/laravel-lang-sync-inertia # Paths use defaults # Correct: Publish config composer require erag/laravel-lang-sync-inertia php artisan erag:install-lang # Now can customize paths in config/inertia-lang.php ``` -------------------------------- ### Setup Configuration Publishing Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/classes-and-services.md Sets up the configuration publishing for the package, allowing users to publish the default inertia-lang.php configuration file to their application's config directory using the 'erag:publish-lang-config' tag. ```php protected function publishConfig(): void { $this->publishes([ __DIR__.'/../config/inertia-lang.php' => config_path('inertia-lang.php'), ], 'erag:publish-lang-config'); } ``` -------------------------------- ### Artisan Commands Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/README.md Artisan commands for installing the package and generating language JSON files. ```APIDOC ## Artisan Commands ### Description Commands to manage package installation and language file generation. ### Commands #### `php artisan erag:install-lang` Publishes the configuration file for the package. #### `php artisan erag:generate-lang` Generates language JSON files for frontend use. ``` -------------------------------- ### Use Facade to Load and Get Language Translations Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/package-structure.md Utilize the `Lang` facade to load translations by file name, retrieve specific files, or get all currently loaded translations. The facade can be used with or without an explicit `use` statement. ```php use LaravelLangSyncInertia\Facades\Lang; Lang::load('auth'); Lang::getFile(['auth', 'messages']); Lang::getLoaded(); ``` ```php Lang::load('auth'); // Without use statement ``` -------------------------------- ### Console Output for Successful Installation Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/commands.md Displays the expected console output when the 'erag:install-lang' command successfully publishes the language configuration. Indicates that the configuration was published successfully. ```text Publishing language configuration... Language configuration published successfully. ``` -------------------------------- ### Using Specialized Translation Methods Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/frontend-integration.md Provides examples of the different translation methods available: simple key lookups, translations with replacements, and pluralization based on a count. ```typescript __("key") // Simple lookups trans(key, { ...replacements }) // Replacements transChoice(key, count) // Pluralization ``` -------------------------------- ### Environment-Specific Configuration Example Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/configuration.md Demonstrates how to override default configuration values using environment-specific files. The `config/inertia-lang.local.php` file overrides the `output_lang` setting for the local development environment, while `lang_path` retains its default. ```php base_path('lang'), 'output_lang' => resource_path('js/lang'), ]; ``` ```php storage_path('app/generated-lang'), ]; ``` -------------------------------- ### Svelte Component Example Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/frontend-integration.md Example of a Svelte component utilizing translation methods. The script block includes importing and calling the lang function, while the template uses the obtained translation helpers. ```svelte

{__('auth.greeting')}

{trans('auth.welcome', { name })}

{transChoice('messages.items', itemCount)}

``` -------------------------------- ### Runtime Loading Strategy: Flow Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/data-flow-and-architecture.md Details the on-demand runtime loading process, starting from the controller action calling syncLangFiles to translations being shared via Inertia. ```text Controller Action ↓ syncLangFiles(['auth', 'validation']) ↓ TranslationLoader::load() for each group ↓ Reads PHP files from lang/{locale}/*.php ↓ Caches in $loaded ↓ Middleware catches loaded translations ↓ Shared with Inertia as page.props.lang ``` -------------------------------- ### JSON Export Example Output Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/resources/boost/skills/laravel-lang-sync-inertia/references/examples.md The resulting JSON structure generated from the input PHP language file. ```json { "greeting": "Hello!", "welcome": "Welcome, :name" } ``` -------------------------------- ### Get Lang Path and Output Path in Service Provider Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/configuration.md Retrieve the language path and output path configuration values in a service provider. Ensure paths are trimmed of trailing separators. ```php $basePath = rtrim( (string) config('inertia-lang.lang_path'), DIRECTORY_SEPARATOR ); $outputPath = rtrim( (string) config('inertia-lang.output_lang'), DIRECTORY_SEPARATOR ); ``` -------------------------------- ### Install Language Configuration Command Signature Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/commands.md Defines the signature and description for the 'erag:install-lang' artisan command. This command is used to publish the package's configuration file. ```php protected $signature = 'erag:install-lang'; protected $description = 'Publish language configuration and initialize LaravelLangSyncInertia.'; ``` -------------------------------- ### Combined Translation Strategy Controller Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/usage-patterns.md This controller example demonstrates loading static translations via generated JSON and dynamic translations at runtime. The service provider loads generated JSON, and the controller explicitly loads runtime files, which are then merged. ```php status); return Inertia::render('Order/Show', [ 'order' => $order, ]); } } ``` -------------------------------- ### Frontend Fallback with Missing Backend Setup Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/frontend-integration.md When translations are not properly shared from the backend, frontend helpers will gracefully fall back to returning the translation key itself. ```typescript const { __ } = lang(); __('auth.greeting') // Returns: 'auth.greeting' (key fallback) ``` -------------------------------- ### Frontend Translation with Named Placeholders Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/frontend-integration.md This example shows how to use named placeholders for translation strings in the frontend. The placeholders are replaced with values from the provided object. ```typescript __('auth.welcome', { name: 'John' }) ``` -------------------------------- ### Document Custom Language Paths Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/configuration.md Document any custom paths used for language files in your project's deployment guide. This helps other developers or deployment scripts understand the project's configuration. ```markdown ## Language Configuration - Lang files: Custom path via LANG_PATH env var - Output: Generated to TRANSLATION_OUTPUT_PATH ``` -------------------------------- ### Service Provider Boot Phase Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/package-structure.md Outlines the steps executed during the service provider's boot method, such as loading helpers, registering aliases, and sharing translations with Inertia. ```text boot() ├── loadHelpers() │ └── Require src/LangHelpers.php (defines syncLangFiles) ├── registerAlias() │ └── Alias 'Lang' to Lang facade ├── registerMiddleware() │ └── Push ShareLangTranslations to HTTP kernel └── shareLangWithInertia() └── Share 'lang' prop via Inertia::share() ``` -------------------------------- ### Lang Facade Usage with Import Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/classes-and-services.md Demonstrates how to use the Lang facade by importing it first, then making static-like calls to its proxied methods for loading translation data. ```php use LaravelLangSyncInertia\Facades\Lang; // Static-like calls $auth = Lang::load('auth'); $translations = Lang::getFile(['auth', 'validation']); $all = Lang::getLoaded(); ``` -------------------------------- ### React Component Example Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/frontend-integration.md Example of using translation methods within a React functional component. Ensure the lang hook is called to retrieve the translation functions. ```tsx import { lang } from '@erag/lang-sync-inertia/react'; export default function Dashboard() { const { __, trans, transChoice } = lang(); const userName = 'Bob'; const messageCount = 5; return (

{__('auth.greeting')}

{trans('auth.welcome', { name: userName })}

{transChoice('messages.items', messageCount)}

); } ``` -------------------------------- ### Combined Strategy: Step-by-Step Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/data-flow-and-architecture.md Illustrates the combined strategy where generated JSON forms the base, and runtime loading provides dynamic overrides, resulting in a merged translation set for the frontend. ```text 1. Developer runs: php artisan erag:generate-lang → All translation files converted to JSON 2. Service Provider loads generated JSON → Forms the base translation set 3. Controller calls: syncLangFiles('dynamic-messages') → Loads additional runtime translations 4. array_replace_recursive merges both → JSON is base, runtime overrides 5. Frontend receives merged result → page.props.lang contains both ``` -------------------------------- ### Resolve TranslationLoader Instance Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/package-structure.md Get an instance of the TranslationLoader service from the application container. ```php // Resolved via facade accessor $loader = app(TranslationLoader::class); ``` -------------------------------- ### Register Package Commands Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/package-structure.md Register the InstallLangCommand and GenerateLangCommand within the service provider. ```php $this->commands([ InstallLangCommand::class, GenerateLangCommand::class, ]); ``` -------------------------------- ### Request Lifecycle: Request Arrives Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/data-flow-and-architecture.md Illustrates the initial stage of an HTTP request entering the application and being processed by the kernel's middleware stack. ```text HTTP Request ↓ Kernel processes middleware stack ``` -------------------------------- ### Configure Output Path with Environment Variable Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/configuration.md Use environment variables to specify deployment-specific paths for output language files. This allows for flexible configuration without modifying the code directly. ```php 'output_lang' => env('TRANSLATION_OUTPUT_PATH', resource_path('js/lang')), ``` -------------------------------- ### Get Loaded Translation Groups Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/resources/boost/skills/laravel-lang-sync-inertia/references/api.md Retrieves all translation groups that have already been loaded during the current request via the Lang facade. ```php Lang::getLoaded(); ``` -------------------------------- ### Publish Package Configuration Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/api-reference.md Publishes the package's configuration file to the host application. Use this command to customize language paths and output locations. ```bash php artisan vendor:publish --tag=erag:publish-lang-config --force ``` ```bash php artisan erag:install-lang ``` -------------------------------- ### Publish Language Configuration Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/resources/boost/skills/laravel-lang-sync-inertia/references/package.md Use this command to publish the package's configuration files. This allows you to customize settings like `lang_path` and `output_lang`. ```bash php artisan vendor:publish --tag=erag:publish-lang-config --force ``` -------------------------------- ### Get Translation Files Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/resources/boost/skills/laravel-lang-sync-inertia/references/api.md Loads one or many translation groups and returns them grouped by filename using the Lang facade. ```php Lang::getFile('auth'); ``` ```php Lang::getFile(['auth', 'validation']); ``` -------------------------------- ### Laravel Bootstrap Phase Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/package-structure.md Illustrates the initial steps of the Laravel framework bootstrap process as it relates to the service provider. ```text Laravel Boot ↓ Service Provider Discovery ↓ LaravelLangSyncInertiaServiceProvider registers (class found via composer) ``` -------------------------------- ### Frontend Translation Access Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/usage-patterns.md Access translations in the frontend using the imported lang object. This setup is the same whether using runtime or generated JSON. ```vue ``` -------------------------------- ### Command Registration in Service Provider Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/commands.md The `InstallLangCommand` and `GenerateLangCommand` are automatically registered by the service provider's `registerCommands` method. ```php protected function registerCommands(): void { $this->commands([ InstallLangCommand::class, GenerateLangCommand::class, ]); } ``` -------------------------------- ### Get Application Locale Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/data-flow-and-architecture.md Retrieves the current application locale using Laravel's helper function. This locale is used for all translation loading decisions. ```php $locale = app()->getLocale(); ``` -------------------------------- ### Package File Structure Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/api-reference.md Overview of the directory structure for the laravel-lang-sync-inertia package, highlighting key components like commands, facades, middleware, and configuration. ```text src/ ├── Commands/ │ ├── GenerateLangCommand.php # Generate JSON from PHP translations │ └── InstallLangCommand.php # Publish configuration ├── Facades/ │ └── Lang.php # Facade for TranslationLoader ├── Middleware/ │ └── ShareLangTranslations.php # Middleware for sharing translations ├── Support/ │ └── TranslationLoader.php # Core translation loading class ├── LangHelpers.php # Global helper function └── LangSyncInertiaServiceProvider.php # Service provider config/ └── inertia-lang.php # Configuration file ``` -------------------------------- ### Merge Behavior Example Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/data-flow-and-architecture.md Illustrates the recursive merging of translation arrays. Runtime translations override existing keys, while new keys from generated JSON are included. ```php $generated = [ 'auth' => [ 'failed' => 'Credentials incorrect', 'password' => 'Password incorrect', ], 'messages' => [ 'welcome' => 'Welcome!', ], ]; $runtime = [ 'auth' => [ 'failed' => 'Login failed', // Override ], ]; // Result: array_replace_recursive($generated, $runtime) = [ 'auth' => [ 'failed' => 'Login failed', // From runtime 'password' => 'Password incorrect', // From JSON ], 'messages' => [ 'welcome' => 'Welcome!', // From JSON ], ]; ``` -------------------------------- ### Environment-Specific Configuration Override Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/api-reference.md Demonstrates how to override configuration values for specific environments. The local environment overrides the default 'output_lang' setting. ```php base_path('lang'), 'output_lang' => resource_path('js/lang'), ]; // config/inertia-lang.local.php (local overrides) return [ 'output_lang' => storage_path('generated-lang'), ]; ``` -------------------------------- ### Testing Pluralization Edge Cases Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/frontend-integration.md Provides examples for testing the `transChoice` function with different counts (zero, one, multiple) to ensure correct pluralization logic. ```typescript transChoice('items', 0) // No items transChoice('items', 1) // One item transChoice('items', 2) // Multiple items ``` -------------------------------- ### Command: php artisan erag:install-lang Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/resources/boost/skills/laravel-lang-sync-inertia/references/api.md Publishes the package's configuration file using the 'erag:publish-lang-config' tag. ```APIDOC ## php artisan erag:install-lang ### Description Publishes package config using the `erag:publish-lang-config` tag. ### Usage ```bash php artisan erag:install-lang ``` ``` -------------------------------- ### Get Lang Base and Export Lang Paths in GenerateLangCommand Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/configuration.md Retrieve the base language path and the export language path configuration values within a command. ```php $langBasePath = (string) config('inertia-lang.lang_path'); $exportLangPath = (string) config('inertia-lang.output_lang'); ``` -------------------------------- ### Publish and Generate Language Files Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/configuration.md Ensure the language path exists by publishing if necessary, then run the command to generate language files. This ensures all necessary files are in place before generation. ```bash php artisan lang:publish # If needed php artisan erag:generate-lang ``` -------------------------------- ### Configuration Options Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/package-structure.md Exposes configuration values for language file paths. ```APIDOC ## Configuration ### Description Configuration values that control the behavior of language file handling. ### Keys #### `config('inertia-lang.lang_path')` Source path for PHP translation files. #### `config('inertia-lang.output_lang')` Destination path for JSON translation files. ``` -------------------------------- ### Facade Methods: Lang Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/index.md Provides methods for loading, retrieving, and inspecting language files via the Lang facade. ```APIDOC ## Facade Methods: Lang ### Description Provides methods for loading, retrieving, and inspecting language files via the Lang facade. ### Methods - **Lang::load(string $file): array** Loads a specific language file. - **Lang::getFile(string|array $files): array** Retrieves the content of specified language file(s). - **Lang::getLoaded(): array** Returns an array of all currently loaded language files. ``` -------------------------------- ### Configuration Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/README.md Configuration values accessible via the `config()` helper. ```APIDOC ## Configuration ### Description Access package configuration values. ### Keys #### `config('inertia-lang.lang_path')` Returns the base path for language files (default: `base_path('lang')`). #### `config('inertia-lang.output_lang')` Returns the output path for generated frontend language files (default: `resource_path('js/lang')`). ``` -------------------------------- ### Using TranslationLoader in Custom Code Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/api-reference.md An example of how to use the TranslationLoader class within a custom controller to load translation files. The loader caches translations per request. ```php load('validation'); // Now validation contains all validation translations // and is also cached for the middleware to pick up } } ``` -------------------------------- ### Direct Translation Lookup Examples Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/frontend-integration.md Use the `__()` function for direct translation lookups. It supports simple keys and keys with replacements. The function returns the translation or the key if not found. ```typescript __('auth.failed') ``` ```typescript __('auth.welcome', { name: 'John' }) ``` ```typescript __('messages.greeting') ``` -------------------------------- ### Get all loaded translation groups Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/api-reference.md Use Lang::getLoaded() to retrieve all translation groups that have been loaded during the current HTTP request. This is useful for inspecting cached translations before the Inertia share phase. ```php [...], // 'pagination' => [...] // ] ``` -------------------------------- ### Artisan Commands for Language Sync Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/README.md Two Artisan commands are available: `erag:install-lang` to publish the configuration file and `erag:generate-lang` to generate JSON translation files for the frontend. ```bash php artisan erag:install-lang # Publish config ``` ```bash php artisan erag:generate-lang # Generate JSON ``` -------------------------------- ### Local Component Imports vs. Global Registration Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/frontend-integration.md Illustrates the recommended practice of importing translation helpers locally within each component for better maintainability, contrasting it with global registration which should be avoided. ```typescript // Good: Local import per component import { lang } from '@erag/lang-sync-inertia/vue'; // Avoid: Global registration app.provide('lang', lang); ``` -------------------------------- ### React Frontend Placeholder Replacement Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/usage-patterns.md Integrate dynamic translations into your React components for placeholder replacement. This example shows simple, pluralized, and multiple replacements. Import the lang function from the React integration. ```tsx import { lang } from '@erag/lang-sync-inertia/react'; export default function UserProfile({ user }) { const { trans, transChoice } = lang(); const itemCount = 5; return (

{trans('auth.welcome', { name: user.name })}

{transChoice('messages.items', itemCount)}

{trans('email.verification', { email: user.email, name: user.name })}

); } ``` -------------------------------- ### Testing Login Page Translations in Laravel Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/usage-patterns.md Test controllers that use translations by making requests and asserting the presence of translation props. This example verifies that 'auth' translations are available on the login page. ```php get('/login'); $response->assertStatus(200); $response->assertHasInertiaProps(['lang']); // Assert auth translations are present $props = $response->props(); $this->assertArrayHasKey('auth', $props['lang']); $this->assertArrayHasKey('failed', $props['lang']['auth']); } } ``` -------------------------------- ### Use Global Helper Function to Sync Language Files Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/package-structure.md Call the `syncLangFiles` helper function with a single file name or an array of file names to synchronize language files. ```php syncLangFiles('auth'); syncLangFiles(['auth', 'validation']); ``` -------------------------------- ### Configure Language Paths Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/usage-patterns.md Optionally, customize the paths for language files and output in the `config/inertia-lang.php` configuration file. ```php // config/inertia-lang.php base_path('lang'), 'output_lang' => resource_path('js/lang'), ]; ``` -------------------------------- ### Frontend Shared Props Example Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/README.md Translations are made accessible to the frontend via shared props. This JavaScript object contains translation groups that can be directly used in your Vue, React, or Svelte components. ```javascript page.props.lang = { auth: { ... }, messages: { ... } } ``` -------------------------------- ### Configure Language File Paths Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/resources/boost/skills/laravel-lang-sync-inertia/references/package.md Set the paths for your language files in the configuration. Use `lang_path` for custom PHP translation locations and `output_lang` for frontend-expecting JSON output. ```php return [ 'lang_path' => base_path('lang'), 'output_lang' => resource_path('js/lang'), ]; ``` -------------------------------- ### Artisan Commands for Language Management Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/index.md Use Artisan commands to publish configuration files and generate JSON language files for frontend use. ```bash php artisan erag:install-lang # Publish config php artisan erag:generate-lang # Generate JSON files ``` -------------------------------- ### Facade: Lang Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/README.md Provides methods for loading and accessing language files through a facade. ```APIDOC ## Facade Lang ### Description Provides methods for loading and accessing language files. ### Methods #### Lang::load(string $file): array Loads a specific language file. #### Lang::getFile(string|array $files): array Loads one or more specified language files. #### Lang::getLoaded(): array Returns all currently loaded language files. ``` -------------------------------- ### Generate Lang Command Processing Steps Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/data-flow-and-architecture.md Outlines the steps performed by the `GenerateLangCommand` for each PHP translation file found: requiring the file, encoding its contents as JSON, and writing to the output directory. ```text For each .php file: 1. Require the file 2. Get the returned array 3. Encode as JSON 4. Write to output/{locale}/{filename}.json ``` -------------------------------- ### Define Artisan Command Signature and Description Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/commands.md Defines the command's signature and a brief description for Artisan. ```php protected $signature = 'erag:generate-lang'; protected $description = 'Generate frontend language JSON files'; ``` -------------------------------- ### Consistent Placeholder Storage Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/frontend-integration.md Highlights the best practice of using consistent placeholder names (e.g., `:name`) across all translation files for easier management and replacement. ```php 'welcome' => 'Welcome, :name!' // Use :name in all files ``` -------------------------------- ### Use Lang Facade Alias Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/package-structure.md Access translation loading functionality through the Lang facade alias. ```php // Available as alias Lang::load('auth'); ``` -------------------------------- ### Frontend Translation Usage Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/frontend-integration.md Demonstrates how to use the translation helper function '__' in the frontend. It shows successful translation retrieval and fallback behavior when a key is missing. ```typescript __('auth.greeting') // Returns: 'Hello' __('auth.missing') // Returns: 'auth.missing' (key returned as fallback) ``` -------------------------------- ### Load Package Helper Functions Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/classes-and-services.md Loads the package's helper functions from the LangHelpers.php file if it exists. This makes utility functions available globally within the application. ```php protected function loadHelpers(): void { $helpers = __DIR__.'/LangHelpers.php'; if (is_file($helpers)) { require_once $helpers; } } ``` -------------------------------- ### Lang Facade Usage without Import Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/classes-and-services.md Shows how to use the Lang facade globally without explicit import, leveraging Laravel's alias loader for direct static-like calls. ```php // In any context Lang::load('auth'); ``` -------------------------------- ### Configuration Parameters for Inertia Lang Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/README.md Access configuration values using `config()` to determine the source directory for language files (`inertia-lang.lang_path`) and the output directory for generated JSON files (`inertia-lang.output_lang`). ```php config('inertia-lang.lang_path') // Source: base_path('lang') ``` ```php config('inertia-lang.output_lang') // Output: resource_path('js/lang') ``` -------------------------------- ### Default Package Configuration Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/configuration.md This is the complete default configuration file for the package. It specifies the base path for language files and the output path for generated frontend language files. ```php base_path('lang'), /* |-------------------------------------------------------------------------- | Output Path (Exported Files) |-------------------------------------------------------------------------- | | Where the package will write generated files | like JSON for frontend tooling. | */ 'output_lang' => resource_path('js/lang'), ]; ``` -------------------------------- ### Sync Language Files in Settings Controller Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/resources/boost/skills/laravel-lang-sync-inertia/references/examples.md Integrate `syncLangFiles()` into a settings profile controller, typically before rendering the Inertia page, to provide translations for user profile-related views. ```php $request->user() instanceof MustVerifyEmail, 'status' => $request->session()->get('status'), ]); } } ``` -------------------------------- ### Load Translation File from Filesystem Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/data-flow-and-architecture.md Loads a translation file from the filesystem, checking an in-memory cache first. If the file does not exist, an empty array is returned. The loaded content is cached for subsequent requests within the same loader instance. ```php // Check cache if (isset($this->loaded[$file])) { return $this->loaded[$file]; } // Check filesystem if (! file_exists($path)) { $this->loaded[$file] = []; return []; } // Require and cache $this->loaded[$file] = require $path; return $this->loaded[$file]; ``` -------------------------------- ### Artisan Commands Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/index.md Artisan commands for managing language file synchronization and configuration. ```APIDOC ## Artisan Commands ### Description Artisan commands for managing language file synchronization and configuration. ### Commands - **php artisan erag:install-lang** Publishes the configuration file. - **php artisan erag:generate-lang** Generates JSON language files for frontend use. ``` -------------------------------- ### Facade API: Lang::getFile() Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/resources/boost/skills/laravel-lang-sync-inertia/references/api.md Loads one or multiple translation groups and returns them grouped by filename using the Lang facade. ```APIDOC ## Lang::getFile() ### Description Loads one or many translation groups and returns them grouped by filename. ### Signature ```php Lang::getFile(string|array $file): array ``` ### Parameters #### Path Parameters - **file** (string|array) - Required - The name of the translation group(s) to load. ### Response #### Success Response (200) - **array** - An associative array where keys are filenames and values are translation strings. ### Response Example ```json { "auth": { "failed": "These credentials do not match our records." }, "validation": { "required": "The :attribute field is required." } } ``` ``` -------------------------------- ### Verify Generated Files Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/commands.md After generating translations, you can verify the existence of the JSON files using the `ls -R` command. ```bash ls -R resources/js/lang/ ``` -------------------------------- ### Service Provider Register Phase Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/package-structure.md Details the actions performed during the service provider's register method, including configuration merging and command registration. ```text register() ├── mergeConfig() │ └── Merge config/inertia-lang.php defaults ├── registerCommands() │ ├── Register InstallLangCommand │ └── Register GenerateLangCommand └── publishConfig() └── Set up vendor:publish tag 'erag:publish-lang-config' ``` -------------------------------- ### TranslationLoader getFile Method Implementation Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/classes-and-services.md Normalizes input to an array, then maps each file to its loaded translations using the `load` method. Missing groups are returned as empty arrays. ```php public function getFile(string|array $files): array { $files = (array) $files; return collect($files)->mapWithKeys(function ($file) { return [$file => $this->load($file)]; })->all(); } ``` -------------------------------- ### Frontend Helper: __() Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/resources/boost/skills/laravel-lang-sync-inertia/references/api.md Performs a direct translation lookup with optional replacements for frontend applications. ```APIDOC ## __() ### Description Direct translation lookup with optional replacements. Use this helper directly inside your Vue, React, or Svelte components. ### Signature ```ts __( key: string, replace?: Record ): string; ``` ### Parameters #### Path Parameters - **key** (string) - Required - The translation key (e.g., 'auth.greeting'). - **replace** (Record) - Optional - An object containing key-value pairs for replacements. ### Request Example ```ts __('auth.greeting'); __('auth.welcome', { name: 'Amit' }); ``` ``` -------------------------------- ### Check Configuration Values in Tinker Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/configuration.md Use the Artisan Tinker tool to inspect configuration values and verify directory existence. This helps in debugging configuration issues. ```bash php artisan tinker # Check values config('inertia-lang.lang_path') # Should output your language path config('inertia-lang.output_lang') # Should output your JSON output path # Check if directories exist \Illuminate\Support\Facades\File::isDirectory(config('inertia-lang.lang_path')) \Illuminate\Support\Facades\File::isDirectory(config('inertia-lang.output_lang')) ``` -------------------------------- ### Access Configuration in Laravel Controller Source: https://github.com/eramitgupta/laravel-lang-sync-inertia/blob/main/_autodocs/configuration.md Demonstrates how to access configuration values like `lang_path` and `output_lang` from within a Laravel controller using the `config()` helper. ```php