検索を切り替える
検索
メニューを切り替える
39
12
1
569
Sleeping Cocoon-wiki
案内
メインページ
最近の更新
おまかせ表示
MediaWikiについてのヘルプ
特別ページ
ファイルをアップロード
Toggle preferences menu
通知
個人設定を切り替える
ログインしていません
編集を行うと、IPアドレスが公開されます。
user-interface-preferences
個人用ツール
トーク
投稿記録
アカウント作成
ログイン
「
モジュール:Tr
」を編集中
提供:Sleeping Cocoon-wiki
このページを共有
表示
閲覧
編集
履歴表示
associated-pages
モジュール
議論
その他の操作
警告:
ログインしていません。編集を行うと、あなたの IP アドレスが公開されます。
ログイン
または
アカウントを作成
すれば、あなたの編集はその利用者名とともに表示されるほか、その他の利点もあります。
スパム攻撃防止用のチェックです。 けっして、ここには、値の入力は
しない
でください!
-------------------------------------------------------------------------------- -- -- ============================================================================= -- -- Module:Tr -- -- Translations of game terms and page names between English and other languages -- -- ============================================================================= -- -- Code annotations: -- This module is documented according to LuaCATS (Lua Comment and Type System). -- LuaCATS comments are prefixed with three dashes (---) and use Markdown syntax. -- For a full list of annotations, see the following link: -- https://luals.github.io/wiki/annotations/ -- -------------------------------------------------------------------------------- local vardefine = mw.ext.VariablesLua.vardefine ---Load the translation database for the given language (`Module:Tr/db-<lang>`). ---The database is cached; see [[Module:Tr/loaddata]] for details about what this ---means. ---@param lang string Language code ---@return table<"main"|"pagename"|"reversed"|"onWikiLangList", table> local function loadDatabase(lang) return mw.loadData('Module:Tr/loaddata-' .. lang) end -------------------------------------------------------------------------------- ---Main return object local p = {} ---For `{{tr}}`: load the translation database for the given language and store ---it as variables (`{{#var:}}`). The variables have the prefix `_tr:<lang>:`, ---e.g. `{{#var:_tr:it:Fish}}` → `Pesce` (Italian translation of "Fish"). The ---page name translations have the prefix `_tr:<lang>:link:`, e.g. ---`{{#var:_tr:it:link:Fish}}` → `Fish/it` (Italian page for "Fish"). ---@param frame table Interface to the parser (`mw.frame`) p.loadData = function(frame) local lang = frame.args['lang'] or 'en' local database = loadDatabase(lang) -- load regular database local prefix = '_tr:' .. lang .. ':' for termEnglish, termLocalLanguage in pairs(database.main) do vardefine(prefix .. termEnglish, termLocalLanguage) end -- load link database prefix = prefix .. 'link:' for termEnglish, termLocalLanguage in pairs(database.pagename) do vardefine(prefix .. termEnglish, termLocalLanguage) end end ---For `{{tr2e}}`: load the reversed translation database for the given language ---and store it as variables (`{{#var:}}`). The variables have the prefix `_tr2e:<lang>:`, ---e.g. `{{#var:_tr2e:it:Pesce}}` → `Fish` (Italian translation of "Fish"). ---@param frame table Interface to the parser (`mw.frame`) p.loadData2e = function(frame) local lang = frame.args['lang'] or 'en' local database = loadDatabase(lang) local prefix = '_tr2e:' .. lang .. ':' for termLocalLanguage, termEnglish in pairs(database.reversed) do vardefine(prefix .. termLocalLanguage, termEnglish) end end ---Purge the cache of the translation database for the given language. See ---[[Module:Tr/loaddata]] for details about what this means. ---Invoke from wikitext or from another module. ---@param frame table Interface to the parser (`mw.frame`) p.purge = function(frame) local lang if frame == mw.getCurrentFrame() then lang = frame.args['lang'] else lang = frame end lang = lang or 'en' require('Module:Tr/loaddata').purge(lang) end ---For other modules: translate a page name from English to the given language. ---This is the equivalent of `{{tr|<input>|lang=<lang>|link=y}}`. ---@param input string English page name to translate ---@param lang string Language code ---@return string translatedLink p.translateLink = function(input, lang) local database = loadDatabase(lang) -- look up the input in the `pagename` database local t = database.pagename[input] if t then -- input exists, return it return t end -- input does not exist in the `pagename` database if database.onWikiLangList[lang] then -- the target language is "onWiki", so the link translation is very simple -- and always the same: `<English page name>/<language code>` (e.g. -- `Fish/it` for the Italian link translation of `Fish`) return input .. '/' .. lang end -- the target language is "offWiki", so fallback: look up the input in the -- regular translation database -- if that also fails, return the input untranslated return database.main[input] or input end ---For other modules: translate a term from English to the given language. ---This is the equivalent of `{{tr|<input>|lang=<lang>}}`. ---@param input string English term to translate ---@param lang string Language code ---@return string translatedTerm p.translate = function(input, lang) local database = loadDatabase(lang) -- look up the term in the database; if that fails, return the input untranslated return database.main[input] or input end ---For other modules: translate a term from the given language to English. ---This is the equivalent of `{{tr2e|<input>|lang=<lang>}}`. ---@param input string Term to translate ---@param lang string Language code ---@return string englishTerm p.translate2e = function(input, lang) local database = loadDatabase(lang) if database.onWikiLangList[lang] then -- the input language is "onWiki", so first try to reverse the link -- translation (e.g. `Fish/it` with Italian as the input language is -- `Fish` in English) local result, count = string.gsub(input, '/' .. lang .. '$', '') if count then return result end end -- look up the term in the database; if that fails, return the input untranslated return database.reversed[input] or input end return p
編集内容の要約:
『眠ル繭wiki』への投稿はすべて、他の投稿者によって編集、変更、除去される場合があります。 自分が書いたものが他の人に容赦なく編集されるのを望まない場合は、ここに投稿しないでください。
また、投稿するのは、自分で書いたものか、パブリック ドメインまたはそれに類するフリーな資料からの複製であることを約束してください(詳細は
Sleeping Cocoon-wiki:著作権
を参照)。
著作権保護されている作品は、許諾なしに投稿しないでください!
キャンセル
編集の仕方
(新しいウィンドウで開きます)
このページで使用されているテンプレート:
モジュール:Tr/doc
(
編集
)