설정
게시
필요한 경우 다음 명령으로 설정 파일을 게시하세요.
php artisan vendor:publish --tag="localization"
게시된 config/localization.php 파일은 다음과 같습니다.
설정 보기
return [
/*
* 언어 파일을 갱신할 때 사용할 파일 유형을 지정합니다.
*
* @see https://laravel-lang.com/configuration.html#inline
*
* 기본값은 `false`입니다.
*/
'inline' => (bool) env('LOCALIZATION_INLINE', env('LANG_PUBLISHER_INLINE')),
/*
* 배열을 처리하기 전에 키를 기준으로 배열을 정렬할지 정합니다.
*
* @see https://laravel-lang.com/configuration.html#alignment
*
* 기본값은 true입니다.
*/
'align' => (bool) env('LOCALIZATION_ALIGN', env('LANG_PUBLISHER_ALIGN', true)),
/*
* 이 저장소의 파일에 사용하는 언어 코드가
* 프로젝트의 환경설정과 일치하지 않을 수 있습니다.
*
* 저장소의 로캘과 프로젝트의 로캘 사이의 매핑을 여기에 지정합니다.
*
* @see https://laravel-lang.com/configuration.html#aliases
*/
'aliases' => [
// \LaravelLang\LocaleList\Locale::German->value => 'de-DE',
// \LaravelLang\LocaleList\Locale::GermanSwitzerland->value => 'de-CH',
],
/*
* 이 옵션은 번역 키의 문장 부호를 조판용으로
* 변환하는 방식을 지정합니다.
*
* @see https://laravel-lang.com/configuration.html#smart_punctuation
*
* 기본값은 false입니다.
*/
'smart_punctuation' => [
'enable' => (bool) env('LOCALIZATION_SMART_ENABLED', false),
'common' => [
'double_quote_opener' => '“',
'double_quote_closer' => '”',
'single_quote_opener' => '‘',
'single_quote_closer' => '’',
],
'locales' => [
Locale::French->value => [
'double_quote_opener' => '« ',
'double_quote_closer' => ' »',
'single_quote_opener' => '‘',
'single_quote_closer' => '’',
],
Locale::Russian->value => [
'double_quote_opener' => '«',
'double_quote_closer' => '»',
'single_quote_opener' => '‘',
'single_quote_closer' => '’',
],
Locale::Ukrainian->value => [
'double_quote_opener' => '«',
'double_quote_closer' => '»',
'single_quote_opener' => '‘',
'single_quote_closer' => '’',
],
Locale::Belarusian->value => [
'double_quote_opener' => '«',
'double_quote_closer' => '»',
'single_quote_opener' => '‘',
'single_quote_closer' => '’',
],
],
],
/*
* 이 옵션은 애플리케이션의 라우트 설정을 지정합니다.
*
* @see https://laravel-lang.com/configuration.html#routes
*/
'routes' => [
/*
* 애플리케이션에서 라우트를 처리할 때 쓰는 키 이름을 설정합니다.
*
* 기본값은 다음과 같습니다.
*
* parameter - locale
* header - Accept-Language
* cookie - Accept-Language
* session - Accept-Language
* column - column
*/
'names' => [
'parameter' => RouteName::Parameter,
'header' => RouteName::Header,
'cookie' => RouteName::Cookie,
'session' => RouteName::Session,
'column' => RouteName::Column,
],
/*
* 이 옵션은 라우트 그룹 이름의 접두사를 지정합니다.
*
* 기본값은 `localized.`입니다.
*/
'name_prefix' => env('LOCALIZATION_NAME_PREFIX', 'localized.'),
/*
* 이 옵션은 기본 로캘을 열 때 요청을 리디렉션할지 지정합니다.
*
* `LaravelLang\Routes\Facades\LocalizationRoute` 파사드를 사용할 때 적용됩니다.
*/
'redirect_default' => (bool) env('LOCALIZATION_REDIRECT_DEFAULT', false),
/*
* 기본 로캘의 매개변수를 URL에서 제거할지 지정합니다.
*
* `localizedRoute` 헬퍼를 사용할 때 적용됩니다.
*/
'hide_default' => (bool) env('LOCALIZATION_HIDE_DEFAULT', false),
// 라우트 설정입니다.
'group' => [
'middlewares' => [
// 로캘 코드 접두사가 없는 라우트에 적용하는 설정입니다.
'default' => [
LaravelLang\Routes\Middlewares\LocalizationByCookie::class,
LaravelLang\Routes\Middlewares\LocalizationByHeader::class,
LaravelLang\Routes\Middlewares\LocalizationBySession::class,
LaravelLang\Routes\Middlewares\LocalizationByModel::class,
],
// 로캘 코드 접두사가 있는 라우트에 적용하는 설정입니다.
'prefix' => [
LaravelLang\Routes\Middlewares\LocalizationByParameterPrefix::class,
LaravelLang\Routes\Middlewares\LocalizationByCookie::class,
LaravelLang\Routes\Middlewares\LocalizationByHeader::class,
LaravelLang\Routes\Middlewares\LocalizationBySession::class,
LaravelLang\Routes\Middlewares\LocalizationByModel::class,
],
],
],
],
/*
* 이 옵션은 모델 번역에 사용할 설정을 지정합니다.
*
* @see https://laravel-lang.com/configuration.html#models
*/
'models' => [
/*
* 번역을 담는 모델의 이름 접미사를 지정합니다.
*
* 예를 들어 아래 모델 이름을 사용합니다.
* 기본 모델은 `App\Models\Page`
* 번역 모델은 `App\Models\PageTranslation`
*
* 기본값은 `Translation`입니다.
*/
'suffix' => 'Translation',
/*
* 즉시 로딩을 사용할 때 관계에서 불러온 로캘을
* 필터링할지 지정합니다.
*
* 기본값은 true입니다.
*/
'filter' => [
'enabled' => (bool) env('LOCALIZATION_FILTER_ENABLED', true),
],
/*
* IDE 헬퍼 파일을 저장할 디렉터리를 지정합니다.
*
* 기본값은 `vendor/_laravel_lang`입니다.
*/
'helpers' => env('VENDOR_PATH', base_path('vendor/_laravel_lang')),
],
/*
* 이 옵션은 Laravel Lang Translator에서 사용할 번역기 목록을 지정합니다.
*
* 기본적으로 Google 번역이 활성화됩니다.
*
* @see https://laravel-lang.com/configuration.html#translators
*/
'translators' => [
/*
* 번역에 사용할 채널 목록입니다.
*
* 기본적으로 아래와 같이 설정됩니다.
*
* Google 사용
* Deepl 사용 안 함
* Yandex 사용 안 함
*/
'channels' => [
'google' => [
'translator' => '\LaravelLang\Translator\Integrations\Google',
'enabled' => (bool) env('TRANSLATION_GOOGLE_ENABLED', true),
'priority' => (int) env('TRANSLATION_GOOGLE_PRIORITY', 1),
],
'deepl' => [
'translator' => '\LaravelLang\Translator\Integrations\Deepl',
'enabled' => (bool) env('TRANSLATION_DEEPL_ENABLED', false),
'priority' => (int) env('TRANSLATION_DEEPL_PRIORITY', 2),
'credentials' => [
'key' => (string) env('TRANSLATION_DEEPL_KEY'),
],
],
'yandex' => [
'translator' => '\LaravelLang\Translator\Integrations\Yandex',
'enabled' => (bool) env('TRANSLATION_YANDEX_ENABLED', false),
'priority' => (int) env('TRANSLATION_YANDEX_PRIORITY', 3),
'credentials' => [
'key' => (string) env('TRANSLATION_YANDEX_KEY'),
'folder' => (string) env('TRANSLATION_YANDEX_FOLDER_ID'),
],
],
],
'options' => [
/*
* 문자열에서 교체 가능한 키워드를 추출할 사용자 지정 패턴을 설정합니다.
* 기본적으로 콜론으로 시작하는 단어를 추출합니다.
*
* 아래 옵션을 사용할 수 있습니다.
*
* `true`는 `/:(\w+)/`을 사용합니다.
* `false`는 정규식 처리를 비활성화합니다.
* `/any regex/` 대신 정규식을 직접 지정할 수 있습니다.
*
* 기본값은 `true`입니다.
*
* @example "Hello :name"에서는 "name"을 추출합니다.
*/
'preserve_parameters' => true,
],
],
];
인라인
inline 옵션은 언어 파일을 갱신할 때 사용할 파일 유형을 지정합니다.
true이면 인라인 파일을 사용합니다.false이면 기본 파일을 사용합니다.
두 파일의 차이는 아래 예제에서 확인할 수 있습니다.
The :attribute must be accepted. // default
This field must be accepted. // inline
이 옵션은 config/localization.php 파일에서 설정합니다.
return [
'inline' => (bool) env('LOCALIZATION_INLINE', env('LANG_PUBLISHER_INLINE')),
];
정렬
align 옵션은 로캘 파일을 처리할 때 값들의 위치를 어떻게 맞출지 지정합니다.
파일을 갱신하면 최종 파일에서 주석을 모두 자동으로 삭제합니다. var_export가 주석을 처리하지 못하기 때문입니다.
다음은 갱신 전 파일의 예입니다.
declare(strict_types=1);
return [
/*
|--------------------------------------------------------------------------
| 인증 메시지
|--------------------------------------------------------------------------
|
| 다음 문구는 인증 과정에서 사용자에게 표시하는 여러 메시지에
| 사용됩니다. 애플리케이션의 요구 사항에 맞춰
| 이 문구를 자유롭게 변경할 수 있습니다.
|
*/
'failed' => 'These credentials do not match our records 123456.',
'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',
'foo' => 'bar',
];
갱신한 파일은 다음과 같습니다.
declare(strict_types=1);
return [
'failed' => 'These credentials do not match our records 123456.',
'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',
'foo' => 'bar',
];
다음은 validation.php 파일의 예입니다.
내용 보기
declare(strict_types=1);
return [
/*
|--------------------------------------------------------------------------
| 유효성 검사 메시지
|--------------------------------------------------------------------------
|
| 다음 문구에는 유효성 검사기 클래스가 사용하는 기본 오류 메시지가
| 포함됩니다. 크기 규칙 등 일부 규칙은 여러 형태의
| 메시지를 사용합니다. 여기에서 각 메시지를 자유롭게 수정하세요.
|
*/
'accepted' => 'The :attribute must be accepted.',
'active_url' => 'The :attribute is not a valid URL.',
// 여러 규칙
'uuid' => 'The :attribute must be a valid UUID.',
/*
|--------------------------------------------------------------------------
| 사용자 지정 유효성 검사 메시지
|--------------------------------------------------------------------------
|
| "attribute.rule" 규칙에 따라 문구 이름을 정하면
| 속성별 사용자 지정 유효성 검사 메시지를 지정할 수 있습니다.
| 특정 속성 규칙의 전용 메시지를 쉽게 설정할 수 있습니다.
|
*/
'custom' => [
'name' => [
'required' => 'Custom message 1',
'string' => 'Custom message 2',
],
],
/*
|--------------------------------------------------------------------------
| 사용자 지정 유효성 검사 속성 이름
|--------------------------------------------------------------------------
|
| 아래 문구는 속성 자리표시자를 읽기 쉬운 이름으로 바꿉니다.
| 예를 들어 "email"을 "E-Mail Address"로 표시할 수 있습니다.
| 이를 통해 메시지의 의미를 명확히 전달할 수 있습니다.
|
*/
'attributes' => [
'name' => 'Foo',
'bar' => 'Bar',
'baz' => 'Baz',
],
];
갱신 후에는 아래와 같이 바뀝니다.
declare(strict_types=1);
return [
'accepted' => 'The :attribute must be accepted.',
'active_url' => 'The :attribute is not a valid URL.',
'uuid' => 'The :attribute must be a valid UUID.',
'custom' => [
'name' => [
'required' => 'Custom message 1',
'string' => 'Custom message 2',
],
],
'attributes' => [
'name' => 'Foo',
'bar' => 'Bar',
'baz' => 'Baz',
],
];
이 옵션은 config/localization.php 파일에서 설정합니다.
return [
'align' => (bool) env('LOCALIZATION_ALIGN', env('LANG_PUBLISHER_ALIGN', true)),
];
별칭
de 대신 de-DE를 사용하거나 de_CH 대신 de-CH를 사용하려면 설정 파일에 aliases를 정의하세요.
이후 추가, 갱신 및 삭제 작업에 config/localization.php에 지정된 별칭이 자동으로 적용됩니다.
declare(strict_types=1);
use LaravelLang\LocaleList\Locale;
return [
'aliases' => [
Locale::German->value => 'de-DE',
Locale::GermanAustria->value => 'de-AT',
Locale::GermanSwitzerland->value => 'de-CH',
],
];
config/localization.php 파일이 이미 있다면 aliases 키를 추가하고 배열로 원하는 별칭을 지정하세요.
설정한 뒤 로캘을 추가할 때는 기본 코드와 별칭을 모두 지정할 수 있습니다.
php artisan lang:add de de_CH
설치된 로캘의 PHP 번역 디렉터리와 JSON 번역 파일에는 지정한 별칭을 사용합니다.
lang
de-CH
de-DE
이 옵션은 config/localization.php 파일에서 설정합니다.
return [
'aliases' => [
// \LaravelLang\LocaleList\Locale::German->value => 'de-DE',
// \LaravelLang\LocaleList\Locale::GermanSwitzerland->value => 'de-CH',
],
];
스마트 문장 부호
번역 키를 갱신할 때 ASCII 따옴표, 대시 및 줄임표를 대응하는 유니코드 문자로 자동 변환하도록 설정할 수도 있습니다.
다음은 예제입니다.
{
"Some": "\"It's super-configurable... you can even use additional extensions to expand its capabilities -- just like this one!\""
}
결과 파일은 다음과 같습니다.
{
"Some": "“It’s super-configurable… you can even use additional extensions to expand its capabilities – just like this one!”"
}
이 옵션은 config/localization.php 파일에서 설정합니다.
설정 보기
use LaravelLang\LocaleList\Locale;
return [
'smart_punctuation' => [
'enable' => (bool) env('LOCALIZATION_SMART_ENABLED', false),
'common' => [
'double_quote_opener' => '“',
'double_quote_closer' => '”',
'single_quote_opener' => '‘',
'single_quote_closer' => '’',
],
'locales' => [
Locale::French->value => [
'double_quote_opener' => '« ',
'double_quote_closer' => ' »',
'single_quote_opener' => '‘',
'single_quote_closer' => '’',
],
Locale::Russian->value => [
'double_quote_opener' => '«',
'double_quote_closer' => '»',
'single_quote_opener' => '‘',
'single_quote_closer' => '’',
],
Locale::Ukrainian->value => [
'double_quote_opener' => '«',
'double_quote_closer' => '»',
'single_quote_opener' => '‘',
'single_quote_closer' => '’',
],
Locale::Belarusian->value => [
'double_quote_opener' => '«',
'double_quote_closer' => '»',
'single_quote_opener' => '‘',
'single_quote_closer' => '’',
],
],
],
];
각 로캘에 별도의 규칙을 지정할 수도 있습니다.
기본적으로 변환은 꺼져 있습니다.
라우트
라우트 패키지를 사용할 때 키 이름의 기본값을 재정의할 수 있습니다.
이 옵션은 config/localization.php 파일에서 활성화합니다.
use LaravelLang\Config\Constants\RouteName;
return [
'routes' => [
'names' => [
'parameter' => RouteName::Parameter,
'header' => RouteName::Header,
'cookie' => RouteName::Cookie,
'session' => RouteName::Session,
'column' => RouteName::Column,
],
'name_prefix' => env('LOCALIZATION_NAME_PREFIX', 'localized.'),
'redirect_default' => (bool) env('LOCALIZATION_REDIRECT_DEFAULT', false),
'hide_default' => (bool) env('LOCALIZATION_HIDE_DEFAULT', false),
'group' => [
'middlewares' => [
'default' => [
LaravelLang\Routes\Middlewares\LocalizationByCookie::class,
LaravelLang\Routes\Middlewares\LocalizationByHeader::class,
LaravelLang\Routes\Middlewares\LocalizationBySession::class,
LaravelLang\Routes\Middlewares\LocalizationByModel::class,
],
'prefix' => [
LaravelLang\Routes\Middlewares\LocalizationByParameterPrefix::class,
LaravelLang\Routes\Middlewares\LocalizationByCookie::class,
LaravelLang\Routes\Middlewares\LocalizationByHeader::class,
LaravelLang\Routes\Middlewares\LocalizationBySession::class,
LaravelLang\Routes\Middlewares\LocalizationByModel::class,
],
],
],
],
];
모델
Models 패키지를 사용할 때 매개변수의 기본값을 설정할 수 있습니다.
이 설정은 config/localization.php 파일에 있습니다.
return [
'models' => [
'suffix' => 'Translation',
'filter' => [
'enabled' => (bool) env('LOCALIZATION_FILTER_ENABLED', true),
],
'helpers' => env('VENDOR_PATH', base_path('vendor/_laravel_lang')),
],
];
suffix 매개변수는 번역 저장소에 속하는 모델 이름의 접미사를 지정합니다.
다음은 예제입니다.
App\Models\Post::class
App\Models\PostTranslation::class
Translator
여기에서 기본 번역기를 활성화하고 직접 번역기를 만들 수도 있습니다. 자세한 내용은 Translator 패키지 문서를 참조하세요.
이 설정은 config/localization.php 파일에 있습니다.
return [
'translators' => [
'channels' => [
'google' => [
'translator' => '\LaravelLang\Translator\Integrations\Google',
'enabled' => (bool) env('TRANSLATION_GOOGLE_ENABLED', true),
'priority' => (int) env('TRANSLATION_GOOGLE_PRIORITY', 1),
],
'deepl' => [
'translator' => '\LaravelLang\Translator\Integrations\Deepl',
'enabled' => (bool) env('TRANSLATION_DEEPL_ENABLED', false),
'priority' => (int) env('TRANSLATION_DEEPL_PRIORITY', 2),
'credentials' => [
'key' => (string) env('TRANSLATION_DEEPL_KEY'),
],
],
'yandex' => [
'translator' => '\LaravelLang\Translator\Integrations\Yandex',
'enabled' => (bool) env('TRANSLATION_YANDEX_ENABLED', false),
'priority' => (int) env('TRANSLATION_YANDEX_PRIORITY', 3),
'credentials' => [
'key' => (string) env('TRANSLATION_YANDEX_KEY'),
'folder' => (string) env('TRANSLATION_YANDEX_FOLDER_ID'),
],
],
],
'options' => [
'preserve_parameters' => true,
],
],
];