Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added information on working with locales #104

Merged
merged 1 commit into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"laravel-lang/attributes": "^2.4.1",
"laravel-lang/http-statuses": "^3.4.5",
"laravel-lang/lang": "^13.2.8",
"laravel-lang/locales": "^1.0",
"laravel-lang/locales": "^1.2",
"laravel-lang/publisher": "^14.7.0"
},
"require-dev": {
Expand Down
74 changes: 66 additions & 8 deletions docs/usage/features/facades.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# Facades

Perhaps the facades will be useful to you:
## With DTOs

```php
use LaravelLang\Locales\Facades\Locales;
use LaravelLang\Locales\Data\Locale as LocaleData;
use LaravelLang\Locales\Enums\Locale;
use LaravelLang\Locales\Facades\Locales;

// List of available localizations.
Locales::available(): array
Locales::available(): array // array<LocaleData>

// List of installed localizations.
Locales::installed(): array
Locales::installed(): array // array<LocaleData>

// List of uninstalled localizations.
Locales::notInstalled(): array
Locales::notInstalled(): array // array<LocaleData>

// Retrieving a list of protected locales.
Locales::protects(): array
Locales::protects(): array // array<LocaleData>

// Check if language packs are available in requested locale.
Locales::isAvailable(Locale|string|null $locale): bool
Expand All @@ -28,10 +29,67 @@ Locales::isInstalled(Locale|string|null $locale): bool
Locales::isProtected(Locale|string|null $locale): bool

// Getting the default localization name.
Locales::getDefault(): string
Locales::getDefault(): LocaleData

// Getting the fallback localization name.
Locales::getFallback(): LocaleData
```

For example:

```php
return Locales::getDefault();

LaravelLang\Locales\Data\Locale {
+code: "de"
+codeAlias: "de-DE"
+type: "Latn"
+name: "German"
+native: "Deutsch"
+regional: "de_DE"
}
```

## With Raw Data

```php
use LaravelLang\Locales\Enums\Locale;
use LaravelLang\Locales\Facades\Locales;

// List of available localizations.
Locales::raw()->available(): array // array<string>

// List of installed localizations.
Locales::raw()->installed(): array // array<string>

// List of uninstalled localizations.
Locales::raw()->notInstalled(): array // array<string>

// Retrieving a list of protected locales.
Locales::raw()->protects(): array // array<string>

// Check if language packs are available in requested locale.
Locales::raw()->isAvailable(Locale|string|null $locale): bool

// Check if a language pack is installed.
Locales::raw()->isInstalled(Locale|string|null $locale): bool

// The checked locale protecting.
Locales::raw()->isProtected(Locale|string|null $locale): bool

// Getting the default localization name.
Locales::raw()->getDefault(): string

// Getting the fallback localization name.
Locales::getFallback(): string
Locales::raw()->getFallback(): string
```

For example:

```php
return Locales::raw()->getDefault();

// de-DE
```

To use this functionality, make sure you have
Expand Down