Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

[OmekaS]如何製作多國語系檔案

內容目錄

如何製作多國語系檔案

在Omeka S中能切換不同的語言,因此在修改或製作主題/模組時就得考慮加入多國語系,至少做個對應中文與英文

製作方式不難,採用的就是gettext(i18n)的作法

首先需要*.po(zh_TW.po) 如果是繁體中文,就用對應的語言簡稱(zh_TW)

內容大概像這樣

# Translation for the XXX plugin for Omeka.
# Copyright (C) 2011 Roy Rosenzweig Center for History and New Media
# This file is distributed under the same license as the Omeka package.
# 
# Translators:
# billxu <[email protected]>, 2020
msgid ""
msgstr ""
"Project-Id-Version: Omeka\n"
"Report-Msgid-Bugs-To: http://github.com/omeka/plugin-Guest/issues\n"
"POT-Creation-Date: 2012-01-09 21:49-0500\n"
"PO-Revision-Date: 2020-04-12 01:18+0000\n"
"Last-Translator: billxu <[email protected]>\n"
"Language-Team: \n"
"MIME-Version: 2.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: zh_TW\n"
"Plural-Forms: nplurals=1; plural=0;\n"

msgid "Close Menu"  //這是原始字串原文
msgstr "關閉選單"  //翻譯後

再來使用po轉檔成的mo檔 線上轉換器

若開發新模組需要在config/module.config.php中新增下面參數,讓OmekaS能讀到你的語系檔位置

'translator' => [
        'translation_file_patterns' => [
            [
                'type' => 'gettext',
                'base_dir' => dirname(__DIR__) . '/language',
                'pattern' => '%s.mo',
                'text_domain' => null,
            ],
        ],
    ],

html要導入多國語系設定需要要先宣告

$translate = $this->plugin('translate');

接著再對應的位置用這種寫法即可

<?= $translate('Close Menu')?>  ///顯示字串關閉選單

在php只要呼叫這樣即可

$translate('Close Menu'),  ///顯示字串關閉選單