模组:模板字符串

出自Stardew Valley Wiki
於 2024年9月21日 (六) 02:56 由 VulpesLucida討論 | 貢獻 所做的修訂 (建立内容为“← 目录 {{翻译}} 本页面描述了 '''模板字符串''',即一种内置的构建显示文本的方法,该文本可以包含任意…”的新页面)
(差異) ←上個修訂 | 最新修訂 (差異) | 下個修訂→ (差異)
跳至導覽 跳至搜尋

目錄

Robin building.png
“我這裡還有很多事情需要處理。”
— 羅賓

不完整的翻譯

本文或部分尚未完全翻譯成中文。 歡迎您通過編輯幫助其建設。
最後編輯VulpesLucida於2024-09-21 02:56:57.

本頁面描述了 模板字符串,即一種內置的構建顯示文本的方法,該文本可以包含任意組合的純文本、翻譯和占位符值。

格式

綜述

您只能在允許使用模板字符串的數據字段中使用模板字符串(這些數據字段會在本百科文檔中給出)。

一個模板字符串可以包括純文本和下述標記的任意組合。例如:

"Dialogue": "欢迎光临皮埃尔的杂货店![FarmName]最近怎么样?"

當使用Content Patcher時,你可以在字符串的任何位置使用其標記(包括方括號內部);它們將在遊戲解析字符串之前完全展開。例如,"{{Spouse}} 会喜欢 [ArticleFor [SuggestedItem]] [SuggestedItem]!"會輸出"Abigail would love an Apple!"(此處放置英文原文便於理解)。

標記格式

「標記」是預定義的、用於生成文本的占位符,它們包裹在方括號中。標記名稱並不大小寫敏感,所以[LocalizedText][LOCALIZEDTEXT]是相同的標記。

例如,下面內容會在英語環境下生成"Welcome to Pierre's! This is raw text":

"Dialogue": "[LocalizedText Strings\StringsFromCSFiles:ShopMenu.cs.11488] {{i18n: some-translation}}"

標記參數格式

標記可以包含參數(參數也可包含標記)。在上面的例子中,LocalizedText具有一個參數(欲顯示的翻譯鍵)。參數使用空格分隔,因此需要使用EscapedText傳入包含空格的參數:

"Dialogue": "[LocalizedText [EscapedText Strings\BundleNames:Quality Fish]]"

標記

下面列出了原版遊戲支持的標記:

標記格式 輸出
[AchievementName <id>] 某個成就在當前語言下的名稱。成就參見Data/Achievements。例如,[AchievementName 5]會在英語環境下輸出A Complete Collection
[ArticleFor <word>] 英語中的不定冠詞(a or an)。在其他語言環境下為空白。 例如,[ArticleFor apple] apple輸出an apple
[CharacterName <name>] 根據角色的內部名稱顯示其在當前語言下的名詞。
[DayOfMonth] 顯示當月幾日,例如在春5日顯示5
[EscapedText]
[EscapedText <text>]
將文本片段視為單個參數,所以即使該片段為空或包含空格,也能被安全地傳入其他標記中。

例如,SpouseFarmerText需要空格隔開的兩個參數。下面的代碼將向第一個參數傳入空字符串,向第二個參數傳入含空格的文本:

[SpouseFarmerText [EscapedText] [EscapedText spouse 28 63 2]]
[FarmerUniqueID] 目標玩家唯一的內部多人ID。
[FarmName] 當前存檔的農場名(不包含後面的「農場」二字)
[FarmerStat <key>] 當前玩家的被跟蹤的狀態。欲獲得詳細狀態列表,參見PLAYER_STAT game state query

例如:

"你目前已经走了[FarmerStat stepsTaken]步了。"
[GenderedText <male text> <female text>] 根據玩家的性別顯示不同文本。若包含空格,須使用EscapedText
[ItemName <id> [fallback text]] 根據一個物品的限定ID或非限定ID,顯示其在當前語言下的物品名稱。例如,[ItemName (O)128]會在中文語境下顯示「河豚」。

若該物品不存在,且指定了[fallback text]參數,則輸出該參數。否則輸出Error Item (<id>)

[LocalizedText <string key>]
[LocalizedText <string key> <token values>+]
通過翻譯鍵給出翻譯後的文本。如果翻譯中包含諸如{0}的占位符,您可以在字符串鍵後面添加其值。
[LocationName <location ID>] The translated display name for a location given its ID in Data/Locations.
[MovieName <id>] The translated display name for a movie from Data/Movies. For example, [MovieName spring_movie_0] will output The Brave Little Sapling in English.
[NumberWithSeparators <number>] Format a number with thousands separators based on the current language. For example, [NumberWithSeparators 5000000] will output 5,000,000 in English.
[PositiveAdjective] A random adjective from the Strings\Lexicon data asset's RandomPositiveAdjective_PlaceOrEvent entry.
[Season] The current season name, like spring.
[SpecialOrderName <id>] The translated display name for a special order from Data/SpecialOrders. If the special order is currently active, it'll show the same name shown in the quest log. For example, [SpecialOrder Caroline] will output Island Ingredients in English.
[SpouseFarmerText <spouse is farmer text> <spouse is NPC text> Show a different text depending on whether the target player's spouse is a player or NPC. If the text contains spaces, you'll need to escape them using EscapedText.
[SpouseGenderedText <male text> <female text>] Equivalent to GenderedText, but based on the gender of the player's NPC or player spouse instead.
[SuggestedItem [interval] [sync key]] (For shops only.) The name of a random item currently available in the shop stock.

The result will be identical for all queries with the same [sync key] during the given [interval] (one of tick, day, season, year), including between players in multiplayer mode. If omitted, they default to day and the shop ID respectively.

[ToolName <id> [upgrade level]] The translated display name for a tool, including its upgrade level if specified. For example, [ToolName (T)IridiumAxe] will output Iridium Axe in English.

Extensibility for C# mods

  • C# mods can define custom tokens by calling TokenParser.RegisterParser("tokenName", ...). To avoid conflicts, custom token names should apply the unique string ID conventions.
  • The TokenStringBuilder class provides methods for creating token strings. For example, TokenStringBuilder.ItemNameFor(item) will produce a string like [ItemName (O)128] or ItemNameWithFlavor SmokedFish (O)128].