Get started quickly with I2 multi-language

Official API: http://www.inter-illusion.com/assets/I2LocalizationManual/I2LocalizationManual.html
Multi-language can dynamically change the game language to improve work efficiency

  1. Plug-in installation:

    1. Just drag and drop it into Unity
  2. Creating a Language Source:

    1. Method 1: Double-click Assets\Resources\I2Languages.asset (works globally)
    2. Method 2: Create a new GameObject in the scene and add a Language Source component ( I2\Localization\Source ) (the entire scene works)
  3. Adding Languages

    1. In the LanguageSource editor, select the **Languages ​​tab**

    2. Click **Abkhazian[ab]** at the bottom to select language—>click Add;

Insert image description here

  1. Adding Terms

    Method 1: Add locally

    1. Select the **Terms** tab

    2. Standalone ** "+" button, enter Terms ** and then create a key

    3. Enter text at the corresponding position

      Insert image description here

    Method 2: Google Spreadsheet

    1. Official tutorial: http://www.inter-illusion.com/assets/I2LocalizationManual/HowtolinkwithGoogleSpreadsheet.html

      1. Note: You need to use a personal Google account, company account permissions cannot be opened to everyone
  2. Localizing a Label

    1. Method 1: Manual mounting

      1. Select the corresponding UI component
      2. Add component: L2 Localize
      3. Choose the appropriate tag
      4. Click Term to select the defined Term
    2. Code dynamic mounting

      public class TestLanguage : MonoBehaviour
      {
          public string termKey="win"; // 术语关键字,用于定位多语言文本
          public Localize Localizes;
      
          private void Start()
          {
      
              Localizes=GetComponent<Localize>();
              
              // 动态设置多语言文本
              Localizes.SetTerm(termKey);
      
          }
      }
      
  3. Change language in game

    1. Method 1: Make a script and write the code and pass in the language name as a parameter

      if ( LocalizationManager .HasLanguage( LanguageName ))
      
      {
      
      LocalizationManager .CurrentLanguage =语言名称;
      
      }
      
      1. 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();
            }
        
    2. Method two:

      1. CreateButton
      2. Add SetLanguage Button component
        1. Set language (converted language)
        2. Select Language Source component
      3. Add listener event ApplyLanguage to Button
  4. 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.

    1. Components that need to be displayed dynamically mount the new component LocalizationParamsManager

    2. Table for content that needs to be dynamically displayed: I am {[name]}

    3. Code logic:

      GetComponent<Localize>().SetTerm("keys");
      GetComponent<LocalizationParamsManager>().SetParameterValue("名字","小明");
      

Guess you like

Origin blog.csdn.net/Xz616/article/details/132630044