- How do I integrate this package into a Laravel project for multilingual language dropdowns?
- Use the JSON format and register it as a Laravel service provider. Load the data once via `config/language-list.php`, then create a facade like `LanguageList::get('en', 'fr')` to fetch localized names. For Blade templates, add a directive like `@language($code, $locale)`. Cache the data with `Cache::rememberForever()` to avoid repeated parsing.
- Does this package support Laravel’s built-in localization (e.g., `App::getLocale()`) for dynamic language switching?
- Yes, but you’ll need to manually bridge it. Store the resolved locale in a variable (e.g., `$currentLocale = app()->getLocale()`) and pass it to your facade or helper methods. Avoid duplicating Laravel’s localization logic—use this package only for ISO 639-1 name lookups when needed.
- What Laravel versions and PHP versions does this package officially support?
- The package has no Laravel-specific dependencies and works with Laravel 8.x, 9.x, and 10.x. For PHP, it supports versions 8.0+ due to its stateless, data-only nature. Test with your target PHP version to ensure no deprecated function warnings appear during runtime.
- How can I cache the language data to improve performance in a high-traffic Laravel app?
- Leverage Laravel’s cache drivers (Redis, Memcached, or file cache) to store the parsed data. Use `Cache::rememberForever()` in your service provider’s boot method to load the data once and reuse it across requests. For JSON formats, serialize the array and cache the result.
- Can I use this package to validate user-submitted language codes (e.g., ISO 639-1) against the official list?
- Absolutely. Load the package’s data into an array or database table, then validate user inputs by checking if the submitted code exists in the dataset. For example, `if (array_key_exists($userInput, $languageCodes)) { ... }`. This ensures compliance with ISO standards.
- What’s the best format to use if I need to import language data into a PostgreSQL database?
- Use the PostgreSQL SQL dump provided in the package. Run the SQL file during migrations (e.g., `php artisan db:seed`) to create a `languages` table. This avoids manual parsing and ensures data consistency. For updates, rebuild the SQL dump and re-run the migration.
- How do I handle cases where a language name differs between regions (e.g., 'English' vs. 'English (UK)')?
- The package includes standardized ISO 639-1 codes but may not distinguish regional variants by default. For granular control, combine this package with a regional dialect list or use Laravel’s localization system to append region-specific suffixes (e.g., `{{ $languageName }} ({{ $region }})`).
- Is there a way to seed the language data into an Eloquent model for easy querying?
- Yes. Create a `Language` model and seed it using the SQL dump or CSV format. Add a trait like `HasLanguages` to your models (e.g., `User`, `Post`) to access methods like `getLanguageName($locale)`. Example: `public function getLanguageName($locale) { return $this->language->name[$locale] ?? null; }`.
- What are the alternatives to this package for Laravel language lists, and when should I consider them?
- Alternatives include Laravel’s built-in `Locale` class (limited to language codes) or third-party packages like `spatie/array-to-xml`. Use this package if you need **localized names** (e.g., 'Español' for 'Spanish') across 100+ locales. For lightweight needs, the built-in `Locale` class suffices, but it lacks multilingual support.
- How often should I update the language data in a production Laravel app to stay current with ISO standards?
- Check for updates annually or when new languages are added to ISO 639-1 (e.g., artificial languages like 'art'). Automate updates with a cron job to pull the latest JSON/XML and trigger a migration or cache refresh. Monitor the [GitHub repo](https://github.com/umpirsky/language-list) for release notes.