Skip to content

Commit fce1ca7

Browse files
author
孙晨
committed
+ translate doc 5.1 localization
1 parent 4226ec0 commit fce1ca7

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

localization.md

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# Localization
1+
# 本地化
22

3-
- [Introduction](#introduction)
4-
- [Basic Usage](#basic-usage)
5-
- [Pluralization](#pluralization)
6-
- [Overriding Vendor Language Files](#overriding-vendor-language-files)
3+
- [介绍](#introduction)
4+
- [基本用法](#basic-usage)
5+
- [复数形式](#pluralization)
6+
- [覆写扩展包的语言文件](#overriding-vendor-language-files)
77

88
<a name="introduction"></a>
9-
## Introduction
9+
## 介绍
1010

11-
Laravel's localization features provide a convenient way to retrieve strings in various languages, allowing you to easily support multiple languages within your application.
11+
Laravel的本地化功能提供了一种便利的获取多种语言字串的方法,让你轻松地在应用中支持多语言。
1212

13-
Language strings are stored in files within the `resources/lang` directory. Within this directory there should be a subdirectory for each language supported by the application:
13+
语言字串保存在目录 `resources/lang` 下的文件中。应用支持的每种语言都对应该目录下的一个子目录:
1414

1515
/resources
1616
/lang
@@ -19,69 +19,69 @@ Language strings are stored in files within the `resources/lang` directory. With
1919
/es
2020
messages.php
2121

22-
All language files simply return an array of keyed strings. For example:
22+
所有语言文件都简单返回一个带有键值的数组。例如:
2323

2424
<?php
2525

2626
return [
2727
'welcome' => 'Welcome to our application'
2828
];
2929

30-
#### Configuring The Locale
30+
#### 配置语言环境
3131

32-
The default language for your application is stored in the `config/app.php` configuration file. Of course, you may modify this value to suit the needs of your application. You may also change the active language at runtime using the `setLocale` method on the `App` facade:
32+
你的应用的默认语言保存在 `config/app.php` 配置文件中。当然,你可以根据需要修改该值。你也可以使用 `App` facade 的 `setLocale` 方法在运行时修改当前语言。
3333

3434
Route::get('welcome/{locale}', function ($locale) {
3535
App::setLocale($locale);
3636

3737
//
3838
});
3939

40-
You may also configure a "fallback language", which will be used when the active language does not contain a given language line. Like the default language, the fallback language is also configured in the `config/app.php` configuration file:
40+
你也可以配置一个 "备用语言", 它会在当前语言不含有给定的语句时被使用。 和默认语言一样,备用语言也在 `config/app.php` 中设置:
4141

4242
'fallback_locale' => 'en',
4343

4444
<a name="basic-usage"></a>
45-
## Basic Usage
45+
## 基本用法
4646

47-
You may retrieve lines from language files using the `trans` helper function. The `trans` method accepts the file and key of the language line as its first argument. For example, let's retrieve the language line `welcome` in the `resources/lang/messages.php` language file:
47+
你可以通过 `trans` 方法从语言文件中获取各行字串。`trans` 方法接受文件名和键值作为第一个参数。比如获取 `resources/lang/messages.php` 文件中键值为 `welcome` 的字串:
4848

4949
echo trans('messages.welcome');
5050

51-
Of course if you are using the [Blade templating engine](/docs/{{version}}/blade), you may use the `{{ }}` syntax to echo the language line:
51+
如果你在使用 [Blade templating engine](/docs/{{version}}/blade) 模版引擎,你可以使用 `{{ }}` 语法输出行字串:
5252

5353
{{ trans('messages.welcome') }}
5454

55-
If the specified language line does not exist, the `trans` function will simply return the language line key. So, using the example above, the `trans` function would return `messages.welcome` if the language line does not exist.
55+
如果该指定的行字串不存在,`trans` 函数只简单返回该行字串的键值。所以在上面的例子中,`trans` 将返回 `messages.welcome`如果不存在该行字串。
5656

57-
#### Replacing Parameters In Language Lines
57+
#### 在语言文件中替换参数
5858

59-
If you wish, you may define place-holders in your language lines. All place-holders are prefixed with a `:`. For example, you may define a welcome message with a place-holder name:
59+
你还可以给语言文件中的各行定义占位符。所有的占位符都以 `:` 为前缀。比如你可以定义一个带有占位符 name 的欢迎信息:
6060

6161
'welcome' => 'Welcome, :name',
6262

63-
To replace the place-holders when retrieving a language line, pass an array of replacements as the second argument to the `trans` function:
63+
要替换占位符,只需要将一个数组作为第二个参数传入 `trans` 函数:
6464

6565
echo trans('messages.welcome', ['name' => 'Dayle']);
6666

6767
<a name="pluralization"></a>
68-
### Pluralization
68+
### 复数形式
6969

70-
Pluralization is a complex problem, as different languages have a variety of complex rules for pluralization. By using a "pipe" character, you may distinguish a singular and plural form of a string:
70+
复数是个复杂的问题,不同语言对复数有各自不同的规则。通过使用 “|” 标记,你可以区分一个字符串的单数和复数形式:
7171

7272
'apples' => 'There is one apple|There are many apples',
7373

74-
Then, you may then use the `trans_choice` function to retrieve the line for a given "count". In this example, since the count is greater than one, the plural form of the language line is returned:
74+
接下来你可以使用 `trans_choice` 方法来根据给定的”个数“取得字串。在下面的例子中,因为个数大于1,所以返回该行的复数形式的字串:
7575

7676
echo trans_choice('messages.apples', 10);
7777

78-
Since the Laravel translator is powered by the Symfony Translation component, you may create even more complex pluralization rules:
78+
因为 Laravel 的翻译器由 Symfony 翻译组件提供,你可以创建更加复杂的复数规则:
7979

8080
'apples' => '{0} There are none|[1,19] There are some|[20,Inf] There are many',
8181

8282
<a name="overriding-vendor-language-files"></a>
83-
## Overriding Vendor Language Files
83+
## 覆写扩展包的语言文件
8484

85-
Some packages may ship with their own language files. Instead of hacking the package's core files to tweak these lines, you may override them by placing your own files in the `resources/lang/vendor/{package}/{locale}` directory.
85+
有些扩展包自带语言文件。你可以将语言文件放置在 `resources/lang/vendor/{package}/{locale}` 目录来覆写它们,而不是去修改扩展包的核心文件。
8686

87-
So, for example, if you need to override the English language lines in `messages.php` for a package named `skyrim/hearthfire`, you would place a language file at: `resources/lang/vendor/hearthfire/en/messages.php`. In this file you should only define the language lines you wish to override. Any language lines you don't override will still be loaded from the package's original language files.
87+
所以,如果你需要覆写 `skyrim/hearthfire` 扩展包的 `messages.php` 中的英文语句,你可以将一个语言文件放置在 `resources/lang/vendor/hearthfire/en/messages.php`。在该文件中只定义需要覆写的语句,没有被覆写的语句将依然从扩展包的语言文件中加载。

0 commit comments

Comments
 (0)