検索を切り替える
検索
メニューを切り替える
39
12
1
569
Sleeping Cocoon-wiki
案内
メインページ
最近の更新
おまかせ表示
MediaWikiについてのヘルプ
特別ページ
ファイルをアップロード
Toggle preferences menu
通知
個人設定を切り替える
ログインしていません
編集を行うと、IPアドレスが公開されます。
user-interface-preferences
個人用ツール
トーク
投稿記録
アカウント作成
ログイン
「
モジュール:Tr/loaddata
」を編集中
提供:Sleeping Cocoon-wiki
このページを共有
表示
閲覧
編集
履歴表示
associated-pages
モジュール
議論
その他の操作
警告:
ログインしていません。編集を行うと、あなたの IP アドレスが公開されます。
ログイン
または
アカウントを作成
すれば、あなたの編集はその利用者名とともに表示されるほか、その他の利点もあります。
スパム攻撃防止用のチェックです。 けっして、ここには、値の入力は
しない
でください!
-------------------------------------------------------------------------------- -- -- ============================================================================= -- -- Module:Tr/loaddata -- -- Cache management of the translation databases for Module:Tr -- -- ============================================================================= -- -- 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 cache = mw.ext.LuaCache local trim = mw.text.trim -- Note: -- It seems that objects/lists stored via LuaCache have a limit on the number of -- entities, which is about 8000. Any object/list with more than 8000 entities or -- with such a large sub-object/sub-list will be truncated. Therefore, we encode -- the data into a JSON string to get around this problem. -------------------------------------------------------------------------------- ---Main return object local p = {} ---Get the cached translation database for the specified language `lang`. Recreate ---the cache if necessary. ---This function should only be called from the `Module:Tr/loaddata-<lang>` modules ---(e.g. `Module:Tr/loaddata-ar`), like so: `return require('Module:Tr/loaddata').load('<lang>')` ---@param lang string Language code ---@return table<string, string> data p.load = function(lang) -- attempt to load the cached data local success, result = pcall(function() return mw.text.jsonDecode(cache.get('tr__database-' .. lang)) end) if success then -- cached data is available, just return it return result end -- cached data is not available, so we need to recreate it ---Fetch the database. We use `require()` for this and not `mw.loadData()` ---because the return table of `mw.loadData()` has a metatable and therefore ---cannot be used with `cache.set()` and `mw.loadData()`. ---@type table local info = require('Module:Tr/db-' .. lang) ---List of language codes that are "on-wiki", i.e. not on a separate wiki. See ---[[Template:LangList]]. ---@type { [string]: true } info.onWikiLangList = {} local langListStr = mw.getCurrentFrame():expandTemplate{ title = 'langList', args = {'onWiki'} } -- convert e.g. `"ar, bg, cs, da"` to `{"ar", " bg", " cs", " da"}`, then to -- `{["ar"] = true, ["bg"] = true, ["cs"] = true, ["da"] = true}` for _, langcode in ipairs(mw.text.split(langListStr, ',')) do info.onWikiLangList[trim(langcode)] = true end ---Assemble the database for "reverse" translation (local language to English). ---@type table<string, string> local reversed = {} -- add all terms from the `main` table for termEnglish, termLocalLanguage in pairs(info.main or {}) do reversed[termLocalLanguage] = termEnglish end -- add all terms from the `pagename` table, potentially overriding the `main` -- table where necessary for termEnglish, termLocalLanguage in pairs(info.pagename or {}) do reversed[termLocalLanguage] = termEnglish end -- add all manually specified terms, potentially overriding any terms from -- `main` and `pagename` tables for termLocalLanguage, termEnglish in pairs(info.reversed or {}) do reversed[termLocalLanguage] = termEnglish end -- for on-wiki languages: the translation `<English page>/<lang>` => `<English page>` -- is handled by {{pagename2en}}, so there's no need to add that to this database info.reversed = reversed -- cache the `info` table cache.set('tr__database-' .. lang, mw.text.jsonEncode(info)) return info end -- p.load ---Purge the translation database for the specified language `<lang>`. When the ---`load` function is called the next time, the database cache will be forcefully ---recreated. ---This function should only be called from the `purge` function of `Module:Tr`. ---That function can be invoked from wikitext via `{{#invoke:Tr|purge|lang=<lang>}}`, ---which is done on each `Module:Tr/db-<lang>/doc` page. So purging that documentation ---page (or the module page `Module:Tr/db-<lang>` itself) will call this function ---and purge the respective language's translation database cache. ---@param lang string Language code p.purge = function(lang) cache.delete('tr__database-' .. lang) end -- p.purge return p
編集内容の要約:
『眠ル繭wiki』への投稿はすべて、他の投稿者によって編集、変更、除去される場合があります。 自分が書いたものが他の人に容赦なく編集されるのを望まない場合は、ここに投稿しないでください。
また、投稿するのは、自分で書いたものか、パブリック ドメインまたはそれに類するフリーな資料からの複製であることを約束してください(詳細は
Sleeping Cocoon-wiki:著作権
を参照)。
著作権保護されている作品は、許諾なしに投稿しないでください!
キャンセル
編集の仕方
(新しいウィンドウで開きます)
このページで使用されているテンプレート:
モジュール:Tr/loaddata/doc
(
編集
)