### 創建翻譯
> data/language/zh_CN.po
~~~
msgid ""
msgstr ""
"Project-Id-Version: URLNK.COM\n"
"POT-Creation-Date: 2017-05-27 23:14+0800\n"
"PO-Revision-Date: 2018-09-13 15:48+0800\n"
"Language-Team: contact@urlnk.com\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.1.1\n"
"X-Poedit-Basepath: .\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"Last-Translator: \n"
"Language: zh_CN\n"
"X-Poedit-KeywordsList: haha\n"
# 注釋
msgid "Home"
msgstr "主頁"
msgid "Album"
msgstr "專輯"
#
msgid "Skeleton Application"
msgstr "骨架應用"
msgid "Blog"
msgstr "博客"
msgid "Add"
msgstr "添加"
msgid "Edit"
msgstr "編輯"
msgid "Delete"
msgstr "刪除"
msgid "My albums"
msgstr "我的專輯"
msgid "Add new album"
msgstr "添加新專輯"
msgid "Album title"
msgstr "專輯標題"
msgid "Artist"
msgstr "藝術家"
msgid "Title"
msgstr "標題"
msgid "Edit album"
msgstr "編輯專輯"
msgid "Delete album"
msgstr "刪除專輯"
msgid "Yes"
msgstr "是"
msgid "No"
msgstr "否"
msgid "Are you sure that you want to delete"
msgstr "您確定想要刪除"
~~~
然后用 [Poedit](https://poedit.net/) 編譯成 mo 文件
> data/language/zh_CN.mo
**全局配置翻譯**
> config/autoload/global.php
~~~
'translator' => [
'locale' => 'zh_CN',
'translation_file_patterns' => [
[
'type' => 'gettext',
'base_dir' => getcwd() . '/data/language',
'pattern' => '%s.mo',
],
],
],
~~~
### 模板中翻譯字符串
~~~
<p>© 2016 by Examples Ltd. <?= $this->translate('All rights reserved') ?></p>
~~~
### 翻譯源類型
`gettext`, `phparray`, `ini`
> module/Blog/language/zh_CN.php
~~~
<?php
return [
'Blog Posts' => '博客文章',
'Add a blog post' => '添加一篇博客文章',
'Edit blog post' => '編輯博客文章',
'Cancel' => '取消',
'Post Title' => '文章標題',
'Post title' => '文章標題',
'Post Text' => '文章文本',
'Post content' => '文章內容',
'Post Details' => '文章詳情',
'Write new post' => '寫新文章',
'Insert new post' => '插入新文章',
'Update post' => '更新文章',
'Delete post' => '刪除文章',
'Are you sure you want to delete the following post?' => '你確定想要刪除這篇文章?',
];
~~~
**模塊配置翻譯**
> module/Blog/config/module.config.php
~~~
'translator' => [
'locale' => 'zh_CN',
'translation_file_patterns' => [
[
'type' => 'phparray',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.php',
],
],
],
~~~