Skip to content

Commit

Permalink
Merge pull request #128 from Laravel-Lang/5.x
Browse files Browse the repository at this point in the history
[docs]: Fixed: Warning: Undefined array key "native"
  • Loading branch information
andrey-helldar committed Nov 10, 2023
2 parents a4d4b02 + 54ca480 commit 08afa7c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 29 deletions.
29 changes: 25 additions & 4 deletions app/Services/Locales.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Services;

use DragonCode\Support\Facades\Filesystem\File;
use LaravelLang\Locales\Enums\Locale;

class Locales
{
Expand All @@ -13,16 +14,26 @@ class Locales
public static function generate(): void
{
static::store(
static::compilePage(static::compileLocales())
static::compile(
static::availableNames(),
static::availableNatives()
)
);
}

protected static function compileLocales(): array
protected static function compile(array $names, array $natives): string
{
return static::compilePage(
static::compileLocales($names, $natives)
);
}

protected static function compileLocales(array $names, array $natives): array
{
$locales = [];

foreach (static::available() as $code => $data) {
$locales[] = Template::locale($code, $data);
foreach (Locale::values() as $code) {
$locales[] = Template::locale($code, $names, $natives);
}

return $locales;
Expand All @@ -35,6 +46,16 @@ protected static function available(): array
return $locales['map'] ?? [];
}

protected static function availableNames(): array
{
return File::load(__DIR__ . '/../../vendor/laravel-lang/native-locale-names/source/locales.json');
}

protected static function availableNatives(): array
{
return File::load(__DIR__ . '/../../vendor/laravel-lang/native-locale-names/locales/_native/json.json');
}

protected static function compilePage(array $locales): string
{
return Template::page($locales);
Expand Down
8 changes: 4 additions & 4 deletions app/Services/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class Template

protected static ?string $pageStub = null;

public static function locale(string $code, array $locale): string
public static function locale(string $code, array $names, array $natives): string
{
return Str::replaceFormat(static::localeStub(), [
'code' => $code,
'locale' => $locale['name'],
'native' => Str::title($locale['native']),
'code' => $code,
'locale' => Str::title($names[$code]),
'native' => Str::title($natives[$code]),
], '{{%s}}');
}

Expand Down
42 changes: 21 additions & 21 deletions docs/usage/available-locales.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ The Armenian locale is added using the console command:
php artisan lang:add hy
```

## Azərbaycanca
## Azərbaycan

The Azerbaijani (Latin) locale is added using the console command:
The Azerbaijani locale is added using the console command:

```bash:no-line-numbers
php artisan lang:add az
Expand All @@ -60,7 +60,7 @@ php artisan lang:add be

## বাংলা

The Bengali locale is added using the console command:
The Bangla locale is added using the console command:

```bash:no-line-numbers
php artisan lang:add bn
Expand Down Expand Up @@ -90,31 +90,31 @@ The Catalan locale is added using the console command:
php artisan lang:add ca
```

## ភាសាខ្មែរ
## ខ្មែរ

The Khmer locale is added using the console command:

```bash:no-line-numbers
php artisan lang:add km
```

## 简体中文
## 简体中文

The Chinese (Simplified) locale is added using the console command:

```bash:no-line-numbers
php artisan lang:add zh_CN
```

## 简体中文
## 中文(香港)

The Chinese (Hong Kong) locale is added using the console command:

```bash:no-line-numbers
php artisan lang:add zh_HK
```

## 简体中文
## 中文(台灣)

The Chinese (Taiwan) locale is added using the console command:

Expand Down Expand Up @@ -266,7 +266,7 @@ The Icelandic locale is added using the console command:
php artisan lang:add is
```

## Bahasa Indonesia
## Indonesia

The Indonesian locale is added using the console command:

Expand Down Expand Up @@ -338,7 +338,7 @@ The Macedonian locale is added using the console command:
php artisan lang:add mk
```

## Bahasa Melayu
## Melayu

The Malay locale is added using the console command:

Expand All @@ -354,7 +354,7 @@ The Marathi locale is added using the console command:
php artisan lang:add mr
```

## ᠮᠣᠨᠭᠭᠣᠯ ᠬᠡᠯᠡ
## Монгол

The Mongolian locale is added using the console command:

Expand All @@ -370,7 +370,7 @@ The Nepali locale is added using the console command:
php artisan lang:add ne
```

## Bokmål
## Norsk Bokmål

The Norwegian Bokmål locale is added using the console command:

Expand Down Expand Up @@ -434,7 +434,7 @@ The Portuguese locale is added using the console command:
php artisan lang:add pt
```

## Português Do Brasil
## Portugues Do Brasil

The Brazilian Portuguese locale is added using the console command:

Expand All @@ -458,31 +458,31 @@ The Russian locale is added using the console command:
php artisan lang:add ru
```

## Sardu
## Sardinian

The Sardinian locale is added using the console command:

```bash:no-line-numbers
php artisan lang:add sc
```

## Српски
## Српски (Ћирилица)

The Serbian (Cyrillic) locale is added using the console command:

```bash:no-line-numbers
php artisan lang:add sr_Cyrl
```

## Srpski
## Serbian (Latin)

The Serbian (Latin) locale is added using the console command:

```bash:no-line-numbers
php artisan lang:add sr_Latn
```

## Serbian (Latin, Montenegro)
## Serbian (Montenegro)

The Serbian (Montenegro) locale is added using the console command:

Expand All @@ -508,7 +508,7 @@ php artisan lang:add sk

## Slovenščina

The Slovene locale is added using the console command:
The Slovenian locale is added using the console command:

```bash:no-line-numbers
php artisan lang:add sl
Expand Down Expand Up @@ -548,7 +548,7 @@ php artisan lang:add tl

## Тоҷикӣ

The Tajik (Cyrillic) locale is added using the console command:
The Tajik locale is added using the console command:

```bash:no-line-numbers
php artisan lang:add tg
Expand All @@ -570,7 +570,7 @@ The Turkish locale is added using the console command:
php artisan lang:add tr
```

## Түркменче
## Türkmenler

The Turkmen locale is added using the console command:

Expand Down Expand Up @@ -602,15 +602,15 @@ The Urdu locale is added using the console command:
php artisan lang:add ur
```

## Ўзбек
## O'zbek (Kirill)

The Uzbek (Cyrillic) locale is added using the console command:

```bash:no-line-numbers
php artisan lang:add uz_Cyrl
```

## Oʼzbekcha
## Uzbek (Latin)

The Uzbek (Latin) locale is added using the console command:

Expand Down

0 comments on commit 08afa7c

Please sign in to comment.