本地化

本页面讲述的内容长期有效
林登万讨论 | 贡献2020年8月17日 (一) 00:33的版本 (林登万移动页面Localisation本地化

钢铁雄心4使用修改过的其他许多P社游戏使用的YAML本地化(localization)系统。

基础

基本的格式如下:

l_<language>:
 <key>: "Text here"

空格可以省略。

一般来说你都会想使用l_englishkey指的是你要本地化的事物的脚本名称。

进阶的格式如下所示:

l_<language>:
 <key>:<number> "Text here"

这里是一个装备的本地化文件的实例:

l_english:
 infantry_equipment: "Infantry Equipment"
 infantry_equipment_short: "Inf. Eq."
 infantry_equipment_desc: "This is infantry equipment"

增加本地化语句时语法要准确,否则解析器会break而你得到的会是残缺的本地化。

.yml格式的文件是一种简单的文本文件,想要保存这种文件只需要选择保存为任意格式,然后输入'.yml 后缀

确保.yml文件使用UTF-8-BOM编码。使用Notepad++或是其他类似的项目可以很简单地查看和修改这一项。

特殊字符

Quote

Quote characters in text will be interpreted as part of the file if they are not escaped properly.

l_english:
 example_key: "This is "my quote" within a string."

This example would not be read correctly, as the parser would treat the second quote mark as the end of the string.

To avoid this, escape the quote mark with the \ character.

l_english:
 example_key: "This is \"my quote\" within a string."

In-game, the \ character will not be visible.

New line

You may want to force a string to display with a line break. To do this, include the \n character where you want the line break.

l_english:
 example_key: "This is line 1\nThis is line 2\nThis line 3."

Formatting characters

Various characters can be added to a string to alter its presentation ingame.

The following formatting characters are implemented:

Code Effect
§% Converts following value to percent.
§* Converts following value to SI units.
§= Prefixes following value with + if the value is positive or - if it is negative.
§0..9 Controls the number of decimals to display.
§W Colors the text white.
§G Colors the text green.
§R Colors the text red.
§B Colors the text blue.
§Y Colors the text yellow.
§b Colors the text black.
§C Colors the text light blue (cyan).
§g Colors the text gray.
§T Colors the text turquoise.
§l Colors the text lime green.
§H Colors the text yellow (same as §Y).
§O Colors the text orange.
§+ Colors the following value green if positive, yellow if zero, red if negative.
§- Colors the following value red if positive, yellow if zero, green if negative.
§! Ends the current formatting rule.

Here is an example of the color formatting:

l_english:
 example_key: "This is my text, §Bthis text is blue§!, and §Rthis text is red§!"

Formatting variables

When formatting variables instead of regular strings, the formatting character are added at the end after a | like so:

[?party_popularity@democracy|%G0]

The resulting localization depicts the current scope's democratic popularity as a percentage (%), in green (G), rounded to 0 (0)

Text icons

Icons can be displayed within strings using the £ notation.

l_english:
 example_key: "£army_experience"

Text icons are defined in the texticons.gfx file by default, although new ones can be added in any .gfx file.

Overwriting Strings

Sometimes you don't want to create new localisations, but rather overwrite the original ones in the base game. Creating a file in the localisation folder may not result in every string being overwritten, so instead you must create a subfolder in the localisation folder named "replace" (It MUST to be named replace, no other subfolders will be recognized). Inside this subfolder you can put the file with the strings you wish to rewrite. (E.G, if you want to rename the parties of a country, you would create a file named new_parties.yml and place it inside of the replace folder which is inside of the localisation folder)

Namespaces

In specific contexts, such as events, it is possible to use namespace localization. This operates using the scopes with special functions in an object-oriented manner.

l_english:
 example_key: "[Root.GetName]"

This would grab the name of the ROOT scope and display it as the string.

It is possible to string scopes together:

l_english:
 example_key: "[From.Owner.GetName]"

This would grab the name of the OWNER (country) scope of the FROM (province) scope for the current ROOT (country) scope, and display it as the string.

Another example would be getting the capital:

l_english:
 example_key: "[Root.Capital.GetName]"

You can use country tags:

l_english:
 example_key: "[HUN.GetRulingParty]"

You can use event targets:

l_english:
 example_key: "[was_attacked.GetName]"

Possible Scopes are:

  • Owner
  • Capital
  • Root
  • From
  • Prev

Functions

  • GetName
  • GetNameDef
  • GetAdjective
  • GetAdjectiveCap
  • GetLeader
  • GetRulingParty
  • GetRulingIdeology
  • GetRulingIdeologyNoun
  • GetPartySupport
  • GetLastElection
  • GetManpower
  • GetFactionName
  • GetFlag
  • GetNameWithFlag
  • GetCommunistParty
  • GetDemocraticParty
  • GetFascistParty
  • GetNeutralParty
  • GetDateText
  • GetDateString
  • GetDateStringShortMonth
  • GetDateStringNoHour
  • GetDateStringNoHourLong
  • GetYear
  • GetHerselfHimself
  • GetHerHis
  • GetSheHe
  • GetSheHeCap
  • GetRank
  • GetManchuriaPuppet
  • GetID
  • GetTag