多語系處理 String API

1 篇文章 / 0 new
author
多語系處理 String API
提供多語系相關文字的操作, 相關對應語言檔案放置於 lang/{語系}/{PluginName}.php
► 一般語系文字定義方式
$string['editingquiz'] = '編輯測驗'

► 動態參數 : 在取得文字get_string(語義名稱, PlugInName, [動態參數])時也可動態傳入所需參數來產生組合的文字, 而語系檔內通常使用{$a}來獲取動態傳入的資料
// Strings defined in the language file.
$string['greeting'] = 'Dear {$a}';
$string['info'] = 'There are {$a->count} new messages from {$a->from}.';
 
// Passing values for the placeholders.
echo get_string('greeting', 'tool_example', 'Mr. Anderson'); // out Dear Mr. Anderson
echo get_string('info', 'tool_example', ['count' => 42, 'from' => 'Mr. Smith']);

► 輔助字串 : 幫助字串是顯示在幫助工具提示中的內容。
$string['submissionsize'] = 'Submission size';<br />
$string['submissionsize_help'] = 'Blah blah blah some useful text..';<br />
$string['submissionsize_link'] = 'mod/workshop/submission';<br />
$string['submissionsize_desc'] = 'Default value for submission size. This value will be pre-filled  ...';


_link 可使用相對路徑(起始於 $CFG->wwwroot)或絕對路徑(起始於 http)

► 角色用語
當定義的文字內有義指系統中的角色, 則在 en 語系檔內需使用下特定單字
Participants - all people with a role
Teachers - people with some sort of a facilitation/editing role
Students - people primarily there to learn
Users - people across the site

► 字串函數 :
lib / moodlelib.php-與語言環境相關的功能
lib / textlib.class.php-常規字符串函數(substr,strlen等)

String_API
Free Web Hosting