Skip to content

Commit

Permalink
Merge pull request #104 from Laravel-Lang/4.x
Browse files Browse the repository at this point in the history
Added information on working with locales
  • Loading branch information
andrey-helldar authored Oct 29, 2023
2 parents f04bfd5 + e1b2438 commit 6d69c71
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 9 deletions.
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

0 comments on commit 6d69c71

Please sign in to comment.