Official API: http://www.inter-illusion.com/assets/I2LocalizationManual/I2LocalizationManual.html
Multi-language can dynamically change the game language to improve work efficiency
-
Plug-in installation:
- Just drag and drop it into Unity
-
Creating a Language Source:
- Method 1: Double-click Assets\Resources\I2Languages.asset (works globally)
- Method 2: Create a new GameObject in the scene and add a Language Source component ( I2\Localization\Source ) (the entire scene works)
-
Adding Languages
-
In the LanguageSource editor, select the **Languages tab**
-
Click **Abkhazian[ab]** at the bottom to select language—>click Add;
-
-
Adding Terms
Method 1: Add locally
-
Select the **Terms** tab
-
Standalone ** "+" button, enter Terms ** and then create a key
-
Enter text at the corresponding position
Method 2: Google Spreadsheet
-
Official tutorial: http://www.inter-illusion.com/assets/I2LocalizationManual/HowtolinkwithGoogleSpreadsheet.html
- Note: You need to use a personal Google account, company account permissions cannot be opened to everyone
-
-
Localizing a Label
-
Method 1: Manual mounting
- Select the corresponding UI component
- Add component: L2 Localize
- Choose the appropriate tag
- Click Term to select the defined Term
-
Code dynamic mounting
public class TestLanguage : MonoBehaviour { public string termKey="win"; // 术语关键字,用于定位多语言文本 public Localize Localizes; private void Start() { Localizes=GetComponent<Localize>(); // 动态设置多语言文本 Localizes.SetTerm(termKey); } }
-
-
Change language in game
-
Method 1: Make a script and write the code and pass in the language name as a parameter
if ( LocalizationManager .HasLanguage( LanguageName )) { LocalizationManager .CurrentLanguage =语言名称; }
-
Example
public void SetLanguage() { int count = LocalizationManager.GetAllLanguages().Count; //获取语言个数 int nowId = LocalizationManager.GetAllLanguages().IndexOf(LocalizationManager.CurrentLanguage); //获取当前语言索引 //索引递增 if (nowId < count - 1) { setLanguage._Language = LocalizationManager.GetAllLanguages()[nowId + 1].ToString(); } else { setLanguage._Language = "English"; } setLanguage.ApplyLanguage(); }
-
-
Method two:
- CreateButton
- Add SetLanguage Button component
- Set language (converted language)
- Select Language Source component
- Add listener event ApplyLanguage to Button
-
-
Dynamically modify the language in the game
For example, for joint display, our table only has the word "joint", so the numbers of joint 1 and joint 2 need to be displayed dynamically.
-
Components that need to be displayed dynamically mount the new component LocalizationParamsManager
-
Table for content that needs to be dynamically displayed: I am {[name]}
-
Code logic:
GetComponent<Localize>().SetTerm("keys"); GetComponent<LocalizationParamsManager>().SetParameterValue("名字","小明");
-